Skip to content

Commit

Permalink
Resolve unknown message role exceptions
Browse files Browse the repository at this point in the history
- updates OpenAI `process_response` to extract `role` with default
  • Loading branch information
joelgarrett committed Sep 19, 2024
1 parent 63d4de3 commit 96de551
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ell/providers/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ def process_response(
)
)
)

# 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:
choice = choice_deltas[0].message
if choice.refusal:
Expand Down Expand Up @@ -229,7 +232,7 @@ def process_response(
role=(
choice.role
if not call_result.actual_streaming
else choice_deltas[0].delta.role
else streamed_role
),
content=content,
)
Expand Down

0 comments on commit 96de551

Please sign in to comment.