This commit is contained in:
narawat lamaiin
2024-12-10 13:17:19 +07:00
parent d763727d7d
commit bc002a3ef4
2 changed files with 23 additions and 22 deletions

View File

@@ -132,8 +132,6 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
else else
1:totalevents 1:totalevents
end end
chathistory = vectorOfDictToText(a.chathistory)
timeline = "" timeline = ""
for (i, event) in enumerate(a.memory[:events][ind]) for (i, event) in enumerate(a.memory[:events][ind])
@@ -167,7 +165,6 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
2) Processing sales orders or engaging in any other sales-related activities 2) Processing sales orders or engaging in any other sales-related activities
At each round of conversation, you will be given the current situation: At each round of conversation, you will be given the current situation:
Your status: your current status
Your recent events: latest 5 events of the situation Your recent events: latest 5 events of the situation
Your Q&A: the question and answer you have asked yourself Your Q&A: the question and answer you have asked yourself
@@ -209,19 +206,23 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
Let's begin! Let's begin!
""" """
chathistory = vectorOfDictToText(a.chathistory)
# check if winename in shortmem occurred in chathistory. if not, skip decision and imediately use PRESENTBOX # check if winename in shortmem occurred in chathistory. if not, skip decision and imediately use PRESENTBOX
if haskey(a.memory[:shortmem], :available_wine) if haskey(a.memory[:shortmem], :available_wine)
# check if wine name mentioned in timeline, only check first wine name is enough # check if wine name mentioned in timeline, only check first wine name is enough
# because agent will recommend every wines it found each time. # because agent will recommend every wines it found each time.
df = a.memory[:shortmem][:available_wine] df = a.memory[:shortmem][:available_wine]
winename = df[1, :wine_name] winenames = df[:, :wine_name]
if !occursin(winename, chathistory) for winename in winenames
return Dict(:action_name=> "PRESENTBOX", if !occursin(winename, chathistory)
:action_input=> """ return Dict(:action_name=> "PRESENTBOX",
1) Provide detailed introductions of the wines you just found to help the user make an informed choice. :action_input=> """
2) If there are multiple wines, offer thorough comparison of each option, highlighting their differences. 1) Provide detailed introductions of the wines you just found to help the user make an informed choice.
3) Explain the potential impact each option could bring to the user. 2) If there are multiple wines, offer thorough comparison of each option, highlighting their differences.
""") 3) Explain the potential impact each option could bring to the user.
""")
end
end end
end end
@@ -233,7 +234,6 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
usermsg = usermsg =
""" """
Your status: $(GeneralUtils.dict_to_string(a.memory[:state]))
Your recent events: $timeline Your recent events: $timeline
Your Q&A: $QandA) Your Q&A: $QandA)
$errornote $errornote
@@ -812,15 +812,18 @@ function think(a::T)::NamedTuple{(:actionname, :result),Tuple{String,String}} wh
a.memory[:state][:wine_presented_to_user] = winename a.memory[:state][:wine_presented_to_user] = winename
else else
a.memory[:state][:wine_presented_to_user] *= ", $winename" a.memory[:state][:wine_presented_to_user] *= ", $winename"
end end
# [WORKING] instead of present wine then delete shortmem, we can present just found wine and leave previous wine in shortmem.
# so agent can use wine data later
delete!(a.memory[:shortmem], :available_wine)
end end
elseif actionname == "CHECKINVENTORY" elseif actionname == "CHECKINVENTORY"
a.memory[:shortmem][:available_wine] = rawresponse if haskey(a.memory[:shortmem], :available_wine)
df = a.memory[:shortmem][:available_wine]
a.memory[:shortmem][:available_wine] = vcat(df, rawresponse)
elseif rawresponse !== nothing
a.memory[:shortmem][:available_wine] = rawresponse
else
# skip, no result
end
push!(a.memory[:events], push!(a.memory[:events],
eventdict(; eventdict(;
event_description= "the assistant searched the database.", event_description= "the assistant searched the database.",
@@ -1085,7 +1088,7 @@ function generatequestion(a, text2textInstructLLM::Function; recent=nothing)::St
You must follow the following guidelines: You must follow the following guidelines:
- Your question should be specific, self-contained and not require any additional context. - Your question should be specific, self-contained and not require any additional context.
- Once the user has chose their wine, your task almost done. Ask the user if they need any further assistance. Do not offer any additional services. If the user doesn't need any further assistance, say goodbye and invite them to come back next time. - Once the user has chose their wine, ask the user if they need any further assistance. Do not offer any additional services. If the user doesn't need any further assistance, say goodbye and invite them to come back next time.
You should follow the following guidelines: You should follow the following guidelines:
- Focus on the latest conversation - Focus on the latest conversation

View File

@@ -26,7 +26,6 @@ function executeSQLVectorDB(sql)
return result return result
end end
function text2textInstructLLM(prompt::String) function text2textInstructLLM(prompt::String)
msgMeta = GeneralUtils.generate_msgMeta( msgMeta = GeneralUtils.generate_msgMeta(
config[:externalservice][:text2textinstruct][:mqtttopic]; config[:externalservice][:text2textinstruct][:mqtttopic];
@@ -55,7 +54,6 @@ function text2textInstructLLM(prompt::String)
return response return response
end end
# get text embedding from a LLM service # get text embedding from a LLM service
function getEmbedding(text::T) where {T<:AbstractString} function getEmbedding(text::T) where {T<:AbstractString}
msgMeta = GeneralUtils.generate_msgMeta( msgMeta = GeneralUtils.generate_msgMeta(
@@ -74,7 +72,7 @@ function getEmbedding(text::T) where {T<:AbstractString}
:text => [text] # must be a vector of string :text => [text] # must be a vector of string
) )
) )
response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg) response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg; timeout=6000)
embedding = response[:response][:embeddings] embedding = response[:response][:embeddings]
return embedding return embedding
end end