update
This commit is contained in:
@@ -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
|
||||
|
||||
37
src/utils.jl
37
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
|
||||
|
||||
Reference in New Issue
Block a user