update
This commit is contained in:
@@ -230,7 +230,7 @@ function planner_mistral_openorca(a::agentReflex)
|
||||
</s>
|
||||
$conversation
|
||||
<|assistant|>
|
||||
|
||||
Plan:
|
||||
"""
|
||||
|
||||
response = sendReceivePrompt(a, assistant_plan_prompt, max_tokens=1024, temperature=0.1,
|
||||
@@ -238,7 +238,7 @@ function planner_mistral_openorca(a::agentReflex)
|
||||
response = split(response, "<|")[1]
|
||||
response = split(response, "</")[1]
|
||||
response = split(response, "\n\n")[1]
|
||||
@show response
|
||||
@show response = "Plan: " * response
|
||||
|
||||
headerToDetect = ["Plan:", "Keyword memory:",]
|
||||
headers = detectCharacters(response, headerToDetect)
|
||||
@@ -276,9 +276,9 @@ function updatePlan(a::agentReflex)
|
||||
<s>
|
||||
<|system|>
|
||||
$(a.roles[a.role])
|
||||
Request the user’s input for the following info initially, and use alternative sources of information only if they are unable to provide it:
|
||||
Request the user’s input for the following info before you could search wine stock:
|
||||
- occasion
|
||||
- type of food ask the user
|
||||
- food pair ask the user
|
||||
- user's personal taste of wine
|
||||
- ambient temperature at the serving location
|
||||
- wine price range
|
||||
@@ -889,16 +889,15 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
|
||||
$(a.roles[a.role])
|
||||
"""
|
||||
|
||||
winestocksearchresult = nothing
|
||||
if haskey(a.memory, :winestocksearchresult) && a.memory[:winestockResult] !== nothing
|
||||
winestocksearchresult =
|
||||
"""
|
||||
<winestock search result>
|
||||
$(a.memory[:winestocksearchresult])
|
||||
</winestock search result>
|
||||
"""
|
||||
else
|
||||
winestocksearchresult = "\n"
|
||||
winestocksearchresult = false
|
||||
if haskey(a.memory, :winestock) && a.memory[:winestock] !== nothing
|
||||
# winestocksearchresult =
|
||||
# """
|
||||
# <winestock search result>
|
||||
# $(a.memory[:winestock])
|
||||
# </winestock search result>
|
||||
# """
|
||||
winestocksearchresult = true
|
||||
end
|
||||
|
||||
keywordmemory = ""
|
||||
@@ -919,8 +918,10 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
|
||||
- Luxury level is high
|
||||
{\"car type\": "SUV",\"brand\":\"Lexus\",\"price\":\"200000\",\"color\": null,\"financing method\": null, \"luxury level\":\"high\"}
|
||||
"""
|
||||
|
||||
prompt =
|
||||
#WORKING actor donot call final reapond after found matched wines because the current prompt
|
||||
# does not contain a.memory[:shortterm] and Thought: do not look for mached wine. Therefore, LLM
|
||||
# did not see matched wine info
|
||||
prompt_1 =
|
||||
"""
|
||||
<s>
|
||||
<|system|>
|
||||
@@ -933,7 +934,8 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
|
||||
</You have access to the following tools>
|
||||
<Your job>
|
||||
Use the following format:
|
||||
Thought: based on what you know about user, you should pay attention on what you don't know first then check out your plan. (PS. 1. let's think only one thing at a time. 2. pay attention to correct numeral calculation and commonsense.)
|
||||
Recall: you must explicitly state each info you did't know about the user
|
||||
Thought: Based on the recall, you must think about what is the immediate next step to do according to the plan and you must address what you didn't know urgently if you have one (PS. 1. pay attention to correct numeral calculation and commonsense.)
|
||||
Act: based on your thought what action to choose?, must be one of [{toolnames}].
|
||||
Actinput: your input to the action using JSON format (pay attention to the tool's input)
|
||||
Obs: observed result of the action
|
||||
@@ -946,10 +948,41 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
|
||||
<User info>
|
||||
$keywordmemory
|
||||
</User info>
|
||||
$winestocksearchresult
|
||||
<|assistant|>
|
||||
Recall:
|
||||
"""
|
||||
|
||||
prompt_2 =
|
||||
"""
|
||||
<s>
|
||||
<|system|>
|
||||
<About yourself>
|
||||
Your name is $(a.agentName)
|
||||
$(a.roles[a.role])
|
||||
</About yourself>
|
||||
<You have access to the following tools>
|
||||
$toollines
|
||||
</You have access to the following tools>
|
||||
<Your job>
|
||||
Use the following format:
|
||||
Thought: you always check your plan and explicitly state what you are going to do next. (PS. 1. let's think only one thing at a time. 2. pay attention to correct numeral calculation and commonsense.)
|
||||
Act: based on your thought what action to choose?, must be one of [{toolnames}].
|
||||
Actinput: your input to the action using JSON format (pay attention to the tool's input)
|
||||
Obs: observed result of the action
|
||||
</Your job>
|
||||
</|system|>
|
||||
</s>
|
||||
$(dictToString(a.memory[:shortterm]))
|
||||
<|assistant|>
|
||||
Thought:
|
||||
"""
|
||||
|
||||
prompt = prompt_1
|
||||
if winestocksearchresult
|
||||
prompt = prompt_2
|
||||
end
|
||||
|
||||
prompt = replace(prompt, "{toolnames}" => toolnames)
|
||||
|
||||
println("")
|
||||
@@ -961,7 +994,7 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
|
||||
|
||||
while true # while Thought or Act is empty, run actor again
|
||||
|
||||
response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=0.5, timeout=300,
|
||||
response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=0.4, timeout=300,
|
||||
stopword=["Thought:", "Obs:", "<|system|>", "</s>", "<|end|>"],
|
||||
seed=rand(1000000:2000000))
|
||||
println("")
|
||||
@@ -1331,7 +1364,7 @@ function actor(a::agentReflex)
|
||||
msgToUser = askbox(toolinput)
|
||||
actorState = toolname
|
||||
|
||||
#WORKING add only a single Q1 to memory because LLM need to ask the user only 1 question at a time
|
||||
# add only a single Q1 to memory because LLM need to ask the user only 1 question at a time
|
||||
latestTask = shortMemLatestTask(a.memory[:shortterm]) +1
|
||||
chunkedtext["Actinput $latestTask:"] = msgToUser
|
||||
addShortMem!(a.memory[:shortterm], chunkedtext)
|
||||
@@ -1341,27 +1374,19 @@ function actor(a::agentReflex)
|
||||
addShortMem!(a.memory[:shortterm], chunkedtext)
|
||||
println(">>> already done")
|
||||
actorState = "formulateFinalResponse"
|
||||
error(5555)
|
||||
|
||||
break
|
||||
else # function call
|
||||
addShortMem!(a.memory[:shortterm], chunkedtext)
|
||||
f = a.tools[toolname][:func]
|
||||
toolresult = f(a, actorResult)
|
||||
@show toolresult
|
||||
if toolname == ""
|
||||
a.memory[:shortterm]["Obs $latestTask:"] = "I found wines in <winestock search result>"
|
||||
a.memory[:winestockResult] = toolresult
|
||||
a.memory[:log]["Obs $latestTask:"] = "winestock search done"
|
||||
else
|
||||
a.memory[:shortterm]["Obs $latestTask:"] = toolresult
|
||||
a.memory[:log]["Obs $latestTask:"] = toolresult
|
||||
if toolname == "winestock"
|
||||
a.memory[:winestock] = toolresult
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
a.memory[:shortterm]["Obs $latestTask:"] = toolresult
|
||||
a.memory[:log]["Obs $latestTask:"] = toolresult
|
||||
end
|
||||
end
|
||||
|
||||
return actorState, msgToUser
|
||||
|
||||
@@ -130,7 +130,7 @@ function agentReflex(
|
||||
:sommelier =>
|
||||
"""
|
||||
You are a helpful sommelier at a wine retailer.
|
||||
You helps users choosing their wine from your stock.
|
||||
You helps users by searching wine that match the user preferences from your stock.
|
||||
""",
|
||||
),
|
||||
roleSpecificInstruction::Dict=Dict(
|
||||
@@ -150,15 +150,14 @@ function agentReflex(
|
||||
# """
|
||||
:sommelier =>
|
||||
"""
|
||||
Request the user’s input for the following info initially, and use alternative sources of information only if they are unable to provide it:
|
||||
- wine price: ask the user
|
||||
You need to know all of the following info before searching your wine stock, and use alternative sources of information only if the user is unable to provide it:
|
||||
- wine budget
|
||||
- wine type (rose, white, red, sparkling, dessert)
|
||||
- food type that will be served with wine
|
||||
- paring food that will be served with wine
|
||||
- wine sweetness level (dry to very sweet)
|
||||
- wine intensity level (light to full bodied)
|
||||
- wine tannin level (low to high)
|
||||
- wine acidity level (low to high)
|
||||
- wines we have in stock (use winestock tool)
|
||||
"""
|
||||
),
|
||||
|
||||
|
||||
15
src/utils.jl
15
src/utils.jl
@@ -453,10 +453,10 @@ end
|
||||
|
||||
""" Convert a vector of dict into 1-continous string.
|
||||
|
||||
Arguments:
|
||||
vecofdict, a vector of dict
|
||||
Arguments\n
|
||||
vecofdict : a vector of dict
|
||||
|
||||
Return:
|
||||
Return\n
|
||||
1-continous string
|
||||
|
||||
Example:
|
||||
@@ -487,9 +487,9 @@ function messagesToString(messages::AbstractVector{T}; addressAIas="assistant")
|
||||
end
|
||||
|
||||
if role == "user"
|
||||
conversation *= "<|$role|>\n $(content[1:end-nouse])\n</s>"
|
||||
conversation *= "<|$role|>\n $(content[1:end-nouse])\n</|$role|>"
|
||||
elseif role == "assistant"
|
||||
conversation *= "<|$addressAIas|>\n $(content[1:end-nouse])\n</s>"
|
||||
conversation *= "<|$addressAIas|>\n $(content[1:end-nouse])\n</|$addressAIas|>"
|
||||
else
|
||||
error("undefied condition role = $role $(@__LINE__)")
|
||||
end
|
||||
@@ -517,9 +517,9 @@ end
|
||||
# end
|
||||
|
||||
# if role == "user"
|
||||
# conversation *= "<|im_start|>$role: $(content[1:end-nouse])\n<|im_end|>"
|
||||
# conversation *= "<|$role|>\n $(content[1:end-nouse])\n</s>"
|
||||
# elseif role == "assistant"
|
||||
# conversation *= "<|im_start|>$addressAIas: $(content[1:end-nouse])\n<|im_end|>"
|
||||
# conversation *= "<|$addressAIas|>\n $(content[1:end-nouse])\n</s>"
|
||||
# else
|
||||
# error("undefied condition role = $role $(@__LINE__)")
|
||||
# end
|
||||
@@ -531,6 +531,7 @@ end
|
||||
# return conversation
|
||||
# end
|
||||
|
||||
|
||||
""" Convert a vector of dict into 1-continous string.
|
||||
|
||||
Arguments:
|
||||
|
||||
Reference in New Issue
Block a user