add guard role

This commit is contained in:
2023-10-09 14:20:43 +00:00
parent 6ee73a2c52
commit 7187c03692

View File

@@ -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