Skip to content

Commit

Permalink
Fix response_format for TogetherLLM (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmbmb committed Jul 1, 2024
1 parent adc12f9 commit 13b9538
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/distilabel/llms/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ async def agenerate( # type: ignore
temperature: float = 1.0,
top_p: float = 1.0,
stop: Optional[Union[str, List[str]]] = None,
response_format: str = "text",
response_format: Optional[str] = None,
) -> GenerateOutput:
"""Generates `num_generations` responses for the given input using the OpenAI async
client.
Expand Down Expand Up @@ -223,12 +223,6 @@ async def agenerate( # type: ignore
Returns:
A list of lists of strings containing the generated responses for each input.
"""
if response_format == "json":
response_format = "json_object"
elif response_format != "text":
raise ValueError(
f"Invalid response format '{response_format}'. Must be either 'text' or 'json'."
)

structured_output = None
if isinstance(input, tuple):
Expand All @@ -254,8 +248,20 @@ async def agenerate( # type: ignore
"top_p": top_p,
"stop": stop,
"timeout": 50,
"response_format": {"type": response_format},
}

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:
kwargs = self._prepare_kwargs(kwargs, structured_output)

Expand Down

0 comments on commit 13b9538

Please sign in to comment.