-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(provider/mistral): response_format.type: 'json_schema'
#8130
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
Changes from all commits
dd74454
d72252d
f326cf3
2ece10b
61c1acf
a6c76d1
4ef15d2
fd480fc
e8ea0da
eed7447
7203cd5
3bbd3f5
178031f
e3ec01e
f74cd3f
4aeb30c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@ai-sdk/mistral': patch | ||
| --- | ||
|
|
||
| feat(provider/mistral): `response_format.type === 'json_schema'` | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -110,22 +110,12 @@ export class MistralChatLanguageModel implements LanguageModelV2 { | |||||
| }); | ||||||
| } | ||||||
|
|
||||||
| // TODO remove when we have JSON schema support (see OpenAI implementation) | ||||||
| if ( | ||||||
| responseFormat != null && | ||||||
gr2m marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| responseFormat.type === 'json' && | ||||||
| responseFormat.schema != null | ||||||
| ) { | ||||||
| warnings.push({ | ||||||
| type: 'unsupported-setting', | ||||||
| setting: 'responseFormat', | ||||||
gr2m marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| details: 'JSON response format schema is not supported', | ||||||
| }); | ||||||
| } | ||||||
| const structuredOutputs = options.structuredOutputs ?? true; | ||||||
| const strictJsonSchema = options.strictJsonSchema ?? false; | ||||||
|
|
||||||
| // For Mistral we need to need to instruct the model to return a JSON object. | ||||||
| // https://docs.mistral.ai/capabilities/structured-output/structured_output_overview/ | ||||||
| if (responseFormat?.type === 'json') { | ||||||
| if (responseFormat?.type === 'json' && !responseFormat?.schema) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
When View DetailsAnalysisThe logic for JSON instruction injection has a bug when This means when:
The condition on line 118 evaluates to RecommendationUpdate the condition on line 118 to inject JSON instructions when either there's no schema OR when there's a schema but if (responseFormat?.type === 'json' && (!responseFormat?.schema || !structuredOutputs)) {This ensures that JSON instructions with schema information are injected when |
||||||
| prompt = injectJsonInstructionIntoMessages({ | ||||||
| messages: prompt, | ||||||
| schema: responseFormat.schema, | ||||||
|
|
@@ -146,9 +136,20 @@ export class MistralChatLanguageModel implements LanguageModelV2 { | |||||
| random_seed: seed, | ||||||
|
|
||||||
| // response format: | ||||||
| // TODO add JSON schema support (see OpenAI implementation) | ||||||
| response_format: | ||||||
| responseFormat?.type === 'json' ? { type: 'json_object' } : undefined, | ||||||
| responseFormat?.type === 'json' | ||||||
| ? structuredOutputs && responseFormat?.schema != null | ||||||
| ? { | ||||||
| type: 'json_schema', | ||||||
| json_schema: { | ||||||
| schema: responseFormat.schema, | ||||||
| strict: strictJsonSchema, | ||||||
| name: responseFormat.name ?? 'response', | ||||||
| description: responseFormat.description, | ||||||
| }, | ||||||
| } | ||||||
| : { type: 'json_object' } | ||||||
| : undefined, | ||||||
|
|
||||||
| // mistral-specific provider options: | ||||||
| document_image_limit: options.documentImageLimit, | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.