This commit is contained in:
2024-12-22 11:32:03 +07:00
parent becda0b309
commit 00f1a6775b

View File

@@ -1,7 +1,7 @@
module interface
export addNewMessage, conversation, decisionMaker, evaluator, reflector, generatechat,
generalconversation
generalconversation, detectWineryName
using JSON3, DataStructures, Dates, UUIDs, HTTP, Random, PrettyPrinting, Serialization
using GeneralUtils
@@ -169,7 +169,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
Your Q&A: the question and answer you have asked yourself
You must follow the following guidelines:
- Generally speaking, your inventory has some wines from France, the United States, Australia, Spain, and Italy, but you won't know which wines your store carries until you check your inventory.
- Generally speaking, your inventory has some wines from France, the United States, Australia, Spain, and Italy, but you won't know exactly until you check your inventory.
- All wines in your inventory are always in stock.
- If the user interrupts, prioritize the user
- Do not ask the user about wine's flavor e.g. floral, citrusy, nutty or some thing similar as these terms cannot be used to search the database.
@@ -217,6 +217,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
winenames = df[:, :wine_name]
for winename in winenames
if !occursin(winename, chathistory)
println("\n~~~ Yiem decisionMaker() found wines from DB ", @__FILE__, " ", @__LINE__)
return Dict(:action_name=> "PRESENTBOX",
:action_input=> """
1) Provide detailed introductions of the wines you just found to help the user make an informed choice.
@@ -817,7 +818,7 @@ function think(a::T)::NamedTuple{(:actionname, :result),Tuple{String,String}} wh
end
elseif actionname == "CHECKINVENTORY"
if haskey(a.memory[:shortmem], :available_wine)
if haskey(a.memory[:shortmem], :available_wine) # store wines in dataframe format
df = a.memory[:shortmem][:available_wine]
a.memory[:shortmem][:available_wine] = vcat(df, rawresponse)
elseif rawresponse !== nothing
@@ -896,13 +897,16 @@ function generatechat(a::sommelier, thought::T) where {T<:AbstractString}
You should only respond in format as described below:
Chat: ...
Here are some examples of response format:
Chat: "I see. Let me think about it. I'll get back to you with my recommendation."
Let's begin!
"""
# a.memory[:shortmem][:available_wine] is a dataframe.
context =
if haskey(a.memory[:shortmem], :available_wine)
"Available wine $(GeneralUtils.dfToString(a.memory[:shortmem][:available_wine]))"
"Available wines $(GeneralUtils.dfToString(a.memory[:shortmem][:available_wine]))"
else
"None"
end
@@ -932,7 +936,15 @@ function generatechat(a::sommelier, thought::T) where {T<:AbstractString}
"""
try
response = a.func[:text2textInstructLLM](prompt)
response_1 = a.func[:text2textInstructLLM](prompt)
# sometime the model response like this "here's how I would respond: ..."
if occursin("respond:", response_1)
errornote = "You don't need to intro your response"
error("generatechat() response contain : ", @__FILE__, " ", @__LINE__)
end
response_2 = replace(response_1, '*' => "")
response_3 = replace(response_2, '$' => "USD")
response = replace(response_3, '`' => "")
responsedict = GeneralUtils.textToDict(response, ["Chat"],
rightmarker=":", symbolkey=true, lowercasekey=true)
@@ -1325,6 +1337,9 @@ function detectWineryName(a, text)
At each round of conversation, you will be given the situation:
Text: a text describing the situation.
Tips:
- Winery usually contains Château, Chateau, Domaine, Côte, Cote, St. de, or a combination of these words.
You should then respond to the user with:
Winery_names: A list of winery names mentioned in the text or "None" if no winery name is mentioned.
@@ -1332,7 +1347,7 @@ function detectWineryName(a, text)
Winery_names: ...
Here are some examples:
Winery_names: Domaine Courbis, Chateau Lafite Rothschild, Matarromera Domaine Roulot
Winery_names: Domaine Courbis, Chateau Lafite Rothschild, Matarromera Domaine Roulot, Château
Let's begin!
"""