From e5248130219f2d5cf73b956f04d3d1c882af25a5 Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Mon, 26 May 2025 07:05:14 +0700 Subject: [PATCH] update --- src/interface.jl | 55 ++++++++++++++++++---------------------------- src/llmfunction.jl | 23 ++++++++++++++----- src/util.jl | 2 +- 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index 99fdc5f..eea2c7c 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -236,13 +236,15 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10 - 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. + - Once the user has selected their wine, if you haven't already, ask the user whether they need any further assistance. Do not offer any additional services. + - If the user is ending the conversation, 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. + - Gift box, gift card, and custom messages are available. Inform the user to contact our sales team. - 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. + - If you are unable to locate the desired item in the database after 2 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. @@ -291,13 +293,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 ----not qualify response--> $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 --not qualify response--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + println("\nERROR YiemAgent decisionMaker() $errornote --(not qualify response)--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue end @@ -334,7 +336,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 --not qualify response--> $(responsedict[:action_name])", @__FILE__, ":", @__LINE__, " $(Dates.now())") + println("\nERROR YiemAgent decisionMaker() $errornote --(not qualify response)--> $(responsedict[:action_name])", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue end @@ -412,12 +414,11 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=10 println("\nYiemAgent decisionMaker() ", @__FILE__, ":", @__LINE__, " $(Dates.now())") println("\n$response") - #[WORKING] evaluationdict = evaluator(a, timeline, responsedict, context) 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 --not qualify response--> \n$response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + println("\nERROR YiemAgent decisionMaker() $errornote --(not qualify response)--> \n$response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue end @@ -831,26 +832,12 @@ 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, 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. - - N/A + - The trainee's plan, action_name, and action_input must be logically consistent + - The trainee's action_input should be in a proper format as specified by the tools. 1) trajectory_evaluation: Analyze the trajectory of a solution to answer the user's original question. @@ -860,16 +847,16 @@ function evaluator(a::T1, timeline, decisiondict, evaluateecontext - Do not generate additional thoughts or actions. 2) decision_evaluation: - Examine how the trainee's decisions align with the store's policies and guidelines before proceeding. - 3) approved: Decide whether to let the trainee proceed or not. Can be "yes" or "no" - 4) suggestion: Based store policy and guidelines, provide a suggestion for the immediate decision step only. + 3) suggestion: Based store policy and guidelines, provide a suggestion for the immediate decision step only. + 4) approved: Based on suggestion, decide whether to let the trainee proceed with the decision. Can be "yes" or "no" { "trajectory_evaluation": "...", "decision_evaluation": "...", + "suggestion": "...", "approved": "...", - "suggestion": "..." } @@ -931,13 +918,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 --not qualify response--> $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 --not qualify response--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + println("\nERROR YiemAgent generatechat() $errornote --(not qualify response)--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue end @@ -1355,13 +1342,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 --not qualify response--> $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 --not qualify response--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + println("\nERROR YiemAgent presentbox() $errornote --(not qualify response)--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue end @@ -1536,13 +1523,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 --not qualify response--> $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 --not qualify response--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") +# println("\nERROR YiemAgent presentbox() $errornote --(not qualify response)--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") # continue # end @@ -1736,13 +1723,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 --not qualify response--> $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 --not qualify response--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + println("\nERROR YiemAgent generatechat() $errornote --(not qualify response)--> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue end diff --git a/src/llmfunction.jl b/src/llmfunction.jl index ad7a242..4a8febb 100644 --- a/src/llmfunction.jl +++ b/src/llmfunction.jl @@ -4,7 +4,7 @@ export virtualWineUserChatbox, jsoncorrection, checkwine, # recommendbox, virtualWineUserRecommendbox, userChatbox, userRecommendbox, extractWineAttributes_1, extractWineAttributes_2, paraphrase -using HTTP, JSON3, URIs, Random, PrettyPrinting, UUIDs, Dates +using HTTP, JSON3, URIs, Random, PrettyPrinting, UUIDs, Dates, DataFrames using GeneralUtils, SQLLLM using ..type, ..util @@ -316,7 +316,11 @@ function checkwine(a::T1, input::T2; maxattempt::Int=3 llmFormatName="qwen3") # check if all of retrieve_attributes appears in textresult isin = [occursin(x, textresult) for x in retrieve_attributes] - if !all(isin) && !occursin("The resulting table has 0 row", textresult) + # check if rawresponse type is DataFrame so that I can check for column + if typeof(rawresponse) == DataFrame && + !occursin("The resulting table has 0 row", textresult) && + !all(isin) + errornote = "Not all of $retrieve_attributes appear in search result" println("\nERROR YiemAgent checkwine() $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue @@ -402,10 +406,10 @@ function extractWineAttributes_1(a::T1, input::T2; maxattempt=10 "wine_name": "N/A", "winery": "N/A", "vintage": "N/A", - "region": "Tuscany, Napa Valley", - "country": "Italy, United States", - "wine_type": "red, white", - "grape_varietal": "Chenin Blanc, Riesling", + "region": "Tuscany or Napa Valley", + "country": "Italy or United States", + "wine_type": "red or white", + "grape_varietal": "Chenin Blanc or Riesling", "tasting_notes": "citrus", "wine_price_min": "0", "wine_price_max": "20", @@ -804,6 +808,13 @@ function extractWineAttributes_2(a::T1, input::T2)::String where {T1<:agent, T2< end end + # delete some key words from responsedict + for (k, v) in responsedict + if k ∈ [:sweetness_keyword, :acidity_keyword, :tannin_keyword, :intensity_keyword] + delete!(responsedict, k) + end + end + result = "" for (k, v) in responsedict # some time LLM generate text with "(some comment)". this line removes it diff --git a/src/util.jl b/src/util.jl index c5ef652..763d37c 100644 --- a/src/util.jl +++ b/src/util.jl @@ -306,7 +306,7 @@ function createTimeline(events::T1; eventindex::Union{UnitRange, Nothing}=nothin # elseif event[:actionname] == "CHECKINVENTORY" && event[:outcome] === nothing # timeline *= "Event_$i $(event[:subject])> action_name: $(event[:actionname]), action_input: $(event[:actioninput]), observation: Not done yet.\n" # If outcome exists, include it in formatting - if event[:actionname] == "CHECKINVENTORY" + if event[:actionname] == "CHECKWINE" timeline *= "Event_$i $(event[:subject])> action_name: $(event[:actionname]), action_input: $(event[:actioninput]), observation: $(event[:outcome])\n" else timeline *= "Event_$i $(event[:subject])> action_name: $(event[:actionname]), action_input: $(event[:actioninput])\n"