This commit is contained in:
2024-12-26 06:15:12 +07:00
parent 9768f22019
commit 795e8a6e31
2 changed files with 27 additions and 33 deletions

View File

@@ -592,14 +592,19 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2<
# check if winery, wine_name, region, country, wine_type, grape_variety are in the query because sometime AI halucinates
for i in [:grape_variety, :winery, :wine_name, :region]
result = check_key_in_input(input, responsedict, attempt, maxattempt, i)
if result === nothing
# nothing wrong
elseif result == "NA"
responsedict[i] = "NA"
content = responsedict[i]
if occursin(",", content)
content = split(content, ",") # sometime AI generates multiple values e.g. "Chenin Blanc, Riesling"
content = strip.(content)
else
errornote = result
error(errornote)
content = [content]
end
for x in content
if !occursin("NA", responsedict[i]) && !occursin(x, input)
errornote = "$x is not mentioned in the user query, you must only use the info from the query."
error(errornote)
end
end
end
@@ -1027,21 +1032,6 @@ function jsoncorrection(config::T1, input::T2, correctJsonExample::T3;
end
function check_key_in_input(input::String, responsedict, attempt::Int, maxattempt::Int, key::Symbol)
if !occursin("NA", responsedict[key]) && !occursin(responsedict[key], input)
if attempt < maxattempt
errornote = "$(responsedict[key]) is not mentioned in the user query, you must only use the info from the query."
return errornote
else
return "NA"
end
else
return nothing
end
end
# function isrecommend(state::T1, text2textInstructLLM::Function
# ) where {T1<:AbstractDict}