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

@@ -133,8 +133,6 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
1:totalevents
end
chathistory = vectorOfDictToText(a.chathistory)
timeline = ""
for (i, event) in enumerate(a.memory[:events][ind])
if event[:outcome] === nothing
@@ -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
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 Q&A: the question and answer you have asked yourself
@@ -209,12 +206,15 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
Let's begin!
"""
chathistory = vectorOfDictToText(a.chathistory)
# check if winename in shortmem occurred in chathistory. if not, skip decision and imediately use PRESENTBOX
if haskey(a.memory[:shortmem], :available_wine)
# check if wine name mentioned in timeline, only check first wine name is enough
# because agent will recommend every wines it found each time.
df = a.memory[:shortmem][:available_wine]
winename = df[1, :wine_name]
winenames = df[:, :wine_name]
for winename in winenames
if !occursin(winename, chathistory)
return Dict(:action_name=> "PRESENTBOX",
:action_input=> """
@@ -224,6 +224,7 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
""")
end
end
end
errornote = ""
response = nothing # placeholder for show when error msg show up
@@ -233,7 +234,6 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen
usermsg =
"""
Your status: $(GeneralUtils.dict_to_string(a.memory[:state]))
Your recent events: $timeline
Your Q&A: $QandA)
$errornote
@@ -813,14 +813,17 @@ function think(a::T)::NamedTuple{(:actionname, :result),Tuple{String,String}} wh
else
a.memory[:state][:wine_presented_to_user] *= ", $winename"
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
elseif actionname == "CHECKINVENTORY"
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],
eventdict(;
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:
- 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:
- Focus on the latest conversation

View File

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