Resolve unknown message role exceptions

- updates OpenAI `process_response` to extract `role` with default
This commit is contained in:
Joel Garrett
2024-09-19 10:55:50 -04:00
parent 63d4de3571
commit 96de55102f

View File

@@ -182,6 +182,9 @@ try:
) )
) )
) )
# Determine the role for streaming responses, defaulting to 'assistant' if not provided
streamed_role = next((choice.delta.role for choice in choice_deltas if choice.delta.role), 'assistant')
else: else:
choice = choice_deltas[0].message choice = choice_deltas[0].message
if choice.refusal: if choice.refusal:
@@ -229,7 +232,7 @@ try:
role=( role=(
choice.role choice.role
if not call_result.actual_streaming if not call_result.actual_streaming
else choice_deltas[0].delta.role else streamed_role
), ),
content=content, content=content,
) )