This commit is contained in:
narawat lamaiin
2024-08-14 21:21:44 +07:00
parent 38a2f673e9
commit 2c095a584b
5 changed files with 250 additions and 80 deletions

View File

@@ -3,7 +3,7 @@ module llmfunction
export virtualWineUserChatbox, jsoncorrection, checkinventory, # recommendbox,
virtualWineUserRecommendbox, userChatbox, userRecommendbox
using HTTP, JSON3, URIs, Random, PrettyPrinting, UUIDs
using HTTP, JSON3, URIs, Random, PrettyPrinting, UUIDs, Dates
using GeneralUtils, SQLLLM
using ..type, ..util
@@ -289,13 +289,24 @@ julia> result = checkinventory(agent, input)
"""
function checkinventory(a::T1, input::T2
)::NamedTuple{(:result, :success, :errormsg), Tuple{String, Bool, Union{String, Nothing}}} where {T1<:agent, T2<:AbstractString}
println("--> checkinventory input: $input ", @__FILE__, " ", @__LINE__)
println("--> checkinventory order: $input ", @__FILE__, " ", @__LINE__)
wineattributes_1 = extractWineAttributes_1(a, input)
wineattributes_2 = extractWineAttributes_2(a, input)
inventoryquery = "$wineattributes_1, $wineattributes_2"
println("--> checkinventory: $inventoryquery ", @__FILE__, " ", @__LINE__)
println("--> checkinventory input: $inventoryquery ", @__FILE__, " ", @__LINE__)
result = SQLLLM.query(inventoryquery, a.executeSQL, a.text2textInstructLLM)
push!(a.memory[:events],
eventdict(;
event_description= "the assistant searched the database.",
timestamp= Dates.now(),
subject= "assistant",
action_or_dialogue= "I searched the database with this query: $inventoryquery",
outcome= "This is what I found in the database, $result"
)
)
return (result=result, success=true, errormsg=nothing)
end
@@ -338,16 +349,16 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2<
3) Do not generate other comments.
You should then respond to the user with the following points:
- reasoning: State your understanding of the current situation
- wine_type: Can be one of: "red", "white", "sparkling", "rose", "dessert" or "fortified"
- price: Must be an integer representing the cost of the wine.
- reasoning: state your understanding of the current situation
- wine_type: can be one of: "red", "white", "sparkling", "rose", "dessert" or "fortified"
- price: must be an integer representing the cost of the wine
- occasion: ...
- food_to_be_paired_with_wine: food that the user will be served with wine
- country: wine's country of origin
- region: wine's region of origin such as Burgundy, Napa Valley
- grape variety: a single name of grape used to make wine.
- flavors: Names of items that the wine tastes like.
- aromas: wine's aroma
- food_to_be_paired_with_wine: food that the user will be served with the wine
- region: a region in a country where the wine is produced, such as Burgundy, Napa Valley, etc
- country: a country where the wine is produced
- grape_variety: the name of the primary grape used to make the wine
- flavors: names of items that the wine tastes like, such as citrus, lime, etc
- aromas: the wine's aromas, such as fruity, floral, etc
You should only respond in the form as described below:
reasoning: ...
@@ -355,8 +366,8 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2<
price: ...
occasion: ...
food_to_be_paired_with_wine: ...
country: ...
region: ...
country: ...
grape_variety: ...
flavors: ...
aromas: ...
@@ -364,7 +375,7 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2<
Let's begin!
"""
attributes = ["reasoning", "wine_type", "price", "occasion", "food_to_be_paired_with_wine", "country", "region", "grape_variety", "flavors", "aromas"]
attributes = ["reasoning", "wine_type", "price", "occasion", "food_to_be_paired_with_wine", "region", "country", "grape_variety", "flavors", "aromas"]
errornote = ""
maxattempt = 5
for attempt in 1:maxattempt
@@ -427,6 +438,7 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2<
# check if grape_variety is mentioned in the input
if !occursin("NA", responsedict[:grape_variety]) && !occursin(responsedict[:grape_variety], input)
if attempt < maxattempt
errornote = "You are halucinating, $(responsedict[:grape_variety]) is not mentioned in the input"
error("$(responsedict[:grape_variety]) is not mentioned in the input")
else
responsedict[:grape_variety] = "NA"
@@ -438,6 +450,7 @@ function extractWineAttributes_1(a::T1, input::T2)::String where {T1<:agent, T2<
delete!(responsedict, :tasting_notes)
delete!(responsedict, :flavors)
delete!(responsedict, :aromas)
delete!(responsedict, :price)
# remove (some text)
for (k, v) in responsedict
@@ -527,14 +540,10 @@ function extractWineAttributes_2(a::T1, input::T2)::String where {T1<:agent, T2<
You should then respond to the user with the following points:
- reasoning: State your understanding of the current situation
- sweetness: S where S are integers represent the range of sweetness levels
Example: 1-2
- acidity: D where D are integers represent the range of acidity level
Example: 3-5
- tannin: T where T are integers represent the range of tannin level
Example: 1-3
- intensity: I where I are integers represent the range of intensity level
Example: 2-4
- sweetness: ( S ), where ( S ) represents integers indicating the range of sweetness levels. Example: 1-2
- acidity: ( A ), where ( A ) represents integers indicating the range of acidity level. Example: 3-5
- tannin: ( T ), where ( T ) represents integers indicating the range of tannin level. Example: 1-3
- intensity: ( I ), where ( I ) represents integers indicating the range of intensity level. Example: 2-4
- notes: Anything you want to add
You should only respond in the form as described below: