From a5f43a0403de5b10822969e1b0066c16d567dfa5 Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Sat, 10 Aug 2024 20:58:07 +0700 Subject: [PATCH] update --- src/interface.jl | 48 +++++++++++++++++++++++++++--------------------- test/runtest.jl | 6 +++--- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index 71b2e4a..cbfba6d 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -228,7 +228,8 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent} - All wines in your inventory are always in stock. - Use the "understand-then-check" inventory strategy to understand the user, as there are many wines in the inventory. - Do not ask the user about wine's flavor e.g. floral, citrusy, nutty or some thing similar as these terms cannot be used to search the database. - - Once the user has selected their wine, if they don’t require any further assistance, use the ENDCONVERSATION function to end the conversation. + - Once the user has selected their wine, ask the user if they require any further assistance. Do not offer additional services. + - If the user doesn't require any further assistance, use the ENDCONVERSATION function to end the conversation. You should follow the following guidelines as you see fit: - If the user interrupts, prioritize the user. @@ -248,6 +249,9 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent} 2) CHECKINVENTORY which you can use to check info about wine in your inventory. The input is a search term in verbal English. Good query example: black car, a stereo, 200 mile range, electric motor. Good query example: How many car brand are from Asia? + 3) PRESENTBOX which you can use to present the wines to the user. This function is better than CHATBOX at presenting wines. The input is the names of wines to present. + 4) ENDCONVERSATION which you can use to end the conversation with the user. The input is "NA". + - action_input: input details of the action - mentioning_wine: Are you mentioning specific wine name to the user? Can be "Yes" or "No" @@ -303,7 +307,7 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent} # action_name = string(split(responsedict[:action_name], '[')[1]) # end - if responsedict[:action_name] ∉ ["ENDCONVERSATION", "CHATBOX", "CHECKINVENTORY"] + if responsedict[:action_name] ∉ ["CHATBOX", "PRESENTBOX", "CHECKINVENTORY", "ENDCONVERSATION"] errornote = "You must use the given functions" error("You must use the given functions ", @__FILE__, " ", @__LINE__) end @@ -331,8 +335,8 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent} if occursin("Yes", responsedict[:mentioning_wine]) && isMemEmpty && responsedict[:action_name] != "CHECKINVENTORY" - errornote = "Note: You must check your inventory before recommending wine to the user." - error( "You must check your inventory before recommending wine") + errornote = "Note: You can't recommend wines yet. You must check your inventory before recommending wine to the user." + error( "You can't recommend wines yet. You must check your inventory before recommending wines") else errornote = "" end @@ -510,7 +514,7 @@ end """ Assigns a scalar value to each new child node to be used for selec- -tion and backpropagation. This value effectively quantifies the agent’s progress in task completion, +tion and backpropagation. This value effectively quantifies the agent's progress in task completion, serving as a heuristic to steer the search algorithm towards the most promising regions of the tree. # Arguments @@ -1051,12 +1055,14 @@ function think(a::T)::NamedTuple{(:actionname, :result), Tuple{String, String}} response = if actionname == "CHATBOX" (result=actioninput, errormsg=nothing, success=true) - elseif actionname == "ENDCONVERSATION" - (result=actioninput, errormsg=nothing, success=true) - # recommendbox(a, actioninput) - # (result="Compare and recommend wines to the user, providing reasons why each wine is a suitable match for their specific needs.", errormsg=nothing, success=true) elseif actionname == "CHECKINVENTORY" checkinventory(a, actioninput) + elseif actionname == "PRESENTBOX" + x = "Present the following wines to the user: $actioninput" + (result=x, errormsg=nothing, success=true) + elseif actionname == "ENDCONVERSATION" + x = "Thanks the user and end the conversation." + (result=x, errormsg=nothing, success=true) else error("undefined LLM function. Requesting $actionname") end @@ -1069,14 +1075,16 @@ function think(a::T)::NamedTuple{(:actionname, :result), Tuple{String, String}} errormsg::Union{AbstractString, Nothing} = haskey(response, :errormsg) ? response[:errormsg] : nothing success::Bool = haskey(response, :success) ? response[:success] : false - # manage memory + # manage memory (pass msg to generatechat) if actionname == "CHATBOX" a.memory[:CHATBOX] = result - elseif actionname == "PRESENTBOX" # tell the generatechat() - a.memory[:CHATBOX] = result elseif actionname == "CHECKINVENTORY" x = "You have searched the inventory, this is what you found: $result" push!(a.memory[:shortmem], Dict(Symbol(actionname)=> x)) + elseif actionname == "PRESENTBOX" # tell the generatechat() + a.memory[:CHATBOX] = result + elseif actionname == "ENDCONVERSATION" + a.memory[:CHATBOX] = result else error("condition is not defined") end @@ -1245,13 +1253,13 @@ function generatechat(memory::Dict, chathistory::Vector, text2textInstructLLM::F Context: ... You MUST follow the following guidelines: - - Once the user has selected their wine, congratulate them on their choice. If they don’t require any further assistance, politely conclude the conversation without offering additional services. + - Do not offer additional services I didn't thought. You should follow the following guidelines: - - When recommending wines, compare each option and provide reasons why each one is a suitable match for the user's specific needs. + - When recommending wines, compare each option against the others and explain why each one is a suitable match for the user's specific needs. You should then respond to the user with: - - chat: Your conversation with the user according to your thoughts. + - chat: Based on your thoughts, what will you say to the user? - mentioning_wine: Are you mentioning specific wine name to the user? Can be "Yes" or "No" You should only respond in format as described below: @@ -1272,7 +1280,7 @@ function generatechat(memory::Dict, chathistory::Vector, text2textInstructLLM::F errornote = "" response = nothing # placeholder for show when error msg show up - for attempt in 1:5 + for attempt in 1:10 usermsg = """ Your conversation with the user: $chathistory @@ -1320,7 +1328,7 @@ function generatechat(memory::Dict, chathistory::Vector, text2textInstructLLM::F # check if LLM recommend wine before checking inventory isMemEmpty = isempty(memory[:shortmem]) if occursin("Yes", responsedict[:mentioning_wine]) && isMemEmpty - errornote = "Note: You must check your inventory before recommending wine to the user." + errornote = "Note: You can't recommend wines yet. You must check your inventory before recommending wine to the user." error( "You must check your inventory before recommending wine") else errornote = "" @@ -1346,9 +1354,7 @@ end function generatequestion(a, text2textInstructLLM::Function)::String - """ - 3) ENDCONVERSATION which you can use to end the conversation with the user. The input is "NA" - """ + systemmsg = """ You are a helpful assistant acting as a polite, website-based sommelier for an online wine store. @@ -1363,7 +1369,7 @@ function generatequestion(a, text2textInstructLLM::Function)::String 1) Ask at least two questions but no more than five. 2) Your question should be specific, self-contained and not require any additional context. 3) Do not generate any question or comments at the end. - 4) Once the user has selected their wine, congratulate them on their choice. If they don’t require any further assistance, politely the conversation without offering additional services. + 4) Once the user has selected their wine, congratulate them on their choice. If they don't require any further assistance, politely the conversation without offering additional services. You should follow the following guidelines: - Do not ask the user about wine's flavor e.g. floral, citrusy, nutty or some thing similar as these terms cannot be used to search the database. diff --git a/test/runtest.jl b/test/runtest.jl index 08bd7c2..abea598 100644 --- a/test/runtest.jl +++ b/test/runtest.jl @@ -88,9 +88,9 @@ end main() """ -I'm joining a graduation party this evening. I have unlimited budget. I want a bottle of dry red wine. -Well, it is a small casual party with close friends and no food serving. -I'm open to suggestion since I have no specific idea about wine but I like full bodied wine from France. + I'm joining a graduation party this evening. I have unlimited budget. I want a bottle of dry red wine. + Well, it is a small casual party with close friends and no food serving. + I'm open to suggestion since I have no specific idea about wine but I like full bodied wine from France. """