diff --git a/src/interface.jl b/src/interface.jl index 6c114bf..f5c5fd6 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -212,8 +212,8 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent} systemmsg = """ - You are an website-based polite sommelier working for an online wine store. You are currently talking with the user. - Your task is to help the user choose the best wine from your inventory that matches their tastes. + You are a website-based, attentive, and polite sommelier working for an online wine store. You are currently talking with the user. + Your task is to help the user choose the best wine from your inventory that matches the user preferences. Definitions: "observation" is result of the preceding immediate action. @@ -225,8 +225,8 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent} You MUST follow the following guidelines: - Generally speaking, your inventory has some wines from France, the United States, Australia, Spain, and Italy but you won't know which wines are in stock until you check your inventory. - Use the "get to know the user's preferences, then check inventory" strategy to help the user, as there are many wines in the inventory. - - After recommending wine to the user, ask if there is anything else you can help with, but do not offer any additional services. If the user doesn't need anything else, say thank you and goodbye. - - Do not ask the user about wine's flavors + - After recommending wines to the user, ask if there is anything else you can help with, but do not offer any extra services. If the user doesn't need anything else, say thank you and goodbye. + - Do not ask the user about wine's flavor e.g. floral, citrusy, nutty or some thing similar. You should follow the following guidelines as you see fit: - If the user interrupts, prioritize the user. @@ -1000,18 +1000,14 @@ function conversation(a::T, userinput::Dict) where {T<:agent} if llmCheckInv && actionname != "checkinventory" actionname, result = forceInventoryCheck(a) - if actionname == "CHATBOX" - a.memory[:chatbox] = result - else - push!(a.memory[:shortmem], Dict(Symbol(actionname)=> result)) - end + push!(a.memory[:shortmem], Dict(Symbol(actionname)=> result)) # generate chatresponse again because we have force inventory check chatresponse = generatechat(a.memory, a.chathistory, a.text2textInstructLLM) else if actionname == "CHATBOX" - a.memory[:chatbox] = result + # skip else push!(a.memory[:shortmem], Dict(Symbol(actionname)=> result)) end @@ -1221,8 +1217,8 @@ julia> function generatechat(memory::Dict, chathistory::Vector, text2textInstructLLM::Function) systemmsg = """ - You are an website-based polite sommelier working for an online wine store. - Your task is to help the user choose the best wine from your inventory that matches their tastes. + You are a website-based, attentive, and polite sommelier working for an online wine store. You are currently talking with the user. + Your task is to help the user choose the best wine from your inventory that matches the user preferences. At each round of conversation, the user will give you the current situation: Context: ... @@ -1231,7 +1227,6 @@ function generatechat(memory::Dict, chathistory::Vector, text2textInstructLLM::F You must follow the following guidelines: - Your thoughts matter. - - Do not ask the user about wine's flavors You should then respond to the user with: - chat: what do you want to say to the user based on the current situation diff --git a/src/llmfunction.jl b/src/llmfunction.jl index e532adf..f39531f 100644 --- a/src/llmfunction.jl +++ b/src/llmfunction.jl @@ -330,7 +330,7 @@ function extractWineAttributes_1(a::T1, input::T2 User's query: ... The preference form requires the following information: - wine_type, price, occasion, food_to_be_paired_with_wine, country, grape_variety, wine_notes. + wine_type, price, occasion, food_to_be_paired_with_wine, country, grape_variety, flavors, aromas. You must follow the following guidelines: 1) If specific information required in the preference form is not available in the query or there isn't any, mark with 'NA' to indicate this. @@ -345,7 +345,7 @@ function extractWineAttributes_1(a::T1, input::T2 - occasion: ... - food_to_be_paired_with_wine: food that the user will be served with wine - country: wine's country of origin - - grape variety: Name of grape used to make wine. + - grape variety: a single name of grape used to make wine. - flavors: Names of items that the wine tastes like. - aromas: wine's aroma @@ -384,7 +384,7 @@ function extractWineAttributes_1(a::T1, input::T2 """ attributes = ["reasoning", "wine_type", "price", "occasion", "food_to_be_paired_with_wine", "country", "grape_variety", "flavors", "aromas"] - + errornote = "" for attempt in 1:5 try response = a.text2textInstructLLM(prompt) @@ -396,23 +396,33 @@ function extractWineAttributes_1(a::T1, input::T2 end end + #[PENDING] check if grape_variety has more than 1 name + if length(split(responsedict[:grape_variety], ",")) > 1 + error("multiple name in grape_variety is not allowed") + end + responsedict[:flavors] = replace(responsedict[:flavors], "notes"=>"") delete!(responsedict, :reasoning) delete!(responsedict, :tasting_notes) delete!(responsedict, :flavors) delete!(responsedict, :aromas) + # remove (some text) + for (k, v) in responsedict + _v = replace(v, r"\(.*?\)" => "") + responsedict[k] = _v + end + result = "" for (k, v) in responsedict # some time LLM generate text with "(some comment)". this line removes it - v = replace(v, r"\(.*?\)" => "") if !occursin("NA", v) && v != "" && !occursin("none", v) && !occursin("None", v) result *= "$k: $v, " end end #[PENDING] remove halucination. "highend dry white wine" --> "wine_type: white, occasion: special occasion, food_to_be_paired_with_wine: seafood, fish, country: France, Italy, USA, grape_variety: Chardonnay, Sauvignon Blanc, Pinot Grigio\nwine_notes: citrus, green apple, floral" - + result = result[1:end-2] # remove the ending ", " return result @@ -551,6 +561,20 @@ function extractWineAttributes_2(a::T1, input::T2 end end + # remove (some text) + for (k, v) in responsedict + _v = replace(v, r"\(.*?\)" => "") + responsedict[k] = _v + end + + # some time LLM not put integer range + for (k, v) in responsedict + responsedict[k] = v + if length(v) > 5 + error("non-range is not allowed. $k $v") + 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) @@ -562,7 +586,6 @@ function extractWineAttributes_2(a::T1, input::T2 result = "" for (k, v) in responsedict # some time LLM generate text with "(some comment)". this line removes it - v = replace(v, r"\(.*?\)" => "") if !occursin("NA", v) result *= "$k: $v, " end diff --git a/test/runtest.jl b/test/runtest.jl index f2f0d6f..c1eb0b4 100644 --- a/test/runtest.jl +++ b/test/runtest.jl @@ -88,8 +88,8 @@ end main() """ -I'm having a graduation party this evening. I have unlimited budget. I want a bottle of dry white wine. -The party will be casual with no food serving. +I'm having a graduation party this evening. I have unlimited budget. I want a bottle of dry red wine. +It will be a casual party with no food serving. I'm open to suggestion since I have no specific idea about wine other than I like full bodied wine from France. The latter one seems nice.