add guard role
This commit is contained in:
@@ -10,6 +10,7 @@ using JSON3, DataStructures
|
||||
|
||||
|
||||
@kwdef mutable struct agent
|
||||
availableRole=["system", "user", "assistant"]
|
||||
sessionId::Int= 1
|
||||
maxUserMsg::Int= 10
|
||||
|
||||
@@ -34,6 +35,10 @@ julia> addNewMessage(agent1, "user", "Where should I go to buy snacks")
|
||||
````
|
||||
"""
|
||||
function addNewMessage(a::agent, role::String, content::String)
|
||||
if role ∉ a.availableRole # guard against typo
|
||||
error("role is not in agent.availableRole")
|
||||
end
|
||||
|
||||
# check whether user messages exceed limit
|
||||
userMsg = 0
|
||||
for i in a.messages
|
||||
|
||||
Reference in New Issue
Block a user