From 4397ec5fb37397ffae883c2b85a64a5dc96ca6a7 Mon Sep 17 00:00:00 2001 From: narawat Date: Mon, 27 Jul 2026 16:54:36 +0700 Subject: [PATCH] update --- src/interface.jl | 116 +++++++++++++++++---------------------------- src/llmfunction.jl | 1 - src/type.jl | 8 ++-- 3 files changed, 48 insertions(+), 77 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index 8c1ca5c..0037776 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -141,7 +141,7 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=3 "action_name": { "type": "string", "enum": ["search_web", "get_weather", "calculate_math"], - "description": "The exact name of the tool to execute." + "description": "The exact name of the action to execute." }, "action_input": { "type": "object", @@ -171,11 +171,21 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=3 "schema"=> Dict( "type"=> "object", "properties"=> Dict( - "plan"=> Dict("type"=> "string"), - "action_name"=> Dict("type"=> "string"), - "action_input"=> Dict("type"=> "string"), + "think"=> Dict( + "type"=> "string", + "description"=> "your thought" + ), + "action_name"=> Dict( + "type"=> "string", + "enum"=> ["CHAT_BOX", "SEARCH_WINE_DATABASE", "WINE_PRESENTATION_GUIDELINE", "END_CONVER_GUIDELINE"], + "description"=> "one of the available actions" + ), + "action_input"=> Dict( + "type"=> "string", + "description"=> "action's input" + ), ), - "required"=> ["plan", "action_name", "action_input"], + "required"=> ["think", "action_name", "action_input"], "additionalProperties"=> false ) ) @@ -191,46 +201,24 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=3 for attempt in 1:maxattempt response = a.context.text2textInstructLLM(a.id, msg) response = GeneralUtils.remove_french_accents(response) - # think, response = GeneralUtils.extractthink(response) # dollar sign in Julia means string interpolation while occursin('$', response) response = replace(response, '$' => "USD") end - # responsedict = nothing - # try - # responsedict = Serde.parse_yaml(response) - # catch e - # println("\nERROR YiemAgent decisionMaker() Error: $e --(not qualify response)-> $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n") - # continue - # end - - # # check whether all answer's key points are in responsedict - # println("\n---") - # println(responsedict) - # println("---\n") - # ispass, errormsg = GeneralUtils.checkAgentResponse_JSON(responsedict, requiredKeys) - - # if !ispass - # errornote = errormsg - # println("\nERROR YiemAgent decisionMaker() $errornote --(not qualify response)-> $responsedict ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n") - # continue - # end - responsedict = JSON.parse(response) - if responsedict["action_input"] == "CHAT_BOX" && - occursin("similar", responsedict["action_input"]) - + if occursin("CHAT_BOX", responsedict["action_input"]) + println("\nERROR YiemAgent decisionMaker() --(not qualify response)> $responsedict ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n") continue end - # if responsedict["action_name"] ∉ ["CHAT_BOX", "SEARCH_WINE_DATABASE", "PRESENT_WINE_GUIDELINE", "END_CONVER_GUIDELINE"] - # 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())") - # continue - # end + if responsedict["action_name"] ∉ ["WINE_PRESENTATION_GUIDELINE", "END_CONVER_GUIDELINE"] && + length(responsedict["action_input"]) < 20 + println("\nERROR YiemAgent decisionMaker() --(not qualify response)> $responsedict ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n") + continue + end # println("\nYiem decisionMaker() ", @__FILE__, ":", @__LINE__, " $(Dates.now())") # pprintln(responsedict) @@ -240,7 +228,7 @@ function decisionMaker(a::T; recentevents::Integer=20, maxattempt=3 # in case decisionMaker failed, force to use generatechat!() responsedict = OrderedDict( - "plan"=> "N/A", + "think"=> "N/A", "action_name"=> "CHAT_BOX", "action_input"=> "N/A" ) @@ -776,9 +764,9 @@ function generatechat!(a::T; maxattempt::Integer=10 - Processing sales orders or engaging in any other sales-related activities. These are the job of our sales team at the store. - 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. - # you should then respond to the user with interleaving plan, action_name, action_input in JSON format - 1) "plan", Based on the current situation, state a complete action plan to complete the task and rationale. Be specific. - 2) "action_name", action_name must be CHAT_BOX. + # you should then respond to the user with interleaving think, action_name, action_input in JSON format + 1) "think", Your step-by-step reasoning process. Explain why you are choosing this action. + 2) "action_name", Can be one of the available_actions name. 3) "action_input", Dialogue you want to chat with the user according to your plan. After the action is executed you gets "action_result". It is the output from the action you selected. @@ -814,20 +802,21 @@ function generatechat!(a::T; maxattempt::Integer=10 "schema"=> Dict( "type"=> "object", "properties"=> Dict( - "plan"=> Dict( + "think"=> Dict( "type"=> "string", - "description" => "Based on the current situation, state a complete action plan to complete the task and rationale. Be specific.", + "description" => "Your step-by-step reasoning process. Explain why you are choosing this action.", ), "action_name"=> Dict( "type"=> "string", - "description" => "action_name must be CHAT_BOX", + "enum"=> ["CHAT_BOX"], + "description" => "one of the available actions", ), "action_input"=> Dict( "type"=> "string", "description" => "Dialogue you want to chat with the user according to your plan.", ), ), - "required"=> ["plan", "action_name", "action_input"], + "required"=> ["think", "action_name", "action_input"], "additionalProperties"=> false ) ) @@ -841,43 +830,26 @@ function generatechat!(a::T; maxattempt::Integer=10 ) response = a.context.text2textInstructLLM(a.id, msg) - response = GeneralUtils.clean_json_response(response) response = GeneralUtils.remove_french_accents(response) - think, response = GeneralUtils.extractthink(response) - response = strip(response) + # dollar sign in Julia means string interpolation + while occursin('$', response) + response = replace(response, '$' => "USD") + end - responsedict = nothing - if occursin(requiredKeys[2], response) - try - _responsedict = JSON.parse(response) - responsedict = GeneralUtils.dictify(_responsedict; keytype=String, sort_order=requiredKeys) - catch - println("\nERROR YiemAgent generatechat() failed to parse response: $response ", @__FILE__, ":", @__LINE__, " $(Dates.now())") - continue - end - else - println("\nERROR YiemAgent generatechat() $errornote --(not qualify response)> $responsedict ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n") + responsedict = JSON.parse(response) + + if occursin("CHAT_BOX", responsedict["action_input"]) || + length(responsedict["action_input"]) < 20 + println("\nERROR YiemAgent generatechat() --(not qualify response)> $responsedict ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n") continue end + println("\nYiem generatechat!() ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + pprintln(responsedict) + responsedict["action_result"] = "Action result is the next user dialogue." + @info "YiemAgent generatechat!() end " @__LINE__ - # check whether all answer's key points are in responsedict - ispass, errormsg = GeneralUtils.checkAgentResponse_JSON(responsedict, requiredKeys) - if !ispass - errornote = errormsg - println("\nERROR YiemAgent generatechat() $errornote --(not qualify response)> $responsedict ", @__FILE__, ":", @__LINE__, " $(Dates.now())\n") - continue - end - - # if responsedict["action_name"] ∉ ["CHAT_BOX", "SEARCH_WINE_DATABASE", "PRESENT_WINE_GUIDELINE", "END_CONVER_GUIDELINE"] - # 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())") - # continue - # end - - # println("\nYiem decisionMaker() ", @__FILE__, ":", @__LINE__, " $(Dates.now())") - # pprintln(responsedict) responsedict["action_result"] = "Action result is the next user dialogue." @info "YiemAgent generatechat!() end " @__LINE__ return (thoughtdict=responsedict, result_raw=responsedict["action_input"]) diff --git a/src/llmfunction.jl b/src/llmfunction.jl index 55ef96f..99f0b9c 100644 --- a/src/llmfunction.jl +++ b/src/llmfunction.jl @@ -846,7 +846,6 @@ function wine_search_term_classification(a::T, searchterm::String, push!(vector_search, entry) end end - responsedict = hard_conditions println("") @show responsedict diff --git a/src/type.jl b/src/type.jl index d554f2a..d60d9e0 100644 --- a/src/type.jl +++ b/src/type.jl @@ -199,10 +199,10 @@ function sommelier( - Processing sales orders or engaging in any other sales-related activities. These are the job of our sales team at the store. - 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. - # you should then respond to the user with interleaving plan, action_name, action_input in JSON format - 1) "plan", Based on the current situation, state a complete action plan to complete the task and rationale. Be specific. - 2) "action_name", (Typically corresponds to the execution of the first step in your plan) Can be one of the available_actions name - 3) "action_input", The input to the action you are about to perform according to your plan. + # you should then respond to the user with interleaving think, action_name, action_input in JSON format + 1) "think", Your step-by-step reasoning process. Explain why you are choosing this action. + 2) "action_name", Can be one of the available actions + 3) "action_input", The input to the action you are about to perform. After the action is executed you gets "action_result". It is the output from the action you selected. # available actions -- 2.52.0