This commit is contained in:
narawat lamaiin
2024-08-04 21:17:48 +07:00
parent 3a5c0f188a
commit 99f19c2796
3 changed files with 39 additions and 21 deletions

View File

@@ -330,7 +330,7 @@ function extractWineAttributes_1(a::T1, input::T2
User's query: ...
The preference form requires the following information:
wine_type, price, occasion, food_to_be_paired_with_wine, country, grape_variety, wine_notes.
wine_type, price, occasion, food_to_be_paired_with_wine, country, grape_variety, flavors, aromas.
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.
@@ -345,7 +345,7 @@ function extractWineAttributes_1(a::T1, input::T2
- occasion: ...
- food_to_be_paired_with_wine: food that the user will be served with wine
- country: wine's country of origin
- grape variety: Name of grape used to make wine.
- grape variety: a single name of grape used to make wine.
- flavors: Names of items that the wine tastes like.
- aromas: wine's aroma
@@ -384,7 +384,7 @@ function extractWineAttributes_1(a::T1, input::T2
"""
attributes = ["reasoning", "wine_type", "price", "occasion", "food_to_be_paired_with_wine", "country", "grape_variety", "flavors", "aromas"]
errornote = ""
for attempt in 1:5
try
response = a.text2textInstructLLM(prompt)
@@ -396,23 +396,33 @@ function extractWineAttributes_1(a::T1, input::T2
end
end
#[PENDING] check if grape_variety has more than 1 name
if length(split(responsedict[:grape_variety], ",")) > 1
error("multiple name in grape_variety is not allowed")
end
responsedict[:flavors] = replace(responsedict[:flavors], "notes"=>"")
delete!(responsedict, :reasoning)
delete!(responsedict, :tasting_notes)
delete!(responsedict, :flavors)
delete!(responsedict, :aromas)
# remove (some text)
for (k, v) in responsedict
_v = replace(v, r"\(.*?\)" => "")
responsedict[k] = _v
end
result = ""
for (k, v) in responsedict
# some time LLM generate text with "(some comment)". this line removes it
v = replace(v, r"\(.*?\)" => "")
if !occursin("NA", v) && v != "" && !occursin("none", v) && !occursin("None", v)
result *= "$k: $v, "
end
end
#[PENDING] remove halucination. "highend dry white wine" --> "wine_type: white, occasion: special occasion, food_to_be_paired_with_wine: seafood, fish, country: France, Italy, USA, grape_variety: Chardonnay, Sauvignon Blanc, Pinot Grigio\nwine_notes: citrus, green apple, floral"
result = result[1:end-2] # remove the ending ", "
return result
@@ -551,6 +561,20 @@ function extractWineAttributes_2(a::T1, input::T2
end
end
# remove (some text)
for (k, v) in responsedict
_v = replace(v, r"\(.*?\)" => "")
responsedict[k] = _v
end
# some time LLM not put integer range
for (k, v) in responsedict
responsedict[k] = v
if length(v) > 5
error("non-range is not allowed. $k $v")
end
end
# some time LLM says NA-2. Need to convert NA to 1
for (k, v) in responsedict
if occursin("NA", v) && occursin("-", v)
@@ -562,7 +586,6 @@ function extractWineAttributes_2(a::T1, input::T2
result = ""
for (k, v) in responsedict
# some time LLM generate text with "(some comment)". this line removes it
v = replace(v, r"\(.*?\)" => "")
if !occursin("NA", v)
result *= "$k: $v, "
end