This commit is contained in:
narawat lamaiin
2024-10-14 12:48:55 +07:00
parent 8b67eb1713
commit a35e6e5ba8
2 changed files with 17 additions and 29 deletions

View File

@@ -232,7 +232,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol, Any} where {T<:age
systemmsg = systemmsg =
""" """
Your name is $(a.name). You are a helpful assistant acting as a polite, website-based sommelier for $(a.retailername) store. Your name is $(a.name). You are a helpful assistant acting as a polite, website-based sommelier for $(a.retailername)'s online store.
Your goal includes: Your goal includes:
1) Get to know the user preferences about wine 1) Get to know the user preferences about wine
2) Help them select the best wines from your inventory that align with their preferences 2) Help them select the best wines from your inventory that align with their preferences
@@ -363,8 +363,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol, Any} where {T<:age
end end
end end
println("") println("\n~~~ Yiem decisionMaker() ", @__FILE__, " ", @__LINE__)
println("--> Yiem decisionMaker() ", @__FILE__, " ", @__LINE__)
pprintln(Dict(responsedict)) pprintln(Dict(responsedict))
# check if LLM recommend wine before checking inventory # check if LLM recommend wine before checking inventory
@@ -391,9 +390,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol, Any} where {T<:age
showerror(io, e) showerror(io, e)
errorMsg = String(take!(io)) errorMsg = String(take!(io))
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace())) st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
println("") println("\nAttempt $attempt. \nError occurred: $errorMsg\n$st \nPrompt $prompt", @__FILE__, " ", @__LINE__)
println("Attempt $attempt. Error occurred: $errorMsg\n$st ", @__FILE__, " ", @__LINE__)
println("")
end end
end end
error("DecisionMaker failed to generate a thought ", response) error("DecisionMaker failed to generate a thought ", response)
@@ -546,9 +543,7 @@ function evaluator(config::T1, state::T2
showerror(io, e) showerror(io, e)
errorMsg = String(take!(io)) errorMsg = String(take!(io))
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace())) st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
println("") println("\nAttempt $attempt. Error occurred: $errorMsg\n$st ", @__FILE__, " ", @__LINE__)
println("Attempt $attempt. Error occurred: $errorMsg\n$st ", @__FILE__, " ", @__LINE__)
println("")
end end
end end
error("evaluator failed to generate an evaluation") error("evaluator failed to generate an evaluation")
@@ -679,9 +674,7 @@ function reflector(config::T1, state::T2)::String where {T1<:AbstractDict, T2<:A
showerror(io, e) showerror(io, e)
errorMsg = String(take!(io)) errorMsg = String(take!(io))
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace())) st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
println("") println("\nAttempt $attempt. Error occurred: $errorMsg\n$st ", @__FILE__, " ", @__LINE__)
println("Attempt $attempt. Error occurred: $errorMsg\n$st ", @__FILE__, " ", @__LINE__)
println("")
end end
end end
error("reflector failed to generate a thought") error("reflector failed to generate a thought")
@@ -1149,8 +1142,7 @@ function generatechat(a::sommelier)
error("Context: is in text. This is not allowed") error("Context: is in text. This is not allowed")
end end
println("") println("\n~~~ generatechat() ", @__FILE__, " ", @__LINE__)
println("--> generatechat() ", @__FILE__, " ", @__LINE__)
pprintln(Dict(responsedict)) pprintln(Dict(responsedict))
# check if LLM recommend wine before checking inventory # check if LLM recommend wine before checking inventory
@@ -1177,9 +1169,7 @@ function generatechat(a::sommelier)
showerror(io, e) showerror(io, e)
errorMsg = String(take!(io)) errorMsg = String(take!(io))
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace())) st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
println("") println("\nAttempt $attempt. Error occurred: $errorMsg\n$st ", @__FILE__, " ", @__LINE__)
println("Attempt $attempt. Error occurred: $errorMsg\n$st ", @__FILE__, " ", @__LINE__)
println("")
end end
end end
error("generatechat failed to generate an evaluation") error("generatechat failed to generate an evaluation")
@@ -1235,8 +1225,7 @@ function generatechat(a::companion)
try try
response = a.text2textInstructLLM(prompt) response = a.text2textInstructLLM(prompt)
println("") println("\n~~~ generatechat() ", @__FILE__, " ", @__LINE__)
println("--> generatechat() ", @__FILE__, " ", @__LINE__)
pprintln(response) pprintln(response)
responsedict = GeneralUtils.textToDict(response,["Chat"], responsedict = GeneralUtils.textToDict(response,["Chat"],
@@ -1250,9 +1239,7 @@ function generatechat(a::companion)
showerror(io, e) showerror(io, e)
errorMsg = String(take!(io)) errorMsg = String(take!(io))
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace())) st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
println("") println("\n Attempt $attempt. Error occurred: $errorMsg\n$st ", @__FILE__, " ", @__LINE__)
println("Attempt $attempt. Error occurred: $errorMsg\n$st ", @__FILE__, " ", @__LINE__)
println("")
noise = GeneralUtils.randstrings(3, 5) noise = GeneralUtils.randstrings(3, 5)
end end
end end
@@ -1308,7 +1295,7 @@ function generatequestion(a, text2textInstructLLM::Function; recent=nothing)::St
systemmsg = systemmsg =
""" """
Your name is $(a.name). You are a helpful assistant acting as a polite, website-based sommelier for Yiem's online wine store. Your name is $(a.name). You are a helpful assistant acting as a polite, website-based sommelier for $(a.retailername)'s online store.
Your goal includes: Your goal includes:
1) Help the user select the best wines from your inventory that align with the user's preferences 1) Help the user select the best wines from your inventory that align with the user's preferences
2) Thanks the user when they don't need any further assistance and invite them to comeback next time 2) Thanks the user when they don't need any further assistance and invite them to comeback next time
@@ -1370,6 +1357,9 @@ function generatequestion(a, text2textInstructLLM::Function; recent=nothing)::St
Q: What did I find in the database? Q: What did I find in the database?
A: According to the situation, ... A: According to the situation, ...
Q: What items are within the user price range?
A: According to the situation, ...
Q: Did I introduce the coffee blend varieties to the user yet? Q: Did I introduce the coffee blend varieties to the user yet?
A: According to the situation, no, I didn't because I have not searched the database yet. A: According to the situation, no, I didn't because I have not searched the database yet.
@@ -1431,7 +1421,7 @@ function generatequestion(a, text2textInstructLLM::Function; recent=nothing)::St
["Understanding", "Q1"], ["Understanding", "Q1"],
rightmarker=":", symbolkey=true, lowercasekey=true) rightmarker=":", symbolkey=true, lowercasekey=true)
response = "Q1: " * responsedict[:q1] response = "Q1: " * responsedict[:q1]
println("--> generatequestion ", @__FILE__, " ", @__LINE__) println("\n~~~ generatequestion ", @__FILE__, " ", @__LINE__)
pprintln(response) pprintln(response)
return response return response
catch e catch e
@@ -1439,9 +1429,7 @@ function generatequestion(a, text2textInstructLLM::Function; recent=nothing)::St
showerror(io, e) showerror(io, e)
errorMsg = String(take!(io)) errorMsg = String(take!(io))
st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace())) st = sprint((io, v) -> show(io, "text/plain", v), stacktrace(catch_backtrace()))
println("") println("\n Attempt $attempt. Error occurred: $errorMsg\n$st ", @__FILE__, " ", @__LINE__)
println("Attempt $attempt. Error occurred: $errorMsg\n$st ", @__FILE__, " ", @__LINE__)
println("")
end end
end end
error("generatequestion failed to generate a thought ", response) error("generatequestion failed to generate a thought ", response)

