From 3444f000625db08112a9068e7070558223b29c74 Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Mon, 19 May 2025 21:10:04 +0700 Subject: [PATCH] update --- src/interface.jl | 85 ++++++++++++++++++++++++++++-------------------- src/type.jl | 1 + 2 files changed, 50 insertions(+), 36 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index c5b5ad2..99fdc5f 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -193,22 +193,6 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10 1) Requesting the user to place an order, make a purchase, or confirm the order. 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. - - - - Generally speaking, the store inventory has some wines from France, the United States, Australia, Spain, and Italy, but you won't know exactly until you check your inventory. - - If you found wines in the store's database, they are in stock - - Approach each customer with open-ended questions to understand their preferences, budget, and occasion. Once you have these information, you can check your inventory. - - 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. Other wine characteristics useful for CHECKINVENTORY tools are allowed. - - 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. - - Spicy foods should not be paired with medium and full-bodied red wines. - - We do not sell organic, sustainability and sulfite wine. - - - - Encourage the customer to explore different options and try new things. - - If you are unable to locate the desired item in the database after multiple attempts, it may not be available in your inventory. In such cases, inform the user that the item is unavailable and suggest an alternative instead. - - Your store carries only wine. - - Vintage 0 means non-vintage. - At each round of conversation, you will be given the following information: context: additional information about the current situation @@ -247,6 +231,21 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10 context = """ + + - Generally speaking, the store inventory has some wines from France, the United States, Australia, Spain, and Italy, but you won't know exactly until you check your inventory. + - If you found wines in the store's database, they are in stock + - Approach each customer with open-ended questions to understand their preferences, budget, and occasion. Once you have these information, you can check your inventory. + - 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. Other wine characteristics useful for CHECKINVENTORY tools are allowed. + - Once the user has selected their wine, if you haven't already, 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. + - Spicy foods should not be paired with medium and full-bodied red wines. + - We do not sell organic, sustainability and sulfite wine. + + + - Encourage the customer to explore different options and try new things. + - If you are unable to locate the desired item in the database after multiple attempts, it may not be available in your inventory. In such cases, inform the user that the item is unavailable and suggest an alternative instead. + - Your store carries only wine. + - Vintage 0 means non-vintage. + - CHATBOX which you can use to talk with the user. Be specific. - CHECKWINE allows you to check information about wines you want in your inventory's database. The input must be supported search criteria includeing: wine price, winery, name, vintage, region, country, type, grape varietal, tasting notes, occasion, food pairing, intensity, tannin, sweetness, and acidity. @@ -292,13 +291,13 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10 if length(is_requiredKeys_in_responsedictKey) > length(requiredKeys) errornote = "Your previous attempt has more key points than answer's required key points." - println("\nERROR YiemAgent decisionMaker() $errornote --> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + println("\nERROR YiemAgent decisionMaker() $errornote ----not qualify response--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue elseif !all(is_requiredKeys_in_responsedictKey) zeroind = findall(x -> x == 0, is_requiredKeys_in_responsedictKey) missingkeys = [requiredKeys[i] for i in zeroind] errornote = "$missingkeys are missing from your previous response" - println("\nERROR YiemAgent decisionMaker() $errornote --> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + println("\nERROR YiemAgent decisionMaker() $errornote --not qualify response--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue end @@ -335,7 +334,7 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10 if responsedict[:action_name] ∉ ["CHATBOX", "CHECKWINE", "PRESENTBOX", "ENDCONVERSATION"] errornote = "Your previous attempt didn't use the given functions" - println("\nERROR YiemAgent decisionMaker() $errornote --> $(responsedict[:action_name])", @__FILE__, ":", @__LINE__, " $(Dates.now())") + println("\nERROR YiemAgent decisionMaker() $errornote --not qualify response--> $(responsedict[:action_name])", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue end @@ -402,9 +401,6 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10 end delete!(responsedict, :mentioned_winery) - responsedict[:systemmsg] = systemmsg - responsedict[:unformatPrompt] = unformatPrompt - # responsedict[:QandA] = QandA # check whether responsedict[:action_input] is the same as previous dialogue if responsedict[:action_input] == a.chathistory[end][:text] @@ -421,17 +417,26 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10 if evaluationdict[:approved] == "no" mentor_comment = evaluationdict[:suggestion] errornote = "Your previous attempt was not good enough. Please try again. Here is the mentor's suggestion: $mentor_comment" - println("\nERROR YiemAgent decisionMaker() $errornote --> \n$response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + println("\nERROR YiemAgent decisionMaker() $errornote --not qualify response--> \n$response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue end # store for later training responsedict[:system] = systemmsg + responsedict[:unformatPrompt] = unformatPrompt responsedict[:recentchat] = recentchat responsedict[:prompt] = prompt responsedict[:context] = context responsedict[:think] = think + responsedict[:response] = response # responsedict[:QandA] = QandA + + # check whether there is a file path exists before writing to it + if !haskey(a.memory[:shortmem], :decisionlog) + a.memory[:shortmem][:decisionlog] = [responsedict] + else + push!(a.memory[:shortmem][:decisionlog], responsedict) + end # # save to filename ./log/decisionlog.txt # println("\nsaving YiemAgent decisionMaker() to disk ", @__FILE__, ":", @__LINE__, " $(Dates.now())") @@ -454,6 +459,7 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10 # end # end # println("\nYiemAgent decisionMaker() saved to disk is done. agent $(a.id)") + responsedict[:prompt] = prompt return responsedict @@ -825,21 +831,21 @@ function evaluator(a::T1, timeline, decisiondict, evaluateecontext "action_name" is the name of the action taken, which can be one of the available tool name. "action_input" is the input to the action. - + - Generally speaking, the store inventory has some wines from France, the United States, Australia, Spain, and Italy, but you won't know exactly until you check your inventory. - If you found wines in the store's database, they are in stock - Approach each customer with open-ended questions to understand their preferences, budget, and occasion. Once you have these information, you can check your inventory. - 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. Other wine characteristics useful for CHECKINVENTORY tools are allowed. - - 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. + - Once the user has selected their wine, if you haven't already, 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. - Spicy foods should not be paired with medium and full-bodied red wines. - We do not sell organic, sustainability and sulfite wine. - - + + - Encourage the customer to explore different options and try new things. - If you are unable to locate the desired item in the database after multiple attempts, it may not be available in your inventory. In such cases, inform the user that the item is unavailable and suggest an alternative instead. - Your store carries only wine. - Vintage 0 means non-vintage. - + - Use only infomation provided by the store policy and guidelines as a bedrocks for your response. @@ -925,13 +931,13 @@ function evaluator(a::T1, timeline, decisiondict, evaluateecontext if length(is_requiredKeys_in_responsedictKey) > length(requiredKeys) errornote = "Your previous attempt has more key points than answer's required key points." - println("\nERROR YiemAgent generatechat() $errornote --> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + println("\nERROR YiemAgent generatechat() $errornote --not qualify response--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue elseif !all(is_requiredKeys_in_responsedictKey) zeroind = findall(x -> x == 0, is_requiredKeys_in_responsedictKey) missingkeys = [requiredKeys[i] for i in zeroind] errornote = "$missingkeys are missing from your previous response" - println("\nERROR YiemAgent generatechat() $errornote --> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + println("\nERROR YiemAgent generatechat() $errornote --not qualify response--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue end @@ -1349,13 +1355,13 @@ function presentbox(a::sommelier, thoughtDict; maxtattempt::Integer=10, recentev if length(is_requiredKeys_in_responsedictKey) > length(requiredKeys) errornote = "Your previous attempt has more key points than answer's required key points." - println("\nERROR YiemAgent presentbox() $errornote --> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + println("\nERROR YiemAgent presentbox() $errornote --not qualify response--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue elseif !all(is_requiredKeys_in_responsedictKey) zeroind = findall(x -> x == 0, is_requiredKeys_in_responsedictKey) missingkeys = [requiredKeys[i] for i in zeroind] errornote = "$missingkeys are missing from your previous response" - println("\nERROR YiemAgent presentbox() $errornote --> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + println("\nERROR YiemAgent presentbox() $errornote --not qualify response--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue end @@ -1530,13 +1536,13 @@ end # if length(is_requiredKeys_in_responsedictKey) > length(requiredKeys) # errornote = "Your previous attempt has more key points than answer's required key points." -# println("\nERROR YiemAgent presentbox() $errornote --> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") +# println("\nERROR YiemAgent presentbox() $errornote --not qualify response--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") # continue # elseif !all(is_requiredKeys_in_responsedictKey) # zeroind = findall(x -> x == 0, is_requiredKeys_in_responsedictKey) # missingkeys = [requiredKeys[i] for i in zeroind] # errornote = "$missingkeys are missing from your previous response" -# println("\nERROR YiemAgent presentbox() $errornote --> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") +# println("\nERROR YiemAgent presentbox() $errornote --not qualify response--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") # continue # end @@ -1730,13 +1736,13 @@ function generatechat(a::sommelier, thoughtDict; maxattempt::Integer=10) if length(is_requiredKeys_in_responsedictKey) > length(requiredKeys) errornote = "Your previous attempt has more key points than answer's required key points." - println("\nERROR YiemAgent generatechat() $errornote --> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + println("\nERROR YiemAgent generatechat() $errornote --not qualify response--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue elseif !all(is_requiredKeys_in_responsedictKey) zeroind = findall(x -> x == 0, is_requiredKeys_in_responsedictKey) missingkeys = [requiredKeys[i] for i in zeroind] errornote = "$missingkeys are missing from your previous response" - println("\nERROR YiemAgent generatechat() $errornote --> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + println("\nERROR YiemAgent generatechat() $errornote --not qualify response--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue end @@ -2003,6 +2009,13 @@ function generatechat(a::virtualcustomer; continue end + # check if the dialogue is the same as the previous one + if responsedict[:dialogue] == a.chathistory[end][:text] + errornote = "In your previous attempt you said $(responsedict[:dialogue]) which was the same as the previous one." + println("\nYiemAgent generatechat() $errornote:\n$response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + continue + end + # println("\n$prompt", @__FILE__, ":", @__LINE__, " $(Dates.now())") diff --git a/src/type.jl b/src/type.jl index b21d69c..242da74 100644 --- a/src/type.jl +++ b/src/type.jl @@ -200,6 +200,7 @@ function sommelier( :state=> Dict{Symbol, Any}( ), :recap=> OrderedDict{Symbol, Any}(), + ) newAgent = sommelier(