From ca81e4496bbff3a4bad4fe40b9f7b5c97d956c85 Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Thu, 1 Aug 2024 13:09:42 +0700 Subject: [PATCH] update --- src/interface.jl | 23 +++++++++++++++-------- src/llmfunction.jl | 28 ++++++++++++++++++++++------ test/runtest.jl | 4 ++-- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index 2b409ea..b6fdc0d 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -219,17 +219,20 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent} Context: ... Your earlier conversation with the user: ... - You SHOULD follow the following guidelines: - - If the user interrupts, prioritize the user then get back to the guidelines. + You should follow the following guidelines as you see fit: + - If the user interrupts, prioritize the user. - 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 + - With enough user information, search your inventory + - Recommend the wines to the user - After recommending wine to the user, ask the customer if there is anything else you can help with. If the customer doesn’t need anything else, finish the conversation. You MUST follow the following guidelines: - - Do not mentioning any wine until you've check your inventory. + - Do not mentioning any wine until you've check your inventory + - Do not ask what the user already told you You should then respond to the user with interleaving Thought, Plan, Action and Observation: - thought: @@ -253,9 +256,11 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent} Let's begin! """ + context = length(a.memory[:shortmem]) > 0 ? vectorOfDictToText(memory[:shortmem], withkey=false) : "None" + usermsg = """ - Context: None + Context: $context Your earlier conversation with the user: $(vectorOfDictToText(a.chathistory)) """ @@ -1014,6 +1019,10 @@ 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] @@ -1193,8 +1202,8 @@ function generatechat(memory::Dict, chathistory::Vector, text2textInstructLLM::F At each round of conversation, the user will give you the current situation: Context: ... - Your current thoughts in your mind: ... Your earlier conversation with the user: ... + Your current thoughts in your mind: ... You must follow the following guidelines: - Do not mentioning any wine until you've check your inventory. @@ -1219,9 +1228,7 @@ function generatechat(memory::Dict, chathistory::Vector, text2textInstructLLM::F Your earlier conversation with the user: $(vectorOfDictToText(chathistory)) Your thoughts: $(memory[:chatbox]) """ - println("") - println("--> think ", @__FILE__, " ", @__LINE__) - println(memory[:chatbox]) + _prompt = [ Dict(:name=> "system", :text=> systemmsg), diff --git a/src/llmfunction.jl b/src/llmfunction.jl index 220d3aa..ab3e4de 100644 --- a/src/llmfunction.jl +++ b/src/llmfunction.jl @@ -399,7 +399,7 @@ function extractWineAttributes_1(a::T1, input::T2 result = "" for (k, v) in responsedict - if !occursin("NA", v) + if !occursin("NA", v) && v != "" result *= "$k: $v, " end end @@ -423,7 +423,10 @@ function extractWineAttributes_1(a::T1, input::T2 error("wineattributes_wordToNumber() failed to get a response") end - +""" +# TODO + - [PENDING] "French dry white wines with medium bod" the LLM does not recognize sweetness. use LLM self questioning to solve. +""" function extractWineAttributes_2(a::T1, input::T2 )::String where {T1<:agent, T2<:AbstractString} @@ -475,10 +478,14 @@ function extractWineAttributes_2(a::T1, input::T2 You should then respond to the user with the following points: - repeat: repeat the user query exactly - - sweetness: S where S are integers represent the range of sweetness levels e.g. 1-2 - - acidity: D where D are integers represent the range of acidity level e.g. 3-4 - - tannin: T where T are integers represent the range of tannin level e.g. 4-5 - - intensity: I where I are integers represent the range of intensity level e.g. 3-4 + - sweetness: S where S are integers represent the range of sweetness levels + Example: 1-2 + - acidity: D where D are integers represent the range of acidity level + Example: 3-5 + - tannin: T where T are integers represent the range of tannin level + Example: 1-3 + - intensity: I where I are integers represent the range of intensity level + Example: 2-4 You should only respond in the form as described below: repeat: ... @@ -529,6 +536,15 @@ function extractWineAttributes_2(a::T1, input::T2 end end + # some time LLM says NA-2. Need to convert NA to 1 + for (k, v) in responsedict + if occursin("NA", v) && occursin("-", v) + new_v = replace(v, "NA"=>"1") + responsedict[k] = new_v + end + end + + result = "" for (k, v) in responsedict if !occursin("NA", v) diff --git a/test/runtest.jl b/test/runtest.jl index b48ff79..fd25c34 100644 --- a/test/runtest.jl +++ b/test/runtest.jl @@ -89,7 +89,7 @@ main() """ I'm having a graduation party this evening. I have no budget limit. I want a bottle of dry white wine. -I have no idea. The party will be formal. What type of wine people usually get for this occasion? +I have no idea. The party will be casual. I like medium bodied wine from France. What about sparkling Rose? """ @@ -118,7 +118,7 @@ What about sparkling Rose? - +# input = "French dry white wines with medium body" # input = "query=\"medium-bodied dry white wine\"" # # input = "the customer is looking for a medium-bodied, dry white wine." # result = YiemAgent.checkinventory(a, input)