Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable valid OpenAI response_format specification #1069

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/distilabel/llms/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ async def agenerate( # type: ignore
if response_format == "json":
response_format = "json_object"

kwargs["response_format"] = response_format
kwargs["response_format"] = {"type": response_format}

if structured_output:
kwargs = self._prepare_kwargs(kwargs, structured_output) # type: ignore
Expand Down Expand Up @@ -395,6 +395,18 @@ def offline_batch_generate(
return self._check_and_get_batch_results()

if inputs:
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"

response_format = {"type": response_format}

self.jobs_ids = self._create_jobs(
inputs=inputs,
**{
Expand Down