This commit is contained in:
narawat lamaiin
2024-04-15 21:05:30 +07:00
parent 4cb2353213
commit 45a1d93bc7
2 changed files with 49 additions and 26 deletions

View File

@@ -1,6 +1,6 @@
module interface module interface
export addNewMessage export add_new_message
using JSON3, DataStructures, Dates, UUIDs, HTTP, Random using JSON3, DataStructures, Dates, UUIDs, HTTP, Random
using GeneralUtils using GeneralUtils
@@ -47,7 +47,7 @@ using ..type, ..util, ..llmfunction
Return\n Return\n
----- -----
message left nothing
Example\n Example\n
----- -----
@@ -72,13 +72,13 @@ using ..type, ..util, ..llmfunction
msgMeta, msgMeta,
agentConfig, agentConfig,
) )
julia> YiemAgent.addNewMessage(a, "user", "hello") julia> YiemAgent.add_new_message(a, "user", "hello")
``` ```
Signature\n Signature\n
----- -----
""" #WORKING """
function addNewMessage(a::T1, role::String, text::T2; function add_new_message(a::T1, role::String, text::T2;
maximumMsg::Integer=20) where {T1<:agent, T2<:AbstractString} maximumMsg::Integer=20) where {T1<:agent, T2<:AbstractString}
if role ["system", "user", "assistant"] # guard against typo if role ["system", "user", "assistant"] # guard against typo
error("role is not in agent.availableRole $(@__LINE__)") error("role is not in agent.availableRole $(@__LINE__)")

View File

@@ -1,6 +1,6 @@
module type module type
export agent, sommelier, initAgentMemory export agent, sommelier, clearhistory
using Dates, UUIDs, DataStructures, JSON3 using Dates, UUIDs, DataStructures, JSON3
using GeneralUtils using GeneralUtils
@@ -67,7 +67,7 @@ abstract type agent end
tools=tools tools=tools
) )
``` ```
""" """ #TODO update document
@kwdef mutable struct sommelier <: agent @kwdef mutable struct sommelier <: agent
name::String name::String
id::String id::String
@@ -154,29 +154,52 @@ function sommelier(
return newAgent return newAgent
end end
""" Clear agent history.
Arguments\n
-----
a::agent
an agent
# function initAgentMemory(a::T) where {T<:agent} Return\n
# a.chathistory = Dict{String,Any}() -----
# a.mctstree = Dict{Symbol, Any}() nothing
# a.plan[:activeplan] = Dict{Symbol, Any}()
# a.plan[:currenttrajectory] = Dict{Symbol, Any}()
# end
Example\n
-----
```jldoctest
julia> using YiemAgent, MQTTClient, GeneralUtils
julia> client, connection = MakeConnection("test.mosquitto.org", 1883)
julia> connect(client, connection)
julia> msgMeta = GeneralUtils.generate_msgMeta("testtopic")
julia> agentConfig = Dict(
:receiveprompt=>Dict(
:mqtttopic=> "testtopic/receive",
),
:receiveinternal=>Dict(
:mqtttopic=> "testtopic/internal",
),
:text2text=>Dict(
:mqtttopic=> "testtopic/text2text",
),
)
julia> a = YiemAgent.sommelier(
client,
msgMeta,
agentConfig,
)
julia> YiemAgent.add_new_message(a, "user", "hello")
julia> YiemAgent.clearhistory(a)
```
function clearMessage(a::T) where {T<:agent} Signature\n
for i in eachindex(a.messages) -----
if length(a.messages) > 0 """ #TODO update document
pop!(a.messages) function clearhistory(a::T) where {T<:agent}
else empty!(a.chathistory)
break empty!(a.mctstree)
end empty!(a.plan[:activeplan])
end empty!(a.plan[:currenttrajectory])
a.memory = newAgentMemory()
# @show a.messages
# @show a.memory
end end