Skip to content

Commit

Permalink
Fix new response_format variable in openai api (#1053)
Browse files Browse the repository at this point in the history
  • Loading branch information
plaguss authored Nov 7, 2024
1 parent f1397e9 commit 53e46c1
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/distilabel/models/llms/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ async def agenerate( # type: ignore
temperature: float = 1.0,
top_p: float = 1.0,
stop: Optional[Union[str, List[str]]] = None,
response_format: Optional[str] = None,
response_format: Optional[Dict[str, str]] = None,
) -> GenerateOutput:
"""Generates `num_generations` responses for the given input using the OpenAI async
client.
Expand All @@ -257,7 +257,8 @@ async def agenerate( # type: ignore
Defaults to `None`.
response_format: the format of the response to return. Must be one of
"text" or "json". Read the documentation [here](https://platform.openai.com/docs/guides/text-generation/json-mode)
for more information on how to use the JSON model from OpenAI. Defaults to `text`.
for more information on how to use the JSON model from OpenAI. Defaults to None
which returns text. To return JSON, use {"type": "json_object"}.
Note:
If response_format
Expand Down Expand Up @@ -292,15 +293,6 @@ async def agenerate( # type: ignore
}

if response_format is not None:
if response_format not in ["text", "json", "json_object"]:
raise ValueError(
f"Invalid response format '{response_format}'. Must be either 'text'"
" or 'json'."
)

if response_format == "json":
response_format = "json_object"

kwargs["response_format"] = response_format

if structured_output:
Expand Down

0 comments on commit 53e46c1

Please sign in to comment.