This commit is contained in:
narawat lamaiin
2024-08-10 20:58:07 +07:00
parent 07cd336d0a
commit a5f43a0403
2 changed files with 30 additions and 24 deletions

View File

@@ -228,7 +228,8 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent}
- All wines in your inventory are always in stock. - 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. - 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. - 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 dont 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: You should follow the following guidelines as you see fit:
- If the user interrupts, prioritize the user. - 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. 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: black car, a stereo, 200 mile range, electric motor.
Good query example: How many car brand are from Asia? 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 - action_input: input details of the action
- mentioning_wine: Are you mentioning specific wine name to the user? Can be "Yes" or "No" - 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]) # action_name = string(split(responsedict[:action_name], '[')[1])
# end # end
if responsedict[:action_name] ["ENDCONVERSATION", "CHATBOX", "CHECKINVENTORY"] if responsedict[:action_name] ["CHATBOX", "PRESENTBOX", "CHECKINVENTORY", "ENDCONVERSATION"]
errornote = "You must use the given functions" errornote = "You must use the given functions"
error("You must use the given functions ", @__FILE__, " ", @__LINE__) error("You must use the given functions ", @__FILE__, " ", @__LINE__)
end end
@@ -331,8 +335,8 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent}
if occursin("Yes", responsedict[:mentioning_wine]) && isMemEmpty && if occursin("Yes", responsedict[:mentioning_wine]) && isMemEmpty &&
responsedict[:action_name] != "CHECKINVENTORY" responsedict[:action_name] != "CHECKINVENTORY"
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") error( "You can't recommend wines yet. You must check your inventory before recommending wines")
else else
errornote = "" errornote = ""
end end
@@ -510,7 +514,7 @@ end
""" Assigns a scalar value to each new child node to be used for selec- """ Assigns a scalar value to each new child node to be used for selec-
tion and backpropagation. This value effectively quantifies the agents 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. serving as a heuristic to steer the search algorithm towards the most promising regions of the tree.
# Arguments # Arguments
@@ -1051,12 +1055,14 @@ function think(a::T)::NamedTuple{(:actionname, :result), Tuple{String, String}}
response = response =
if actionname == "CHATBOX" if actionname == "CHATBOX"
(result=actioninput, errormsg=nothing, success=true) (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" elseif actionname == "CHECKINVENTORY"
checkinventory(a, actioninput) 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 else
error("undefined LLM function. Requesting $actionname") error("undefined LLM function. Requesting $actionname")
end 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 errormsg::Union{AbstractString, Nothing} = haskey(response, :errormsg) ? response[:errormsg] : nothing
success::Bool = haskey(response, :success) ? response[:success] : false success::Bool = haskey(response, :success) ? response[:success] : false
# manage memory # manage memory (pass msg to generatechat)
if actionname == "CHATBOX" if actionname == "CHATBOX"
a.memory[:CHATBOX] = result a.memory[:CHATBOX] = result
elseif actionname == "PRESENTBOX" # tell the generatechat()
a.memory[:CHATBOX] = result
elseif actionname == "CHECKINVENTORY" elseif actionname == "CHECKINVENTORY"
x = "You have searched the inventory, this is what you found: $result" x = "You have searched the inventory, this is what you found: $result"
push!(a.memory[:shortmem], Dict(Symbol(actionname)=> x)) 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 else
error("condition is not defined") error("condition is not defined")
end end
@@ -1245,13 +1253,13 @@ function generatechat(memory::Dict, chathistory::Vector, text2textInstructLLM::F
Context: ... Context: ...
You MUST follow the following guidelines: You MUST follow the following guidelines:
- Once the user has selected their wine, congratulate them on their choice. If they dont 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: 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: 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" - 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: You should only respond in format as described below:
@@ -1272,7 +1280,7 @@ function generatechat(memory::Dict, chathistory::Vector, text2textInstructLLM::F
errornote = "" errornote = ""
response = nothing # placeholder for show when error msg show up response = nothing # placeholder for show when error msg show up
for attempt in 1:5 for attempt in 1:10
usermsg = usermsg =
""" """
Your conversation with the user: $chathistory 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 # check if LLM recommend wine before checking inventory
isMemEmpty = isempty(memory[:shortmem]) isMemEmpty = isempty(memory[:shortmem])
if occursin("Yes", responsedict[:mentioning_wine]) && isMemEmpty 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") error( "You must check your inventory before recommending wine")
else else
errornote = "" errornote = ""
@@ -1346,9 +1354,7 @@ end
function generatequestion(a, text2textInstructLLM::Function)::String function generatequestion(a, text2textInstructLLM::Function)::String
"""
3) ENDCONVERSATION which you can use to end the conversation with the user. The input is "NA"
"""
systemmsg = systemmsg =
""" """
You are a helpful assistant acting as a polite, website-based sommelier for an online wine store. 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. 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. 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. 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 dont 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: 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. - 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.