update
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
module interface
|
||||
|
||||
# export
|
||||
export addNewMessage
|
||||
|
||||
using JSON3, DataStructures, Dates, UUIDs, HTTP, Random
|
||||
using GeneralUtils
|
||||
@@ -47,7 +47,7 @@ using ..type, ..util, ..llmfunction
|
||||
|
||||
Return\n
|
||||
-----
|
||||
messageleft
|
||||
message left
|
||||
|
||||
Example\n
|
||||
-----
|
||||
@@ -72,38 +72,25 @@ using ..type, ..util, ..llmfunction
|
||||
msgMeta,
|
||||
agentConfig,
|
||||
)
|
||||
julia> addNewMessage(a, "user", "hello")
|
||||
julia> YiemAgent.addNewMessage(a, "user", "hello")
|
||||
```
|
||||
|
||||
Signature\n
|
||||
-----
|
||||
""" #WORKING
|
||||
function addNewMessage(a::T1, role::String, text::T2;
|
||||
maximumMsg::Integer=20)::Integer where {T1<:agent, T2<:AbstractString}
|
||||
if role ∉ a.availableRole # guard against typo
|
||||
maximumMsg::Integer=20) where {T1<:agent, T2<:AbstractString}
|
||||
if role ∉ ["system", "user", "assistant"] # guard against typo
|
||||
error("role is not in agent.availableRole $(@__LINE__)")
|
||||
end
|
||||
|
||||
# check whether user messages exceed limit
|
||||
userMsg = 0
|
||||
for i in a.messages
|
||||
if i[:role] == "user"
|
||||
userMsg += 1
|
||||
end
|
||||
end
|
||||
messageleft = 0
|
||||
|
||||
if userMsg > maximumMsg # delete all conversation
|
||||
clearMessage(a)
|
||||
messageleft = maximumMsg
|
||||
#TODO summarize the oldest 10 message
|
||||
if length(a.chathistory) > maximumMsg
|
||||
summarize(a.chathistory)
|
||||
else
|
||||
userMsg += 1
|
||||
d = Dict(:role=> role, :text=> text, :timestamp=> Dates.now())
|
||||
push!(a.messages, d)
|
||||
messageleft = maximumMsg - userMsg
|
||||
push!(a.chathistory, d)
|
||||
end
|
||||
|
||||
return messageleft
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user