From 96de55102f60af7fa640feadc96c97aa3abccb18 Mon Sep 17 00:00:00 2001 From: Joel Garrett <106195533+joelgarrett@users.noreply.github.com> Date: Thu, 19 Sep 2024 10:55:50 -0400 Subject: [PATCH] Resolve unknown message role exceptions - updates OpenAI `process_response` to extract `role` with default --- src/ell/providers/openai.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ell/providers/openai.py b/src/ell/providers/openai.py index 2921062c..2381916c 100644 --- a/src/ell/providers/openai.py +++ b/src/ell/providers/openai.py @@ -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: @@ -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, )