diff --git a/src/interface.jl b/src/interface.jl index 72f71ca..963b83d 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -182,11 +182,10 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen 1) Make an informed decision about what you need to do to achieve the goal 2) Thanks the user when they don't need any further assistance and invite them to comeback next time - Your responsibility excludes: - 1) Asking or guiding the user to make an order or purchase - 2) Processing sales orders or engaging in any other sales-related activities - 3) Answering questions beyond just recommendations. - 4) Offering additional services beyond just recommendations. + Your responsibility does NOT includes: + 1) Asking the user to place an order or make a purchase. These are the job of our sales team at the store. + 2) Processing sales orders or engaging in any other sales-related activities. These are the job of our sales team at the store. + 3) Answering questions or offering additional services beyond those related to your store's wine recommendations such as discounts, quantity, rewards programs, promotions, delivery options, shipping, boxes, gift wrapping, packaging, personalized messages or something similar. These are the job of our sales team at the store. At each round of conversation, you will be given the current situation: Your recent events: latest 5 events of the situation @@ -195,7 +194,7 @@ 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. - - Engage in conversation to indirectly investigate the customer's intention, budget and preferences before checking your inventory. + - Approach each customer with open-ended questions to understand their preferences, budget, and occasion. This will help you guide the conversation naturally while gathering essential insights. Once you have this information, you can efficiently check your inventory for the best match. - 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. - 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. @@ -204,11 +203,10 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen - 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. - - If a customer requests information about discounts, quantity, rewards programs, promotions, delivery options, boxes, gift wrapping, packaging, or personalized messages, please inform them that they can contact our sales team at the store. - - Do not discuss other stores with the user except for your own. For your information: - - vintage 0 means non-vintage. + - Your store carries only wine. + - Vintage 0 means non-vintage. You should then respond to the user with interleaving Understanding, Reasoning, Plan, Action: 1) Understanding: @@ -221,7 +219,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen - 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 you want in your inventory. The input is a search term in verbal English. Good query example: white wine, full-bodied, France, less than 2000 USD. - - ENDCONVERSATION which you can use when you believe the user has concluded their interaction, to properly end the conversation with them. Input is "NA". + - ENDCONVERSATION which you can use when the user has finished their conversation with you, so that you can properly end the conversation. Input is "NA". 5) Action_input: input of the action You should only respond in format as described below: @@ -233,7 +231,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen Let's begin! """ - + chathistory = chatHistoryToText(a.chathistory) # check if winename in shortmem occurred in chathistory. if not, skip decision and imediately use PRESENTBOX @@ -271,7 +269,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen push!(winenames, name) end availableWineName = join(winenames, ',') - "You found information about the following wines in your inventory: $availableWineName" + "Available wines you've found in your inventory so far: $availableWineName" else "" end @@ -862,16 +860,49 @@ function think(a::T)::NamedTuple{(:actionname, :result),Tuple{String,String}} wh actionname=actionname, actioninput=chatresponse, ) - - # eventdict(; - # event_description="the assistant talks to the user.", - # timestamp=Dates.now(), - # subject="assistant", - # actioninput=chatresponse, - # ) ) result = chatresponse + # # store thoughtDict after the conversation finish + # if a.memory[:events][end][:thought][:action_name] == "ENDCONVERSATION" + # # generateSituationReport in the agent didn't include the last conversation + # # so the function will be called here + # a.memory[:recap] = generateSituationReport(a, a.func[:text2textInstructLLM]; skiprecent=0) + + # for (i, event) in enumerate(a.memory[:events]) + # if event[:subject] == "assistant" + # # create timeline of the last 3 conversation except the last one. + # # The former will be used as caching key and the latter will be the caching target + # # in vector database + # all_recapkeys = keys(a.memory[:recap]) # recap as caching + # all_recapkeys_vec = [r for r in all_recapkeys] # convert to a vector + + # # select from 1 to 2nd-to-lase event (i.e. excluding the latest which is assistant's response) + # _recapkeys_vec = all_recapkeys_vec[1:i-1] + + # # select only previous 3 recaps + # recapkeys_vec = + # if length(_recapkeys_vec) <= 3 # 1st message is a user's hello msg + # _recapkeys_vec # choose all + # else + # _recapkeys_vec[end-2:end] + # end + # #[PENDING] if there is specific data such as number, donot store in database + # tempmem = DataStructures.OrderedDict() + # for k in recapkeys_vec + # tempmem[k] = a.memory[:recap][k] + # end + + # recap = GeneralUtils.dictToString_noKey(tempmem) + # thoughtDict = a.memory[:events][i][:thought] # latest assistant thoughtDict + # a.func[:insertSommelierDecision](recap, thoughtDict) + # else + # # skip + # end + # end + # println("Caching conversation done") + # end + elseif actionname == "CHECKINVENTORY" if rawresponse !== nothing vd = GeneralUtils.dfToVectorDict(rawresponse) @@ -936,11 +967,10 @@ function generatechat(a::sommelier, thoughtDict) Your responsibility includes: 1) Given the situation, convey your thoughts to the user. - Your responsibility excludes: - 1) Asking or guiding the user to make an order or purchase - 2) Processing sales orders or engaging in any other sales-related activities - 3) Answering questions beyond just recommendations. - 4) Offering additional services beyond just recommendations. + Your responsibility does NOT includes: + 1) Asking the user to place an order or make a purchase. These are the job of our sales team at the store. + 2) Processing sales orders or engaging in any other sales-related activities. These are the job of our sales team at the store. + 3) Answering questions or offering additional services beyond those related to your store's wine recommendations such as discounts, quantity, rewards programs, promotions, delivery options, shipping, boxes, gift wrapping, packaging, personalized messages or something similar. These are the job of our sales team at the store. At each round of conversation, you will be given the current situation: Your ongoing conversation with the user: ... @@ -949,13 +979,13 @@ function generatechat(a::sommelier, thoughtDict) You MUST follow the following guidelines: - Do not offer additional services you didn't thought. + - Focus on plan. You should follow the following guidelines: - Focus on the latest conversation. - If the user interrupts, prioritize the user - Be honest - Medium and full-bodied red wines should not be paired with spicy foods. - - Do not discuss other stores with the user except for your own. 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? @@ -1146,9 +1176,10 @@ function generatequestion(a, text2textInstructLLM::Function; recent=nothing)::St Your responsibility includes: 1) Ask yourself what to do about the current situation - Your responsibility does not include: - 1) Processing sales orders or engaging in any other sales-related activities. - 2) Answering questions and offering additional services beyond just recommendations. + Your responsibility does NOT includes: + 1) Asking the user to place an order or make a purchase. These are the job of our sales team at the store. + 2) Processing sales orders or engaging in any other sales-related activities. These are the job of our sales team at the store. + 3) Answering questions or offering additional services beyond those related to your store's wine recommendations such as discounts, quantity, rewards programs, promotions, delivery options, shipping, boxes, gift wrapping, packaging, personalized messages or something similar. These are the job of our sales team at the store. At each round of conversation, you will be given the current situation: Recap: recap of what has happened so far @@ -1180,7 +1211,7 @@ function generatequestion(a, text2textInstructLLM::Function; recent=nothing)::St - State your understanding about the current situation 2) Q: Given the situation, "ask yourself" at least five, but no more than ten, questions 3) A: Given the situation, "answer to yourself" the best you can - - Do not generate any text after the last answer. + - Do not generate any extra text after you finish answering all questions You must only respond in format as described below: Understanding: ... @@ -1234,7 +1265,7 @@ function generatequestion(a, text2textInstructLLM::Function; recent=nothing)::St context = if length(a.memory[:shortmem][:available_wine]) != 0 - "Wines previously found in your inventory: $(availableWineToText(a.memory[:shortmem][:available_wine]))" + "Available wines you've found in your inventory so far: $(availableWineToText(a.memory[:shortmem][:available_wine]))" else "N/A" end @@ -1350,6 +1381,9 @@ function generateSituationReport(a, text2textInstructLLM::Function; skiprecent:: Events timeline: ... Context: ... + You should follow the following guidelines: + - Use the word "user" and "assistant" instead of their name in the report + You should then respond to the user with: event: a detailed summary for each event without exaggerated details. diff --git a/src/llmfunction.jl b/src/llmfunction.jl index 1e53d73..c831412 100644 --- a/src/llmfunction.jl +++ b/src/llmfunction.jl @@ -441,10 +441,19 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2< end # check whether max wine_price is in the input - maxprice = split(responsedict[:wine_price], '-')[end] + pricerange = split(responsedict[:wine_price], '-') + minprice = pricerange[1] + maxprice = pricerange[end] if !occursin(maxprice, input) responsedict[:wine_price] = "NA" end + # price range like 100-100 is not good + if minprice == maxprice + errornote = "wine_price with minimum equals to maximum is not valid" + println("Attempt $attempt $errornote ", Dates.now(), " ", @__FILE__, " ", @__LINE__) + checkFlag = true + break + end end else content = responsedict[j] @@ -457,7 +466,7 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2< content = [content] end - for x in content #BUG why x is "0-1500" + for x in content #check whether price are mentioned in the input if !occursin("NA", responsedict[j]) && !occursin(x, input) errornote = "$x is not mentioned in the user query, you must only use the info from the query." println("Attempt $attempt $errornote ", Dates.now(), " ", @__FILE__, " ", @__LINE__) @@ -468,7 +477,7 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2< end end end - checkFlag == true ? continue : nothing + checkFlag == true ? continue : nothing # skip the rest code if true # remove (some text) for (k, v) in responsedict diff --git a/src/util.jl b/src/util.jl index 5478394..37b92ac 100644 --- a/src/util.jl +++ b/src/util.jl @@ -107,7 +107,7 @@ function addNewMessage(a::T1, name::String, text::T2; error("name is not in agent.availableRole $(@__LINE__)") end - #[WORKING] summarize the oldest 10 message + #[PENDING] summarize the oldest 10 message if length(a.chathistory) > maximumMsg summarize(a.chathistory) else