View File

@@ -289,7 +289,7 @@ julia> result = checkinventory(agent, input)
""" """
function checkinventory(a::T1, input::T2 function checkinventory(a::T1, input::T2
)::NamedTuple{(:result, :success, :errormsg), Tuple{String, Bool, Union{String, Nothing}}} where {T1<:agent, T2<:AbstractString} )::NamedTuple{(:result, :success, :errormsg), Tuple{String, Bool, Union{String, Nothing}}} where {T1<:agent, T2<:AbstractString}
println("~~~ checkinventory order: $input ", @__FILE__, " ", @__LINE__) println("\n~~~ checkinventory order: $input ", @__FILE__, " ", @__LINE__)
wineattributes_1 = extractWineAttributes_1(a, input) wineattributes_1 = extractWineAttributes_1(a, input)
wineattributes_2 = extractWineAttributes_2(a, input) wineattributes_2 = extractWineAttributes_2(a, input)
@@ -310,7 +310,7 @@ function checkinventory(a::T1, input::T2
) )
) )
println("checkinventory result ", @__FILE__, " ", @__LINE__) println("\n~~~ checkinventory result ", @__FILE__, " ", @__LINE__)
println(result) println(result)
return (result=result, success=true, errormsg=nothing) return (result=result, success=true, errormsg=nothing)