From 689bca3805c58f11a554764e55889eea52c4be64 Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Mon, 29 Jul 2024 15:28:47 +0700 Subject: [PATCH] update --- src/interface.jl | 20 ++++++++------------ src/llmfunction.jl | 8 ++++---- test/runtest.jl | 33 ++++++++++++++++++--------------- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index db30e65..d69d9ad 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -197,7 +197,7 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent} # - plan: Based on the current situation, what would you do to complete the task? Be specific. # - action (Must be aligned with your plan): Can be one of the following functions: # 1) CHATBOX[text], which you can use to talk with the user. "text" is in verbal English. - # 2) WINESTOCK[query], which you can use to find info about wine in your inventory. "query" is a search term in verbal English. + # 2) CHECKINVENTORY[query], which you can use to find info about wine in your inventory. "query" is a search term in verbal English. # - observation: result of the action. # You should only respond in format as described below: @@ -222,15 +222,12 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent} You must follow the following DO guidelines: - If the user interrupts, prioritize the user then get back to the guidelines. + - Check your inventory before mentioning any specific wine. - Get to know how much the user willing to spend - Get to know type of wine the user is looking for e.g. red, white, sparkling, rose, dessert, fortified - 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 - - You must follow the following DON'T guidelines: - - Don't mention any specific wine until you've checked your inventory. - - Check your inventory before recommending any specific wine. You should then respond to the user with interleaving Thought, Plan, Action and Observation: - thought: @@ -238,7 +235,7 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent} - plan: Based on the current situation, state a complete plan to complete the task. Be specific. - action_name (Must be aligned with your plan): Can be one of the following functions: 1) CHATBOX[text], which you can use to talk with the user. "text" is in verbal English. - 2) WINESTOCK[query], which you can use to find info about wine in your inventory. "query" is a search term in verbal English. + 2) CHECKINVENTORY[query], which you can use to find info about wine in your inventory. "query" is a search term in verbal English. Good query example: black car with a stereo, 200 mile range and an electric motor. Good query example: How many car brand are from Asia? - action_input: input to the action @@ -280,7 +277,7 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent} ["thought", "plan", "action_name", "action_input", "observation"], rightmarker=":", symbolkey=true) - if responsedict[:action_name] ∉ ["CHATBOX", "WINESTOCK"] + if responsedict[:action_name] ∉ ["CHATBOX", "CHECKINVENTORY"] error("decisionMaker didn't use the given functions ", @__LINE__) end @@ -493,9 +490,8 @@ function evaluator(config::T1, state::T2 Analyze the trajectories of a solution to a question answering task. The trajectories are labeled by environmental observations about the situation, thoughts that can reason about the current situation and actions that can be three types: - 1) winestock[query], which you can use to find wine in your inventory. - 2) chatbox[text], which you can use to interact with the user. - 3) recommendbox[answer], which returns your wine recommendation to the user. + 1) CHECKINVENTORY[query], which you can use to find wine in your inventory. + 2) CHATBOX[text], which you can use to interact with the user. Given a question and a trajectory, evaluate its correctness and provide your reasoning and analysis in detail. Focus on the latest thought, action, and observation. Incomplete trajectories @@ -1056,8 +1052,8 @@ function think(a::T) where {T<:agent} response = if actionname == "CHATBOX" (result=actioninput, errormsg=nothing, success=true) - elseif actionname == "WINESTOCK" - winestock(a, actioninput) + elseif actionname == "CHECKINVENTORY" + checkinventory(a, actioninput) else error("undefined LLM function. Requesting $actionname") end diff --git a/src/llmfunction.jl b/src/llmfunction.jl index 07540a6..2622f6a 100644 --- a/src/llmfunction.jl +++ b/src/llmfunction.jl @@ -1,7 +1,7 @@ module llmfunction -export virtualWineUserChatbox, jsoncorrection, winestock, - virtualWineUserRecommendbox, userChatbox, userRecommendbox +export virtualWineUserChatbox, jsoncorrection, checkinventory, + virtualWineUserRecommendbox, userChatbox, userRecommendbox, extractWineAttributes using HTTP, JSON3, URIs, Random, PrettyPrinting, UUIDs using GeneralUtils, SQLLLM @@ -352,7 +352,7 @@ end julia> using ChatAgent julia> agent = ChatAgent.agentReflex("Jene") julia> input = "{\"food\": \"pizza\", \"occasion\": \"anniversary\"}" -julia> result = winestock(agent, input) +julia> result = checkinventory(agent, input) "{"wine 1": {\"Winery\": \"Pichon Baron\", \"wine name\": \"Pauillac (Grand Cru Classé)\", \"grape variety\": \"Cabernet Sauvignon\", \"year\": 2010, \"price\": \"125 USD\", \"stock ID\": \"ar-17\"}, }" ``` @@ -362,7 +362,7 @@ julia> result = winestock(agent, input) # Signature """ -function winestock(a::T1, input::T2 +function checkinventory(a::T1, input::T2 )::Union{Tuple{String, Number, Number, Bool}, Tuple{String, Nothing, Number, Bool}} where {T1<:agent, T2<:AbstractString} wineattributes = extractWineAttributes(a, input) diff --git a/test/runtest.jl b/test/runtest.jl index 5788682..86fcc90 100644 --- a/test/runtest.jl +++ b/test/runtest.jl @@ -62,6 +62,9 @@ function text2textInstructLLM(prompt::String) return response end + + + # Instantiate an agent a = YiemAgent.sommelier( text2textInstructLLM, @@ -70,22 +73,22 @@ end id="testingSessionID", # agent instance id ) -function main() - userinput = "Hello, I would like a get a bottle of wine." - for i in 1:10 - response = YiemAgent.conversation(a, Dict(:text=> userinput)) - println("") - println("--> assistant response: \n", response) - println("") - println("--> user input:") - userinput = readline() - end -end +# function main() +# userinput = "Hello, I would like a get a bottle of wine." +# for i in 1:10 +# response = YiemAgent.conversation(a, Dict(:text=> userinput)) +# println("") +# println("--> assistant response: \n", response) +# println("") +# println("--> user input:") +# userinput = readline() +# end +# end -main() +# main() # """ -# I'm having a graduation party this evening. So I think a bottle of wine would be nice. +# I'm having a graduation party this evening. I have no budget limit. # I have no idea. The party will be formal. What type of wine people usually get for this occasion? # What about sparkling Rose? @@ -116,7 +119,7 @@ main() +input = "query=\"medium-bodied dry white wine\"" - - +result = YiemAgent.extractWineAttributes(a, input)