update
This commit is contained in:
@@ -212,16 +212,23 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent}
|
||||
|
||||
systemmsg =
|
||||
"""
|
||||
You are a helpful sommelier working for a wine store.
|
||||
You are an website-based polite sommelier working for an online wine store. You are currently talking with the user.
|
||||
Your task is to help the user choose the best wine that match the user preferences from your inventory.
|
||||
|
||||
Definitions:
|
||||
"observation" is result of the preceding immediate action.
|
||||
|
||||
At each round of conversation, the user will give you the current situation:
|
||||
Context: ...
|
||||
Your earlier conversation with the user: ...
|
||||
Your conversation with the user: ...
|
||||
|
||||
You MUST follow the following guidelines:
|
||||
- You won't know which wines are in stock until you check your inventory.
|
||||
- Generally speaking, your inventory has some wines from France, the United States, Australia, Spain, and Italy but you won't know which wines are in stock until you check your inventory.
|
||||
- Use the "ask the user's preferences, then check inventory" strategy to help the user, as there are many wines in the inventory.
|
||||
- Check inventory before recommending or suggesting wines to the user.
|
||||
- Only recommending wine from your inventory.
|
||||
- After recommending wine to the user, ask if there is anything else you can help with, but do not offer any additional services. If the user doesn't need anything else, say thank you and goodbye.
|
||||
- Do not offer the user to try wine as you are internet-based agent.
|
||||
|
||||
You should follow the following guidelines as you see fit:
|
||||
- If the user interrupts, prioritize the user.
|
||||
@@ -230,8 +237,6 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent}
|
||||
- Get to know what occasion the user is buying wine for.
|
||||
- Get to know what characteristics of wine the user is looking for e.g. tannin, sweetness, intensity, acidity.
|
||||
- Get to know what food will be served with wine.
|
||||
- Based on the user's information, check your inventory and recommend a suitable wine from your stock.
|
||||
- After recommending wine to the user, ask if there is anything else you can help with, but do not offer any additional services. If the user doesn’t need anything else, say thank you and goodbye.
|
||||
|
||||
You should then respond to the user with interleaving Thought, Plan, Action and Observation:
|
||||
- thought:
|
||||
@@ -243,24 +248,33 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent}
|
||||
Good query example: black car, a stereo, 200 mile range, electric motor.
|
||||
Good query example: How many car brand are from Asia?
|
||||
- action_input: input to the action
|
||||
- observation: result of the action.
|
||||
- recommending_wine: Are you recommending wines to the user? Can be "Yes" or "No"
|
||||
|
||||
You should only respond in format as described below:
|
||||
thought: ...
|
||||
plan: ...
|
||||
action_name: ...
|
||||
action_input: ...
|
||||
observation: ...
|
||||
recommending_wine: ...
|
||||
|
||||
Let's begin!
|
||||
"""
|
||||
|
||||
context = length(a.memory[:shortmem]) > 0 ? vectorOfDictToText(a.memory[:shortmem], withkey=false) : "None"
|
||||
# context = length(a.memory[:shortmem]) > 0 ? vectorOfDictToText(a.memory[:shortmem], withkey=false) : "DO not recommending wine because inventory has not been searched yet"
|
||||
context =
|
||||
if length(a.memory[:shortmem]) > 0
|
||||
vectorOfDictToText(a.memory[:shortmem], withkey=false)
|
||||
else
|
||||
"None"
|
||||
end
|
||||
|
||||
chathistory = vectorOfDictToText(a.chathistory)
|
||||
checkinventory_flag = ""
|
||||
usermsg =
|
||||
"""
|
||||
Context: $context
|
||||
Your earlier conversation with the user: $chathistory)
|
||||
Your conversation with the user: $chathistory)
|
||||
$checkinventory_flag
|
||||
"""
|
||||
|
||||
_prompt =
|
||||
@@ -280,7 +294,7 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent}
|
||||
try
|
||||
response = a.text2textInstructLLM(prompt)
|
||||
responsedict = GeneralUtils.textToDict(response,
|
||||
["thought", "plan", "action_name", "action_input", "observation"],
|
||||
["thought", "plan", "action_name", "action_input", "recommending_wine"],
|
||||
rightmarker=":", symbolkey=true)
|
||||
|
||||
if responsedict[:action_name] ∉ ["CHATBOX", "CHECKINVENTORY"]
|
||||
@@ -294,13 +308,27 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent}
|
||||
end
|
||||
|
||||
# check if there are more than 1 key per categories
|
||||
for i ∈ [:thought, :plan, :action_name, :action_input, :observation]
|
||||
for i ∈ [:thought, :plan, :action_name, :action_input, :recommending_wine]
|
||||
matchkeys = GeneralUtils.findMatchingDictKey(responsedict, i)
|
||||
if length(matchkeys) > 1
|
||||
error("DecisionMaker has more than one key per categories")
|
||||
end
|
||||
end
|
||||
|
||||
println("")
|
||||
println("--> Yiem decisionMaker ", @__FILE__, " ", @__LINE__)
|
||||
pprintln(responsedict)
|
||||
isMemEmpty = isempty(a.memory[:shortmem])
|
||||
if occursin("Yes", responsedict[:recommending_wine]) && isMemEmpty &&
|
||||
responsedict[:action_name] != "CHECKINVENTORY"
|
||||
checkinventory_flag = "You must check inventory before recommending wine to the user."
|
||||
error( "You must check inventory before recommending wine")
|
||||
else
|
||||
checkinventory_flag = ""
|
||||
end
|
||||
|
||||
delete!(responsedict, :recommending_wine)
|
||||
|
||||
return responsedict
|
||||
catch e
|
||||
io = IOBuffer()
|
||||
@@ -1016,9 +1044,6 @@ julia>
|
||||
"""
|
||||
function think(a::T)::NamedTuple{(:actionname, :result), Tuple{String, String}} where {T<:agent}
|
||||
thoughtDict = decisionMaker(a)
|
||||
println("")
|
||||
println("--> think ", @__FILE__, " ", @__LINE__)
|
||||
pprintln(thoughtDict)
|
||||
|
||||
actionname = thoughtDict[:action_name]
|
||||
actioninput = thoughtDict[:action_input]
|
||||
@@ -1049,7 +1074,7 @@ end
|
||||
[TESTING]
|
||||
"""
|
||||
function forceInventoryCheck(a::T)::NamedTuple{(:actionname, :result), Tuple{String, String}} where {T<:agent}
|
||||
|
||||
println("--> forceInventoryCheck()")
|
||||
thoughtDict = thinkCheckInventory(a)
|
||||
actionname = thoughtDict[:action_name]
|
||||
actioninput = thoughtDict[:action_input]
|
||||
@@ -1203,7 +1228,8 @@ function generatechat(memory::Dict, chathistory::Vector, text2textInstructLLM::F
|
||||
Your current thoughts in your mind: ...
|
||||
|
||||
You must follow the following guidelines:
|
||||
- Check your inventory before mentioning any wine or region to the user
|
||||
- You won't know which wines are in stock until you check your inventory.
|
||||
- Only recommending (suggesting) wine from your inventory.
|
||||
- Your thoughts matter.
|
||||
- Do not offer the user to try wine as you are internet-based agent.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user