Skip to content

[Inference Providers] Fix structured output #1579

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

Merged
merged 5 commits into from
Jul 4, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 23 additions & 0 deletions packages/inference/src/providers/nebius.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ export class NebiusConversationalTask extends BaseConversationalTask {
constructor() {
super("nebius", NEBIUS_API_BASE_URL);
}

override preparePayload(params: BodyParams): Record<string, unknown> {
const payload = super.preparePayload(params) as Record<string, unknown>;

const responseFormat = (params.args as Record<string, unknown>)["response_format"];
if (
responseFormat &&
typeof responseFormat === "object" &&
"type" in responseFormat &&
(responseFormat as { type?: unknown }).type === "json_schema"
) {
const jsonSchemaDetails = (responseFormat as Record<string, unknown>)["json_schema"];
if (
jsonSchemaDetails &&
typeof jsonSchemaDetails === "object" &&
"schema" in (jsonSchemaDetails as Record<string, unknown>)
) {
payload["guided_json"] = (jsonSchemaDetails as Record<string, unknown>)["schema"];
}
}

return payload;
}
}

export class NebiusTextGenerationTask extends BaseTextGenerationTask {
Expand Down
24 changes: 24 additions & 0 deletions packages/inference/src/providers/sambanova.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@ export class SambanovaConversationalTask extends BaseConversationalTask {
constructor() {
super("sambanova", "https://api.sambanova.ai");
}

override preparePayload(params: BodyParams): Record<string, unknown> {
const payload = super.preparePayload(params) as Record<string, unknown>;

const responseFormat = (params.args as Record<string, unknown>)["response_format"];
if (
responseFormat &&
typeof responseFormat === "object" &&
"type" in responseFormat &&
(responseFormat as { type?: unknown }).type === "json_schema"
) {
const jsonSchemaConfig = (responseFormat as Record<string, unknown>)["json_schema"] as
| Record<string, unknown>
| undefined;
if (jsonSchemaConfig && typeof jsonSchemaConfig === "object") {
const strict = jsonSchemaConfig["strict"];
if (strict === true || strict === undefined) {
jsonSchemaConfig["strict"] = false;
}
}
}

return payload;
}
}

export class SambanovaFeatureExtractionTask extends TaskProviderHelper implements FeatureExtractionTaskHelper {
Expand Down