Skip to content

Commit 36dd84f

Browse files
committed
type checking on old openai versions
1 parent b0cb1c1 commit 36dd84f

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

parea/wrapper/openai/openai.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ def convert_to_openai_object(kwargs) -> OpenAIObject:
2828
if "model" not in kwargs:
2929
kwargs["model"] = "model"
3030
if "choices" in kwargs and isinstance(kwargs["choices"], list) and len(kwargs["choices"]) > 0:
31-
if "message" in kwargs["choices"][0]:
32-
if "parsed" in kwargs["choices"][0]["message"]:
33-
kwargs["choices"][0]["message"]["content"] = json_dumps(kwargs["choices"][0]["message"]["parsed"])
34-
3531
if "finish_reason" not in kwargs["choices"][0]:
3632
kwargs["choices"][0]["finish_reason"] = "stop"
3733

@@ -289,7 +285,7 @@ def _get_output(result: Any, model: Optional[str] = None) -> str:
289285
except ImportError:
290286
ParsedChatCompletionMessage = None
291287

292-
if not isinstance(result, OpenAIObject) and isinstance(result, dict):
288+
if isinstance(result, dict):
293289
result = convert_to_openai_object(
294290
{
295291
"choices": [
@@ -303,7 +299,7 @@ def _get_output(result: Any, model: Optional[str] = None) -> str:
303299
)
304300
response_message = result.choices[0].message
305301
if PARSED_CHAT_COMPLETION_AVAILABLE and isinstance(response_message, ParsedChatCompletionMessage):
306-
completion = response_message.parsed.model_dump_json() if response_message.parsed else ""
302+
completion = json_dumps(response_message.parsed) if response_message.parsed else ""
307303
elif not response_message.get("content", None) if is_old_openai else not response_message.content:
308304
completion = OpenAIWrapper._format_function_call(response_message)
309305
else:

0 commit comments

Comments
 (0)