From a4227ec165b562dc3bc29ab74338aada6d04fe68 Mon Sep 17 00:00:00 2001 From: narawat Date: Wed, 23 Jul 2025 18:31:38 +0700 Subject: [PATCH] update --- src/interface.jl | 15 ++++++++------- src/llmfunction.jl | 42 ++++++++++++++++++++++-------------------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index 501e6f5..debdae0 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -694,14 +694,15 @@ function evaluator(state::T1, thoughtDict, text2textInstructLLM::Function, llmFo response = replace(response, "***"=>"") # check whether response has all header - detected_kw = GeneralUtils.detect_keyword(header, response) - if 0 ∈ values(detected_kw) - errornote = "Your previous attempt does not have all answer points" - println("\nERROR SQLLLM evaluator() Attempt $attempt/$maxattempt. $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + detected_kw = GeneralUtils.detectKeywordVariation(header, response) + missingkeys = [k for (k, v) in detected_kw if v === nothing] + if !isempty(missingkeys) + errornote = "$missingkeys are missing from your previous response" + println("\nERROR SQLLLM extractContent_dataframe() $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue - elseif sum(values(detected_kw)) > length(header) - errornote = "Your previous attempt has duplicated answer point" - println("\nERROR SQLLLM evaluator() Attempt $attempt/$maxattempt. $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + elseif sum([length(i) for i in values(detected_kw)]) > length(header) + errornote = "\nYour previous attempt has duplicated points according to the required response format" + println("\nERROR SQLLLM extractContent_dataframe() $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())") continue end diff --git a/src/llmfunction.jl b/src/llmfunction.jl index 0ac9018..641c317 100644 --- a/src/llmfunction.jl +++ b/src/llmfunction.jl @@ -637,15 +637,17 @@ function extractContent_dataframe(df::DataFrame, text2textInstructLLM::Function, response = GeneralUtils.deFormatLLMtext(response, llmFormatName) think, response = GeneralUtils.extractthink(response) - kw = [] - # use for loop and detect_keyword function to get the exact variation of each keyword in the text then push to kw list - for keyword in header - detected = GeneralUtils.detect_keyword(keyword, response) - push!(kw, detected) - end - if nothing ∈ kw - println("Some keywords are missing, Required keywords=$header, Response keywords=$kw ", @__FILE__, ":", @__LINE__, " $(Dates.now())") - continue # try again next loop + # check whether response has all header + detected_kw = GeneralUtils.detectKeywordVariation(header, response) + missingkeys = [k for (k, v) in detected_kw if v === nothing] + if !isempty(missingkeys) + errornote = "$missingkeys are missing from your previous response" + println("\nERROR SQLLLM extractContent_dataframe() $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + continue + elseif sum([length(i) for i in values(detected_kw)]) > length(header) + errornote = "\nYour previous attempt has duplicated points according to the required response format" + println("\nERROR SQLLLM extractContent_dataframe() $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + continue end responsedict = GeneralUtils.textToDict(response, header; @@ -929,17 +931,17 @@ function compareState(question::String, highValueStateList::Vector{T}, response = GeneralUtils.deFormatLLMtext(response, llmFormatName) think, response = GeneralUtils.extractthink(response) - # make sure every header is in the response - for i in header - detected = GeneralUtils.detect_keyword(i, response) - if detected === nothing - errornote = "Your previous attempt didn't provide $i" - errorFlag = true - end - end - if errorFlag - println("\nERROR SQLLLM compareState() Attempt $attempt $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())") - continue # skip to the next iteration + # check whether response has all header + detected_kw = GeneralUtils.detectKeywordVariation(header, response) + missingkeys = [k for (k, v) in detected_kw if v === nothing] + if !isempty(missingkeys) + errornote = "$missingkeys are missing from your previous response" + println("\nERROR SQLLLM extractContent_dataframe() $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + continue + elseif sum([length(i) for i in values(detected_kw)]) > length(header) + errornote = "\nYour previous attempt has duplicated points according to the required response format" + println("\nERROR SQLLLM extractContent_dataframe() $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())") + continue end responsedict = GeneralUtils.textToDict(response, header; dictKey=dictkey, symbolkey=true)