remove mqttclient integration
This commit is contained in:
@@ -8,7 +8,7 @@ export agentReact, agentReflex,
|
||||
recap, readKeywordMemory
|
||||
|
||||
using JSON3, DataStructures, Dates, UUIDs, HTTP, Random
|
||||
using CommUtils, GeneralUtils
|
||||
using GeneralUtils
|
||||
using ..type, ..utils, ..llmfunction
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
@@ -1170,7 +1170,7 @@ end
|
||||
Chat with llm.
|
||||
|
||||
```jldoctest
|
||||
julia> using JSON3, UUIDs, Dates, FileIO, CommUtils, ChatAgent
|
||||
julia> using JSON3, UUIDs, Dates, FileIO, ChatAgent
|
||||
julia> mqttClientSpec = (
|
||||
clientName= "someclient", # name of this client
|
||||
clientID= "$(uuid4())",
|
||||
@@ -1442,7 +1442,7 @@ end
|
||||
Example:
|
||||
|
||||
```jldoctest
|
||||
julia> using ChatAgent, CommUtils
|
||||
julia> using ChatAgent
|
||||
julia> agent = ChatAgent.agentReflex("Jene")
|
||||
julia> usermsg = "What's AMD latest product?"
|
||||
"
|
||||
@@ -1486,7 +1486,7 @@ end
|
||||
Example:
|
||||
|
||||
```jldoctest
|
||||
julia> using ChatAgent, CommUtils
|
||||
julia> using ChatAgent
|
||||
julia> agent = ChatAgent.agentReflex("Jene")
|
||||
julia> shorttermMemory = OrderedDict{String, Any}(
|
||||
"user" => "What's the latest AMD GPU?",
|
||||
@@ -1560,7 +1560,7 @@ end
|
||||
Example:
|
||||
|
||||
```jldoctest
|
||||
julia> using ChatAgent, CommUtils
|
||||
julia> using ChatAgent
|
||||
julia> agent = ChatAgent.agentReflex("Jene")
|
||||
julia> shorttermMemory = OrderedDict{String, Any}(
|
||||
"user:" => "What's the latest AMD GPU?",
|
||||
@@ -1616,7 +1616,7 @@ end
|
||||
Example:
|
||||
|
||||
```jldoctest
|
||||
julia> using ChatAgent, CommUtils
|
||||
julia> using ChatAgent
|
||||
julia> agent = ChatAgent.agentReflex("Jene")
|
||||
julia> report =
|
||||
"What happened: I tried to search for AMD's latest product using the wikisearch tool,
|
||||
@@ -1671,7 +1671,7 @@ end
|
||||
|
||||
Example:
|
||||
```jldoctest
|
||||
julia> using ChatAgent, CommUtils
|
||||
julia> using ChatAgent
|
||||
julia> agent = ChatAgent.agentReflex("Jene")
|
||||
julia> shorttermMemory = OrderedDict{String, Any}(
|
||||
"user:" => "What's the latest AMD GPU?",
|
||||
@@ -1856,7 +1856,7 @@ end
|
||||
|
||||
Example:
|
||||
```jldoctest
|
||||
julia> using ChatAgent, CommUtils
|
||||
julia> using ChatAgent
|
||||
julia> agent = ChatAgent.agentReflex("Jene")
|
||||
julia> shorttermMemory = OrderedDict{String, Any}(
|
||||
"user:" => "What's the latest AMD GPU?",
|
||||
@@ -2043,7 +2043,7 @@ end
|
||||
|
||||
Example:
|
||||
```jldoctest
|
||||
julia> using ChatAgent, CommUtils
|
||||
julia> using ChatAgent
|
||||
julia> a = ChatAgent.agentReflex("Jene")
|
||||
julia> keywordmemory = OrderedDict{String, Any}(
|
||||
"food type" => nothing,
|
||||
|
||||
@@ -69,7 +69,7 @@ end
|
||||
|
||||
Example\n
|
||||
```jldoctest
|
||||
julia> using ChatAgent, CommUtils
|
||||
julia> using ChatAgent
|
||||
julia> agent = ChatAgent.agentReflex("Jene")
|
||||
julia> input = "{\"food\": \"pizza\", \"occasion\": \"anniversary\"}"
|
||||
julia> result = winestock(agent, input)
|
||||
|
||||
@@ -3,7 +3,6 @@ module type
|
||||
export agent, agentReflex, newAgentMemory
|
||||
|
||||
using Dates, UUIDs, DataStructures
|
||||
using CommUtils
|
||||
|
||||
#------------------------------------------------------------------------------------------------100
|
||||
|
||||
@@ -84,8 +83,6 @@ julia> agent = ChatAgent.agentReflex(
|
||||
agentName::String = "Jene" # ex. Jene
|
||||
maxUserMsg::Int = 30
|
||||
earlierConversation::String = "N/A" # summary of earlier conversation
|
||||
mqttClient::Union{mqttClient, Nothing} = nothing
|
||||
msgMeta::Union{Dict, Nothing} = nothing
|
||||
|
||||
""" Dict(Role=> Content) ; Role can be system, user, assistant
|
||||
Example:
|
||||
@@ -126,8 +123,8 @@ function agentReflex(
|
||||
subtopic= (imgAI="agent/api/v0.1.0/img/respond",
|
||||
txtAI="agent/api/v0.1.0/txt/respond"),
|
||||
keepalive= 30,),
|
||||
role::Symbol=:assistant,
|
||||
roles::Dict=Dict(
|
||||
role::Symbol=:assistant,
|
||||
roles::Dict=Dict(
|
||||
:assistant =>
|
||||
"""
|
||||
You are a helpful assistant.
|
||||
@@ -261,7 +258,6 @@ function agentReflex(
|
||||
newAgent = agentReflex()
|
||||
newAgent.availableRole = availableRole
|
||||
newAgent.maxUserMsg = maxUserMsg
|
||||
newAgent.mqttClient = CommUtils.mqttClient(mqttClientSpec)
|
||||
newAgent.msgMeta = msgMeta
|
||||
newAgent.tools = tools
|
||||
newAgent.role = role
|
||||
|
||||
94
src/utils.jl
94
src/utils.jl
@@ -7,46 +7,20 @@ export sendReceivePrompt, chunktext, extractStepFromPlan, checkTotalTaskInPlan,
|
||||
messagesToString, messagesToString_nomark, removeTrailingCharacters, shortMemLatestTask,
|
||||
keywordMemoryUpdate!
|
||||
|
||||
using UUIDs, Dates, DataStructures
|
||||
using CommUtils, GeneralUtils
|
||||
using UUIDs, Dates, DataStructures, HTTP, MQTTClient
|
||||
using GeneralUtils
|
||||
using ..type
|
||||
|
||||
#------------------------------------------------------------------------------------------------100
|
||||
|
||||
"""
|
||||
Send a msg to registered mqtt topic within mqttClient.
|
||||
|
||||
```jldoctest
|
||||
julia> using JSON3, UUIDs, Dates, FileIO, CommUtils, ChatAgent
|
||||
julia> newAgent = ChatAgent.agentReact(
|
||||
"Jene",
|
||||
mqttClientSpec,
|
||||
role=:assistant_react,
|
||||
msgMeta=msgMeta
|
||||
)
|
||||
```
|
||||
"""
|
||||
function sendReceivePrompt(a::T, prompt::String; max_tokens=256, timeout::Int=120,
|
||||
temperature::AbstractFloat=0.2, stopword=[], seed=nothing) where {T<:agent}
|
||||
a.msgMeta[:msgId] = "$(uuid4())" # new msg id for each msg
|
||||
msg = Dict(
|
||||
:msgMeta=> a.msgMeta,
|
||||
:txt=> prompt,
|
||||
:max_tokens=> max_tokens,
|
||||
:temperature=> temperature,
|
||||
:stopword=> stopword,
|
||||
:seed=> seed,
|
||||
)
|
||||
payloadChannel = Channel(1)
|
||||
|
||||
# send prompt
|
||||
CommUtils.request(a.mqttClient, msg)
|
||||
#WORKING
|
||||
function sendReceivePrompt(message::AbstractDict, mqttclient, pubtopic::String)
|
||||
starttime = Dates.now()
|
||||
result = nothing
|
||||
|
||||
while true
|
||||
timepass = (Dates.now() - starttime).value / 1000.0
|
||||
CommUtils.mqttRun(a.mqttClient, payloadChannel)
|
||||
#WORKING get payload form mqtt or rest
|
||||
if isready(payloadChannel)
|
||||
topic, payload = take!(payloadChannel)
|
||||
if payload[:msgMeta][:repondToMsgId] == msg[:msgMeta][:msgId]
|
||||
@@ -67,6 +41,64 @@ function sendReceivePrompt(a::T, prompt::String; max_tokens=256, timeout::Int=12
|
||||
return result
|
||||
end
|
||||
|
||||
function sendReceivePrompt(message::AbstractDict, endpoint::String)
|
||||
|
||||
end
|
||||
|
||||
"""
|
||||
Send a msg to registered mqtt topic within mqttClient.
|
||||
|
||||
```jldoctest
|
||||
julia> using JSON3, UUIDs, Dates, FileIO, ChatAgent
|
||||
julia> newAgent = ChatAgent.agentReact(
|
||||
"Jene",
|
||||
mqttClientSpec,
|
||||
role=:assistant_react,
|
||||
msgMeta=msgMeta
|
||||
)
|
||||
```
|
||||
"""
|
||||
# function sendReceivePrompt(a::T, prompt::String; max_tokens=256, timeout::Int=120,
|
||||
# temperature::AbstractFloat=0.2, stopword=[], seed=nothing) where {T<:agent}
|
||||
# a.msgMeta[:msgId] = "$(uuid4())" # new msg id for each msg
|
||||
# msg = Dict(
|
||||
# :msgMeta=> a.msgMeta,
|
||||
# :txt=> prompt,
|
||||
# :max_tokens=> max_tokens,
|
||||
# :temperature=> temperature,
|
||||
# :stopword=> stopword,
|
||||
# :seed=> seed,
|
||||
# )
|
||||
# payloadChannel = Channel(1)
|
||||
|
||||
# #WORKING send prompt using mqtt or Rest
|
||||
|
||||
# starttime = Dates.now()
|
||||
# result = nothing
|
||||
|
||||
# while true
|
||||
# timepass = (Dates.now() - starttime).value / 1000.0
|
||||
# #WORKING get payload form mqtt or rest
|
||||
# if isready(payloadChannel)
|
||||
# topic, payload = take!(payloadChannel)
|
||||
# if payload[:msgMeta][:repondToMsgId] == msg[:msgMeta][:msgId]
|
||||
# result = haskey(payload, :txt) ? payload[:txt] : nothing
|
||||
# break
|
||||
# end
|
||||
# elseif timepass <= timeout
|
||||
# # skip, within waiting period
|
||||
# elseif timepass > timeout
|
||||
# println("sendReceivePrompt timeout $timepass/$timeout")
|
||||
# result = nothing
|
||||
# break
|
||||
# else
|
||||
# error("undefined condition. timepass=$timepass timeout=$timeout $(@__LINE__)")
|
||||
# end
|
||||
# end
|
||||
|
||||
# return result
|
||||
# end
|
||||
|
||||
|
||||
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user