From bc002a3ef4a85cabdbb96d733981127c42caec97 Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Tue, 10 Dec 2024 13:17:19 +0700 Subject: [PATCH] update --- src/interface.jl | 41 ++++++++++++++++++++++------------------- test/runtest.jl | 4 +--- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index 69b7fb8..7ef5533 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -132,8 +132,6 @@ function decisionMaker(a::T; recent::Integer=5)::Dict{Symbol,Any} where {T<:agen else 1:totalevents end - - chathistory = vectorOfDictToText(a.chathistory) timeline = "" 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 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,19 +206,23 @@ 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] - if !occursin(winename, chathistory) - 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. - 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. - """) + winenames = df[:, :wine_name] + for winename in winenames + if !occursin(winename, chathistory) + 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. + 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 @@ -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 @@ -812,15 +812,18 @@ function think(a::T)::NamedTuple{(:actionname, :result),Tuple{String,String}} wh a.memory[:state][:wine_presented_to_user] = winename 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 end 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], 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 diff --git a/test/runtest.jl b/test/runtest.jl index c646701..524bfe6 100644 --- a/test/runtest.jl +++ b/test/runtest.jl @@ -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