|
|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
import json
|
|
|
|
|
import logging
|
|
|
|
|
from collections.abc import Generator
|
|
|
|
|
from typing import Optional, Union, cast
|
|
|
|
|
@ -544,13 +545,18 @@ class OpenAILargeLanguageModel(_CommonOpenAI, LargeLanguageModel):
|
|
|
|
|
|
|
|
|
|
response_format = model_parameters.get("response_format")
|
|
|
|
|
if response_format:
|
|
|
|
|
if response_format == "json_object":
|
|
|
|
|
response_format = {"type": "json_object"}
|
|
|
|
|
if response_format == "json_schema":
|
|
|
|
|
json_schema = model_parameters.get("json_schema")
|
|
|
|
|
if not json_schema:
|
|
|
|
|
raise ValueError("Must define JSON Schema when the response format is json_schema")
|
|
|
|
|
try:
|
|
|
|
|
schema = json.loads(json_schema)
|
|
|
|
|
except:
|
|
|
|
|
raise ValueError(f"not currect json_schema format: {json_schema}")
|
|
|
|
|
model_parameters.pop("json_schema")
|
|
|
|
|
model_parameters["response_format"] = {"type": "json_schema", "json_schema": schema}
|
|
|
|
|
else:
|
|
|
|
|
response_format = {"type": "text"}
|
|
|
|
|
|
|
|
|
|
model_parameters["response_format"] = response_format
|
|
|
|
|
|
|
|
|
|
model_parameters["response_format"] = {"type": response_format}
|
|
|
|
|
|
|
|
|
|
extra_model_kwargs = {}
|
|
|
|
|
|
|
|
|
|
|