From 8a1e31b7c8c4126129fa9cc69f5b42cb20af8530 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 11 Feb 2024 06:25:01 +0700 Subject: [PATCH] update --- src/interface.jl | 91 ++++++++++++++++++++++++++++++------------------ src/type.jl | 9 +++-- src/utils.jl | 15 ++++---- 3 files changed, 70 insertions(+), 45 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index b012853..da6a13c 100755 --- a/src/interface.jl +++ b/src/interface.jl @@ -230,7 +230,7 @@ function planner_mistral_openorca(a::agentReflex) $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, " <|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 = - """ - - $(a.memory[:winestocksearchresult]) - - """ - else - winestocksearchresult = "\n" + winestocksearchresult = false + if haskey(a.memory, :winestock) && a.memory[:winestock] !== nothing + # winestocksearchresult = + # """ + # + # $(a.memory[:winestock]) + # + # """ + 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 = """ <|system|> @@ -933,7 +934,8 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing) 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) $keywordmemory + $winestocksearchresult + <|assistant|> + Recall: + """ + + prompt_2 = + """ + + <|system|> + + Your name is $(a.agentName) + $(a.roles[a.role]) + + + $toollines + + + 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 + + + + $(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|>", "", "<|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 " - 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 diff --git a/src/type.jl b/src/type.jl index 014aa0e..2af9d96 100644 --- a/src/type.jl +++ b/src/type.jl @@ -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) """ ), diff --git a/src/utils.jl b/src/utils.jl index 69c7654..4de4386 100644 --- a/src/utils.jl +++ b/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" + conversation *= "<|$role|>\n $(content[1:end-nouse])\n" elseif role == "assistant" - conversation *= "<|$addressAIas|>\n $(content[1:end-nouse])\n" + conversation *= "<|$addressAIas|>\n $(content[1:end-nouse])\n" 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" # elseif role == "assistant" -# conversation *= "<|im_start|>$addressAIas: $(content[1:end-nouse])\n<|im_end|>" +# conversation *= "<|$addressAIas|>\n $(content[1:end-nouse])\n" # 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: