From 795e8a6e3160e5fe86110b884f4abc6d42df95d9 Mon Sep 17 00:00:00 2001 From: tonaerospace Date: Thu, 26 Dec 2024 06:15:12 +0700 Subject: [PATCH] update --- src/interface.jl | 26 +++++++++++++++----------- src/llmfunction.jl | 34 ++++++++++++---------------------- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index 4c266d2..676656e 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -123,7 +123,6 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen # """ # end - # check vectorDB for similar cached decision. USE combined event T, T-1 totalevents = length(a.memory[:events]) ind = if totalevents > recent @@ -153,7 +152,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen """ Your name is $(a.name). You are a helpful English-speaking assistant, acting as a polite, website-based sommelier for $(a.retailername)'s online store. Your goal includes: - 1) Get to know the user preferences about wine + 1) Establish a connection with the customer by greeting them warmly 2) Help them select the best wines from your inventory that align with their preferences Your responsibility includes: @@ -171,14 +170,14 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen 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 exactly until you check your inventory. - All wines in your inventory are always in stock. - - If the user interrupts, prioritize the user + - Before checking the inventory, engage in conversation to indirectly investigate the customer's intention, budget and preferences, which will significantly improve inventory search results. - Do not ask the user about wine's flavor e.g. floral, citrusy, nutty or some thing similar as these terms cannot be used to search the database. - - The best strategy for searching an inventory is to start broadly and then narrow down. - Once the user has selected their wine, ask the user if they need any further assistance. Do not offer any additional services. If the user doesn't need any further assistance, say goodbye and invite them to come back next time. + - Medium and full-bodied red wines should not be paired with spicy foods. - Tips: - - Understanding the user's preferences is key in helping them find the best wine. - - Identifying at least four preferences before checking inventory significantly improves search results + You should follow the following guidelines: + - When searching an inventory, search as broadly as possible based on the information you have gathered so far. + - Encourage the customer to explore different options and try new things. - Sometimes, the item a user desires might not be available in your inventory. In such cases, inform the user that the item is unavailable and suggest an alternative instead. For your information: @@ -193,7 +192,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen 4) Action_name (Must be aligned with your plan): The name of the action. Typically corresponds to the execution of the first step in your plan. Can be one of the following functions: - CHATBOX which you can use to talk with the user. The input is your intentions for the dialogue. Be specific. - - CHECKINVENTORY which you can use to check info about wine in your inventory. The input is a search term in verbal English. + - CHECKINVENTORY which you can use to check info about wine you want in your inventory. The input is a search term in verbal English. Good query example: black car, a stereo, 200 mile range, electric motor. - ENDCONVERSATION which you can use when you believe the user has concluded their interaction, to properly end the conversation with them. Input is "NA". 5) Action_input: input of the action @@ -221,9 +220,10 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen println("\n~~~ Yiem decisionMaker() found wines from DB ", @__FILE__, " ", @__LINE__) return Dict(:action_name=> "PRESENTBOX", :action_input=> """ - 1) Provide detailed introductions of the wines you just found to help the user make an informed choice. - 2) If there are multiple wines, offer thorough comparison of each option, highlighting their differences. - 3) Explain the potential impact each option could bring to the user. + 1) Provide detailed introductions of the wines you just found to the customer. + 2) Explain how the wine could match the customer's intention and what its effects might mean for the customer's experience. + 3) If multiple wines are available, highlight their differences and provide a comprehensive comparison of how each option aligns with the customer's intention and what the potential effects of each option could mean for the customer's experience. + 4) Provide your personal recommendation based on your understanding of the customer's preferences. """) end end @@ -892,6 +892,7 @@ function generatechat(a::sommelier, thought::T) where {T<:AbstractString} You should follow the following guidelines: - Focus on the latest conversation. - If the user interrupts, prioritize the user + - Medium and full-bodied red wines should not be paired with spicy foods. You should then respond to the user with: 1) Chat: Given the situation, How would you respond to the user to express your thoughts honestly and keep the conversation going smoothly? @@ -1133,6 +1134,9 @@ function generatequestion(a, text2textInstructLLM::Function; recent=nothing)::St ... Here are some examples: + Q: The user is buying for her husband, should I dig in to get more information? + A: Yes, I should. So that I have better idea about the user's preferences. + Q: Why the user saying this? A: According to the situation, ... diff --git a/src/llmfunction.jl b/src/llmfunction.jl index 1c05170..c0877e9 100644 --- a/src/llmfunction.jl +++ b/src/llmfunction.jl @@ -592,14 +592,19 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2< # check if winery, wine_name, region, country, wine_type, grape_variety are in the query because sometime AI halucinates for i in [:grape_variety, :winery, :wine_name, :region] - result = check_key_in_input(input, responsedict, attempt, maxattempt, i) - if result === nothing - # nothing wrong - elseif result == "NA" - responsedict[i] = "NA" + content = responsedict[i] + if occursin(",", content) + content = split(content, ",") # sometime AI generates multiple values e.g. "Chenin Blanc, Riesling" + content = strip.(content) else - errornote = result - error(errornote) + content = [content] + end + + for x in content + if !occursin("NA", responsedict[i]) && !occursin(x, input) + errornote = "$x is not mentioned in the user query, you must only use the info from the query." + error(errornote) + end end end @@ -1027,21 +1032,6 @@ function jsoncorrection(config::T1, input::T2, correctJsonExample::T3; end -function check_key_in_input(input::String, responsedict, attempt::Int, maxattempt::Int, key::Symbol) - if !occursin("NA", responsedict[key]) && !occursin(responsedict[key], input) - if attempt < maxattempt - errornote = "$(responsedict[key]) is not mentioned in the user query, you must only use the info from the query." - return errornote - else - return "NA" - end - else - return nothing - end -end - - - # function isrecommend(state::T1, text2textInstructLLM::Function # ) where {T1<:AbstractDict}