This commit is contained in:
narawat lamaiin
2025-05-01 07:59:37 +07:00
parent 03de659c9b
commit cccad676db
3 changed files with 92 additions and 86 deletions

View File

@@ -300,9 +300,10 @@ function checkinventory(a::T1, input::T2
println("\ncheckinventory input: $inventoryquery ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
# add suppport for similarSQLVectorDB
textresult, rawresponse = SQLLLM.query(inventoryquery, a.func[:executeSQL],
a.func[:text2textInstructLLM],
a.func[:text2textInstructLLM];
insertSQLVectorDB=a.func[:insertSQLVectorDB],
similarSQLVectorDB=a.func[:similarSQLVectorDB])
similarSQLVectorDB=a.func[:similarSQLVectorDB],
llmFormatName="qwen3")
println("\ncheckinventory result ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
println(textresult)
@@ -330,7 +331,8 @@ julia>
# Signature
"""
function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2<:AbstractString}
function extractWineAttributes_1(a::T1, input::T2; maxattempt=10
)::String where {T1<:agent, T2<:AbstractString}
systemmsg =
"""
@@ -386,11 +388,16 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2<
dictkey = ["thought", "wine_name", "winery", "vintage", "region", "country", "wine_type", "grape_varietal", "tasting_notes", "wine_price", "occasion", "food_to_be_paired_with_wine"]
errornote = "N/A"
for attempt in 1:10
llmkwargs=Dict(
:num_ctx => 32768,
:temperature => 0.5,
)
for attempt in 1:maxattempt
#[PENDING] I should add generatequestion()
if attempt > 1
println("\nYiemAgent extractWineAttributes_1() attempt $attempt/10 ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
println("\nYiemAgent extractWineAttributes_1() attempt $attempt/$maxattempt ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
end
usermsg =
@@ -407,7 +414,8 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2<
# put in model format
prompt = GeneralUtils.formatLLMtext(_prompt, "granite3")
response = a.func[:text2textInstructLLM](prompt)
response = a.func[:text2textInstructLLM](prompt;
modelsize="medium", llmkwargs=llmkwargs, senderId=a.id)
response = GeneralUtils.remove_french_accents(response)
response = GeneralUtils.deFormatLLMtext(response, "granite3")
@@ -423,14 +431,14 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2<
end
checkFlag == true ? continue : nothing
# check whether response has all header
# check whether response has all answer's key points
detected_kw = GeneralUtils.detect_keyword(header, response)
if 0 values(detected_kw)
errornote = "In your previous attempts, the response does not have all header"
errornote = "In your previous attempts, the response does not have all answer's key points"
println("\nYiemAgent extractWineAttributes_1() Attempt $attempt $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
continue
elseif sum(values(detected_kw)) > length(header)
errornote = "In your previous attempts, the response has duplicated header"
errornote = "In your previous attempts, the response has duplicated answer's key points"
println("\nYiemAgent extractWineAttributes_1() Attempt $attempt $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
continue
end
@@ -571,14 +579,12 @@ function extractWineAttributes_2(a::T1, input::T2)::String where {T1<:agent, T2<
The preference form requires the following information:
sweetness, acidity, tannin, intensity
<You must follow the following guidelines>
You must follow the following guidelines:
1) If specific information required in the preference form is not available in the query or there isn't any, mark with 'NA' to indicate this.
Additionally, words like 'any' or 'unlimited' mean no information is available.
2) Use the conversion table to convert the descriptive word level of sweetness, intensity, tannin, and acidity into a corresponding integer.
3) Do not generate other comments.
</You must follow the following guidelines>
<You should then respond to the user with>
You should then respond to the user with:
Sweetness_keyword: The exact keywords in the user's query describing the sweetness level of the wine.
Sweetness: ( S ), where ( S ) represents integers indicating the range of sweetness levels. Example: 1-2
Acidity_keyword: The exact keywords in the user's query describing the acidity level of the wine.
@@ -587,9 +593,7 @@ function extractWineAttributes_2(a::T1, input::T2)::String where {T1<:agent, T2<
Tannin: ( T ), where ( T ) represents integers indicating the range of tannin level. Example: 1-3
Intensity_keyword: The exact keywords in the user's query describing the intensity level of the wine.
Intensity: ( I ), where ( I ) represents integers indicating the range of intensity level. Example: 2-4
</You should then respond to the user with>
<You should only respond in format as described below>
You should only respond in format as described below:
Sweetness_keyword: ...
Sweetness: ...
Acidity_keyword: ...
@@ -598,9 +602,8 @@ function extractWineAttributes_2(a::T1, input::T2)::String where {T1<:agent, T2<
Tannin: ...
Intensity_keyword: ...
Intensity: ...
</You should only respond in format as described below>
<Here are some examples>
Here are some examples:
User's query: I want a wine with a medium-bodied, low acidity, medium tannin.
Sweetness_keyword: NA
Sweetness: NA
@@ -620,7 +623,6 @@ function extractWineAttributes_2(a::T1, input::T2)::String where {T1<:agent, T2<
Tannin: NA
Intensity_keyword: NA
Intensity: NA
</Here are some examples>
Let's begin!
"""
@@ -648,14 +650,14 @@ function extractWineAttributes_2(a::T1, input::T2)::String where {T1<:agent, T2<
response = a.func[:text2textInstructLLM](prompt)
response = GeneralUtils.deFormatLLMtext(response, "granite3")
# check whether response has all header
# check whether response has all answer's key points
detected_kw = GeneralUtils.detect_keyword(header, response)
if 0 values(detected_kw)
errornote = "In your previous attempt does not have all header"
errornote = "In your previous attempt does not have all answer's key points"
println("\nERROR YiemAgent extractWineAttributes_2() Attempt $attempt $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
continue
elseif sum(values(detected_kw)) > length(header)
errornote = "In your previous attempt has duplicated header"
errornote = "In your previous attempt has duplicated answer's key points"
println("\nERROR YiemAgent extractWineAttributes_2() Attempt $attempt $errornote ", @__FILE__, ":", @__LINE__, " $(Dates.now())")
continue
end
@@ -787,13 +789,13 @@ function paraphrase(text2textInstructLLM::Function, text::String)
response = replace(response, '`' => "")
response = GeneralUtils.remove_french_accents(response)
# check whether response has all header
# check whether response has all answer's key points
detected_kw = GeneralUtils.detect_keyword(header, response)
if 0 values(detected_kw)
errornote = "\nYiemAgent paraphrase() response does not have all header"
errornote = "\nYiemAgent paraphrase() response does not have all answer's key points"
continue
elseif sum(values(detected_kw)) > length(header)
errornote = "\nnYiemAgent paraphrase() response has duplicated header"
errornote = "\nnYiemAgent paraphrase() response has duplicated answer's key points"
continue
end