From 5a890860a63ee2c36d9a9600fbc21e485a6d6ede Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Sat, 22 Mar 2025 09:42:51 +0700 Subject: [PATCH] update --- src/interface.jl | 56 ++++++++++++++++++++++++++++++++++++++++++------ test/config.json | 2 +- test/test_1.jl | 6 +++--- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index e44aafd..39da605 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -231,6 +231,9 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen Let's begin! """ + + header = ["Understanding:", "Reasoning:", "Plan:", "Action_name:", "Action_input:"] + dictkey = ["understanding", "reasoning", "plan", "action_name", "action_input"] chathistory = chatHistoryToText(a.chathistory) @@ -316,8 +319,16 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen continue end - header = ["Understanding:", "Reasoning:", "Plan:", "Action_name:", "Action_input:"] - dictkey = ["understanding", "reasoning", "plan", "action_name", "action_input"] + # check whether response has all header + detected_kw = GeneralUtils.detect_keyword(header, response) + if sum(values(detected_kw)) < length(header) + errornote = "\nSQL evaluator() response does not have all header" + continue + elseif sum(values(detected_kw)) > length(header) + errornote = "\nSQL evaluator() response has duplicated header" + continue + end + responsedict = GeneralUtils.textToDict(response, header; dictKey=dictkey, symbolkey=true) @@ -1229,6 +1240,9 @@ function generatequestion(a, text2textInstructLLM::Function; recent=nothing)::St Let's begin! """ + + header = ["Understanding:", "Q1:"] + dictkey = ["understanding", "q1"] context = if length(a.memory[:shortmem][:available_wine]) != 0 @@ -1339,8 +1353,16 @@ function generatequestion(a, text2textInstructLLM::Function; recent=nothing)::St error("no answer found in the response ", Dates.now(), " ", @__FILE__, " ", @__LINE__) end - header = ["Understanding:", "Q1:"] - dictkey = ["understanding", "q1"] + # check whether response has all header + detected_kw = GeneralUtils.detect_keyword(header, response) + if sum(values(detected_kw)) < length(header) + errornote = "\nSQL evaluator() response does not have all header" + continue + elseif sum(values(detected_kw)) > length(header) + errornote = "\nSQL evaluator() response has duplicated header" + continue + end + responsedict = GeneralUtils.textToDict(response, header; dictKey=dictkey, symbolkey=true) response = "Q1: " * responsedict[:q1] @@ -1424,6 +1446,17 @@ function generateSituationReport(a, text2textInstructLLM::Function; skiprecent:: prompt = GeneralUtils.formatLLMtext(_prompt; formatname="qwen") response = text2textInstructLLM(prompt) + + # check whether response has all header + detected_kw = GeneralUtils.detect_keyword(header, response) + if sum(values(detected_kw)) < length(header) + errornote = "\nYiemAgent generateSituationReport() response does not have all header" + continue + elseif sum(values(detected_kw)) > length(header) + errornote = "\nYiemAgent generateSituationReport() response has duplicated header" + continue + end + responsedict = GeneralUtils.textToDict(response, header; dictKey=dictkey, symbolkey=true) @@ -1459,6 +1492,9 @@ function detectWineryName(a, text) Let's begin! """ + + header = ["Winery_names:"] + dictkey = ["winery_names"] response = nothing # placeholder for show when error msg show up @@ -1481,8 +1517,16 @@ function detectWineryName(a, text) println("\n~~~ detectWineryName() ", Dates.now(), " ", @__FILE__, " ", @__LINE__) pprintln(response) - header = ["Winery_names:"] - dictkey = ["winery_names"] + # check whether response has all header + detected_kw = GeneralUtils.detect_keyword(header, response) + if sum(values(detected_kw)) < length(header) + errornote = "\nSQL evaluator() response does not have all header" + continue + elseif sum(values(detected_kw)) > length(header) + errornote = "\nSQL evaluator() response has duplicated header" + continue + end + responsedict = GeneralUtils.textToDict(response, header; dictKey=dictkey, symbolkey=true) diff --git a/test/config.json b/test/config.json index 74c7a75..13ca00f 100644 --- a/test/config.json +++ b/test/config.json @@ -27,7 +27,7 @@ "description": "agent role" }, "organization": { - "value": "yiem_hq", + "value": "yiem_branch_1", "description": "organization name" }, "externalservice": { diff --git a/test/test_1.jl b/test/test_1.jl index aaef67f..5699e2e 100644 --- a/test/test_1.jl +++ b/test/test_1.jl @@ -36,7 +36,7 @@ function executeSQLVectorDB(sql) return result end -function text2textInstructLLM(prompt::String; maxattempt=3) +function text2textInstructLLM(prompt::String; maxattempt=2) msgMeta = GeneralUtils.generate_msgMeta( config[:externalservice][:loadbalancer][:mqtttopic]; msgPurpose="inference", @@ -60,7 +60,7 @@ function text2textInstructLLM(prompt::String; maxattempt=3) response = nothing for attempts in 1:maxattempt - _response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg; timeout=300, maxattempt=maxattempt) + _response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg; timeout=180, maxattempt=maxattempt) payload = _response[:response] if _response[:success] && payload[:text] !== nothing response = _response[:response][:text] @@ -234,7 +234,7 @@ a = YiemAgent.sommelier( ) while true - println("your respond: ") + print("your respond: ") user_answer = readline() response = YiemAgent.conversation(a, Dict(:text=> user_answer)) println("\n$response")