From 38a2f673e9c878403a9fdd4e6eb763801c3241b4 Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Sun, 11 Aug 2024 01:59:28 +0700 Subject: [PATCH] update --- src/interface.jl | 16 +++++++++++----- src/llmfunction.jl | 48 ++++++++++++++++++++++++++++++---------------- test/runtest.jl | 2 +- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index cbfba6d..979f01a 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -216,7 +216,7 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent} You are a helpful assistant acting as a polite, website-based sommelier for an online wine store. You are currently talking with the user. Your goal is to recommend the best wines from your inventory that match the user's preferences. - You are not responsible for sales. + You don't need to do any sale process. At each round of conversation, you will be given the current situation: Your conversation with the user: ... @@ -1061,7 +1061,7 @@ function think(a::T)::NamedTuple{(:actionname, :result), Tuple{String, String}} x = "Present the following wines to the user: $actioninput" (result=x, errormsg=nothing, success=true) elseif actionname == "ENDCONVERSATION" - x = "Thanks the user and end the conversation." + x = "Thank the user and conclude the conversation by saying goodbye and inviting them to return next time." (result=x, errormsg=nothing, success=true) else error("undefined LLM function. Requesting $actionname") @@ -1079,7 +1079,8 @@ function think(a::T)::NamedTuple{(:actionname, :result), Tuple{String, String}} if actionname == "CHATBOX" a.memory[:CHATBOX] = result elseif actionname == "CHECKINVENTORY" - x = "You have searched the inventory, this is what you found: $result" + # x = "You have searched the inventory, this is what you found: $result" + x = result push!(a.memory[:shortmem], Dict(Symbol(actionname)=> x)) elseif actionname == "PRESENTBOX" # tell the generatechat() a.memory[:CHATBOX] = result @@ -1245,7 +1246,7 @@ function generatechat(memory::Dict, chathistory::Vector, text2textInstructLLM::F You are a helpful assistant acting as a polite, website-based sommelier for an online wine store. You are currently talking with the user. Your goal is to recommend the best wines from your inventory that match the user's preferences. - You are not responsible for sales. + You don't need to do any sale process. At each round of conversation, you will be given the current situation: Your conversation with the user: ... @@ -1321,6 +1322,11 @@ function generatechat(memory::Dict, chathistory::Vector, text2textInstructLLM::F end end + # check if Context: is in chat + if occursin("Context:", responsedict[:chat]) + error("Context: is in text. This is not allowed") + end + println("") println("--> generatechat() ", @__FILE__, " ", @__LINE__) pprintln(responsedict) @@ -1359,7 +1365,7 @@ function generatequestion(a, text2textInstructLLM::Function)::String """ You are a helpful assistant acting as a polite, website-based sommelier for an online wine store. Your task is to self questioning about the current situation. - You are not responsible for sales. + You don't need to do any sale process. At each round of conversation, you will be given the current situation: Your conversation with the user: ... diff --git a/src/llmfunction.jl b/src/llmfunction.jl index 0d2e62b..fe7fd47 100644 --- a/src/llmfunction.jl +++ b/src/llmfunction.jl @@ -366,7 +366,8 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2< attributes = ["reasoning", "wine_type", "price", "occasion", "food_to_be_paired_with_wine", "country", "region", "grape_variety", "flavors", "aromas"] errornote = "" - for attempt in 1:5 + maxattempt = 5 + for attempt in 1:maxattempt usermsg = """ @@ -398,25 +399,38 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2< end #[PENDING] check if the following attributes has more than 1 name - x = length(split(responsedict[:grape_variety], ",")) * length(split(responsedict[:grape_variety], "/")) - if x > 1 - errornote = "Note: You can put only one name in grape_variety. Pick one." - error("only a single grape_variety name is allowed") - end - x = length(split(responsedict[:country], ",")) * length(split(responsedict[:country], "/")) - if x > 1 - errornote = "Note: You can put only one name in country. Pick one." - error("only a single country name is allowed") - end - x = length(split(responsedict[:region], ",")) * length(split(responsedict[:region], "/")) - if x > 1 - errornote = "Note: You can put only one name in region. Pick one." - error("only a single region name is allowed") - end + responsedict[:grape_variety] = split(responsedict[:grape_variety], ',')[1] + responsedict[:grape_variety] = split(responsedict[:grape_variety], '/')[1] + + responsedict[:country] = split(responsedict[:country], ',')[1] + responsedict[:country] = split(responsedict[:country], '/')[1] + + responsedict[:region] = split(responsedict[:region], ',')[1] + responsedict[:region] = split(responsedict[:region], '/')[1] + + # x = length(split(responsedict[:grape_variety], ",")) * length(split(responsedict[:grape_variety], "/")) + # if x > 1 + # errornote = "Note: You can put only one name in grape_variety. Pick one." + # error("only a single grape_variety name is allowed") + # end + # x = length(split(responsedict[:country], ",")) * length(split(responsedict[:country], "/")) + # if x > 1 + # errornote = "Note: You can put only one name in country. Pick one." + # error("only a single country name is allowed") + # end + # x = length(split(responsedict[:region], ",")) * length(split(responsedict[:region], "/")) + # if x > 1 + # errornote = "Note: You can put only one name in region. Pick one." + # error("only a single region name is allowed") + # end # check if grape_variety is mentioned in the input if !occursin("NA", responsedict[:grape_variety]) && !occursin(responsedict[:grape_variety], input) - error("$(responsedict[:grape_variety]) is not mentioned in the input") + if attempt < maxattempt + error("$(responsedict[:grape_variety]) is not mentioned in the input") + else + responsedict[:grape_variety] = "NA" + end end responsedict[:flavors] = replace(responsedict[:flavors], "notes"=>"") diff --git a/test/runtest.jl b/test/runtest.jl index abea598..9ef1542 100644 --- a/test/runtest.jl +++ b/test/runtest.jl @@ -88,7 +88,7 @@ end main() """ - I'm joining a graduation party this evening. I have unlimited budget. I want a bottle of dry red wine. + I'm joining a graduation party this evening. I have unlimited budget but I'm ok with wine in all price range. I want a bottle of dry red wine. Well, it is a small casual party with close friends and no food serving. I'm open to suggestion since I have no specific idea about wine but I like full bodied wine from France.