update
This commit is contained in:
119
src/type.jl
119
src/type.jl
@@ -9,32 +9,39 @@ using GeneralUtils
|
||||
|
||||
abstract type agent end
|
||||
|
||||
|
||||
""" A sommelier agent.
|
||||
|
||||
Arguments\n
|
||||
-----
|
||||
mqttClient::Client
|
||||
MQTTClient's client
|
||||
msgMeta::Dict{Symbol, Any}
|
||||
A dict contain info about a message.
|
||||
config::Dict{Symbol, Any}
|
||||
Config info for an agent. Contain mqtt topic for internal use and other info.
|
||||
|
||||
Keyword Arguments\n
|
||||
-----
|
||||
name::String
|
||||
Agent's name
|
||||
id::String
|
||||
Agent's ID
|
||||
tools::Dict{Symbol, Any}
|
||||
Agent's tools
|
||||
maxHistoryMsg::Integer
|
||||
max history message
|
||||
|
||||
Return\n
|
||||
-----
|
||||
nothing
|
||||
|
||||
Example:
|
||||
```jldoctest
|
||||
julia> using ChatAgent
|
||||
julia> mqttClientSpec = (
|
||||
clientName= "someclient", # name of this client
|
||||
clientID= "$(uuid4())",
|
||||
broker= "mqtt.yiem.ai",
|
||||
pubtopic= (imgAI="img/api/v0.0.1/gpu/request",
|
||||
txtAI="txt/api/v0.1.0/gpu/request"), # this is where LLM server located
|
||||
subtopic= (imgAI="agent/api/v0.1.0/img/respond",
|
||||
txtAI="agent/api/v0.1.0/txt/respond"), # this is where this agent located
|
||||
keepalive= 30,
|
||||
)
|
||||
julia> msgMeta = Dict(
|
||||
:msgPurpose=> "updateStatus",
|
||||
:from=> "agent",
|
||||
:to=> "llmAI",
|
||||
:requestrespond=> "request",
|
||||
:sendto=> "", # destination topic
|
||||
:replyTo=> "agent/api/v0.1.0/txt/respond", # requester ask responder to send reply to this topic
|
||||
:repondToMsgId=> "", # responder is responding to this msg id
|
||||
:taskstatus=> "", # "complete", "fail", "waiting" or other status
|
||||
:timestamp=> Dates.now(),
|
||||
:msgId=> "$(uuid4())",
|
||||
julia> using YiemAgent, MQTTClient, GeneralUtils
|
||||
julia> msgMeta = GeneralUtils.generate_msgMeta(
|
||||
"N/A",
|
||||
replyTopic = "/testtopic/prompt"
|
||||
)
|
||||
julia> tools= Dict(
|
||||
:chatbox=>Dict(
|
||||
@@ -44,51 +51,53 @@ abstract type agent end
|
||||
:output => "" ,
|
||||
:func => nothing,
|
||||
),
|
||||
:wikisearch=>Dict(
|
||||
:name => "wikisearch",
|
||||
:description => "Useful for when you need to search an encyclopedia.",
|
||||
:input => "Input is keywords and not a question.",
|
||||
:output => "",
|
||||
:func => ChatAgent.wikisearch, # put function here
|
||||
)
|
||||
julia> agentConfig = Dict(
|
||||
:receiveprompt=>Dict(
|
||||
:mqtttopic=> "/testtopic/prompt", # topic to receive prompt i.e. frontend send msg to this topic
|
||||
),
|
||||
:winestock=>Dict(
|
||||
:name => "wineStock",
|
||||
:description => "useful for when you need to search your wine stock by wine description, price, name or ID.",
|
||||
:input => "Input is a search query.",
|
||||
:output => "Output are Wine name, description, price and ID" ,
|
||||
:func => ChatAgent.winestock,
|
||||
:receiveinternal=>Dict(
|
||||
:mqtttopic=> "/testtopic/internal", # receive topic for model's internal
|
||||
),
|
||||
:text2text=>Dict(
|
||||
:mqtttopic=> "/text2text/receive",
|
||||
),
|
||||
)
|
||||
julia> agent = ChatAgent.agentReflex(
|
||||
"Jene",
|
||||
role=:assistant,
|
||||
mqttClientSpec=mqttClientSpec,
|
||||
msgMeta=msgMeta,
|
||||
tools=tools
|
||||
julia> client, connection = MakeConnection("test.mosquitto.org", 1883)
|
||||
julia> agent = YiemAgent.bsommelier(
|
||||
client,
|
||||
msgMeta,
|
||||
agentConfig,
|
||||
name= "assistant",
|
||||
id= "555", # agent instance id
|
||||
tools=tools,
|
||||
)
|
||||
```
|
||||
|
||||
Signature\n
|
||||
-----
|
||||
""" #TODO update document
|
||||
@kwdef mutable struct sommelier <: agent
|
||||
name::String
|
||||
id::String
|
||||
config::Dict
|
||||
tools::Union{Dict, Nothing} = nothing
|
||||
attemptlimit::Int # thinking round limit
|
||||
attemptcount::Int # used to count attempted round of a task
|
||||
tools::Dict
|
||||
thinkinglimit::Integer # thinking round limit
|
||||
thinkingcount::Integer # used to count attempted round of a task
|
||||
|
||||
# memory
|
||||
# Ref: Chat prompt format https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/discussions/3
|
||||
# messages= [Dict(:role=>"system", :content=> "", :timestamp=> Dates.now()),]
|
||||
chathistory = Vector{Dict{Symbol, Any}}() # store messages history in the format :name=>"message"
|
||||
maxHistoryMsg::Int = 20 # 31th and earlier messages will get summarized
|
||||
keywordinfo = Dict{Symbol, Any}(
|
||||
chathistory::Vector{Dict{Symbol, Any}} = Vector{Dict{Symbol, Any}}() # store messages history in the format :name=>"message"
|
||||
maxHistoryMsg::Integer # 31th and earlier messages will get summarized
|
||||
keywordinfo::Dict{Symbol, Any} = Dict{Symbol, Any}(
|
||||
:userinfo => Dict{Symbol, Any}(),
|
||||
:retailerinfo => Dict{Symbol, Any}(),
|
||||
)
|
||||
mctstree = Dict{Symbol, Any}()
|
||||
mctstree::Dict{Symbol, Any} = Dict{Symbol, Any}()
|
||||
# 1-history point compose of:
|
||||
# state_t, statevalue_t, thought_t, action_t, observation_t, state_tplus1, statevalue_tplus1
|
||||
plan = Dict{Symbol, Any}(
|
||||
plan::Dict{Symbol, Any} = Dict{Symbol, Any}(
|
||||
|
||||
# store 3 to 5 best plan AI frequently used to avoid having to search MCTS all the time
|
||||
:existingplan => Dict{Symbol, Any}(),
|
||||
@@ -99,11 +108,11 @@ abstract type agent end
|
||||
|
||||
# communication
|
||||
mqttClient::Any= nothing # store mqtt client for use in various internal functions
|
||||
msgMeta::Dict # a template for msgMeta
|
||||
msgMeta::Dict{Symbol, Any} # a template for msgMeta
|
||||
|
||||
# put incoming message here. waiting for further processing
|
||||
userMsg::Channel{Dict} = Channel{Dict}(32) # for user communication
|
||||
internalMsg::Channel{Dict} = Channel{Dict}(32) # for internal communication
|
||||
userMsg::Channel{Dict} = Channel{Dict}(8) # for user communication
|
||||
internalMsg::Channel{Dict} = Channel{Dict}(8) # for internal communication
|
||||
end
|
||||
|
||||
function sommelier(
|
||||
@@ -132,7 +141,9 @@ function sommelier(
|
||||
:func => nothing,
|
||||
),
|
||||
),
|
||||
maxHistoryMsg::Int=20,
|
||||
maxHistoryMsg::Integer= 20,
|
||||
thinkinglimit::Integer= 5,
|
||||
thinkingcount::Integer= 0,
|
||||
)
|
||||
|
||||
#NEXTVERSION publish to a.config[:configtopic] to get a config.
|
||||
@@ -147,8 +158,8 @@ function sommelier(
|
||||
msgMeta = msgMeta,
|
||||
maxHistoryMsg = maxHistoryMsg,
|
||||
tools = tools,
|
||||
attemptlimit = 5,
|
||||
attemptcount = 0,
|
||||
thinkinglimit = thinkinglimit,
|
||||
thinkingcount = thinkingcount,
|
||||
)
|
||||
|
||||
return newAgent
|
||||
|
||||
Reference in New Issue
Block a user