From 30c19a946952c56174272940578fe8d948b282e8 Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Wed, 20 Mar 2024 14:33:38 +0700 Subject: [PATCH] update --- src/type.jl | 5 +++-- src/utils.jl | 37 +++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/type.jl b/src/type.jl index aa6bba6..13ea2f8 100644 --- a/src/type.jl +++ b/src/type.jl @@ -3,6 +3,7 @@ module type export agent, agentReflex, newAgentMemory using Dates, UUIDs, DataStructures +using GeneralUtils # ---------------------------------------------- 100 --------------------------------------------- # @@ -111,7 +112,7 @@ julia> agent = ChatAgent.agentReflex( # communication mqttClient::Any=nothing # store mqtt client for use in various internal functions - msgMeta::Union{Dict, Nothing} = nothing # a template for msgMeta + msgMeta::Dict # a template for msgMeta mqttMsg_internal::Channel{Dict} = Channel{Dict}(32) # LLM function related @@ -120,7 +121,7 @@ end function agentReflex( mqttClient, - msgMeta::Dict, + msgMeta::Dict= GeneralUtils.generate_msgMeta("N/A"), config::Dict = Dict( :frontend=>Dict( :mqtttopic=> nothing diff --git a/src/utils.jl b/src/utils.jl index a7cfa44..50f2684 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -68,21 +68,20 @@ function sendReceivePrompt(a::T1, prompt::String, sendtopic::String; stopword::T2=["nostopwordyet"], seed=nothing) where {T1<:agent, T2<:Vector{<:AbstractString}} - sendto = a.config[:text2text][:mqtttopic] - msgMeta = deepcopy(a.msgMeta) - msgMeta[:sendTopic] = #WORKING assign value + # copy a.msgMeta instead of using GeneralUtils.generate_msgMeta because if I want to custom + # msgMeta for some communication I can do it during that agent instantiation and the custom + # msgMeta will effect all of the communication in that agent without effecting all agent + # via GeneralUtils.generate_msgMeta + msgMeta = deepcopy(a.msgMeta) + msgMeta[:sendTopic] = sendtopic + msgMeta[:senderName] = "agent-wine-backend" + msgMeta[:receiverName] = "text2text-llm" + msgMeta[:replyTopic] = a.config[:receiveinternal][:mqtttopic] + msgMeta[:msgId] = string(uuid4()) - sendto, - senderName = "agent-wine-backend", - receiverName = "text2text-llm", - replyTopic = a.config[:frontend][:mqtttopic], - msgId = string(uuid4()) - - - a.msgMeta[:msgId] = "$(uuid4())" # new msg id for each msg - msg = Dict( - :msgMeta=> a.msgMeta, - :txt=> prompt, + outgoing_msg = Dict( + :msgMeta=> msgMeta, + :text=> prompt, :max_tokens=> max_tokens, :temperature=> temperature, :stopword=> stopword, @@ -90,15 +89,17 @@ function sendReceivePrompt(a::T1, prompt::String, sendtopic::String; ) # send prompt - CommUtils.request(a.mqttClient, msg) + publish(a.mqttClient, outgoing_msg[:msgMeta][:sendTopic], + JSON3.write(outgoing_msg)) + starttime = Dates.now() result = nothing - while true + while true #WORKING check how to receive msg , should i use :text or :message? timepass = (Dates.now() - starttime).value / 1000.0 - if isready(mqttMsg_internal) + if isready(a.mqttMsg_internal) topic, payload = take!(payloadChannel) - if payload[:msgMeta][:repondToMsgId] == msg[:msgMeta][:msgId] + if payload[:msgMeta][:repondToMsgId] == outgoing_msg[:msgMeta][:msgId] result = haskey(payload, :txt) ? payload[:txt] : nothing break end