It seems like the current API docs suggest that only 3 possible roles are allowed:
user, system, assistant
Have people tried using custom roles for other entities such as “event”, “form” etc.?
Does the model understand them?
When building a Chatbot, if I have other entities that need to be in the chat history, is it then better to just dump the Chat History into a consistent string representation into a single user message and have the instructions in the system message of how to interpret them?
Approach 1:
message = [
{"role": "system", "content": "Some instruction"},
{"role": "user", "content": "Hi"},
{"role": "assistant", "content": "Hello! How may I help you today"},
{"role": "user", "content": "I want to do X"},
{"role": "assistant", "content": "Please wait while I run an internal tool to do X"},
{"role": "event", "content": "{'tool': 'x', 'status': 'completed'}"},
....
]
Approach 2:
messages = [
{"role": "system", "content": "Some instruction on how to parse the custom chat history object"},
{"role": "user", "content": "
Chat History:
user: Hi
assistant: Hello, how can I help you today?
user: I want to do X.
assistant: Please what while I run an internal tool to do X
event: "{'tool': 'x', 'status': 'completed'}
"
},
]
There are only three types of roles available: system, user, and assistant.
However, you can include different names within the same role.
For example, you can include conversation histories of userA and userB.
completion = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "name": "userA","content": "Hello!"},
{"role": "user", "name": "userB","content": "Hi there!"}
]
)
print(completion.choices[0].message)
In the same way, is it possible to specify event
as the value for the name
key.
3 Likes
If you want to visualize an implementation of how, what @dignity_for_all is talking about, works in practice, here’s a short clip.
3 Likes
Would you recommend specifying name as “event” for the system message or the user message or the assistant message?
Does the model understand these distinctions?
This is amazing. How are you getting the additional metadata about the message such as message_type to the model? Do you just dump it as a JSON in the content field?
The simplest explanation is that I sub class from Message and add in the necessary attributes; remembering that Message class supports 16 metadata variables.
class AutoExecSubMessage(BaseMessage):
originator:Optional[str] = Field(default="")
# specialized for stories
story_state:Optional[str] = Field(default="Draft")
reference_message_id:Optional[str] = Field(default="")
def update_story_state(self, story_state:str):
self.story_state = story_state
return super().update(story_state=self.story_state)
But the content field in the User message can only be a string. Do you dump it to JSON then?
No. It’s a string. I am not sure what thrust of the question is.
But I can’t convert an arbitary string to json. If you are asking on the way in to chat-completion, I just ignore messages that are set to be ignore.
hth
Sorry if I wasn’t more clear. I don’t know where your AutoExecSubMessage
fits into the content.
Do you just use the story state field or something?
Like
message = AutoExecSubMessage()
messages = [
{'role': 'user', 'name': message.originator, 'content': message.story_state}
]
Oh … I see the question now.
for message in as_thread.list_messages():
# specialized for story
if message.story_state == 'Draft' or message.story_state == 'Final':
# end specialized for story
previous_messages.append({'role': message.role, 'content': message.content[0]['text'].value})