Skip to content

Feat(mistral) use actual response format #6327

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Autumnlight02
Copy link

Background

Currently when calling the mistral AI we are passing on the response schema as an message, but do not actually make use of the structured output endpoint. This commit changes that.

Summary

  1. I implemented that instead of having to rely on the depricated mode.schema, that we now get proper responseFormat results. This should allow us now to stop using the depricated mode field in other packages (like openai) as well.
  2. Inside of Mistral I removed the warning and added a handler to actually make use of the responseFormat field and to return the correct Response schema.

Verification

I manually ran the mistral file inside of the ai core generate-object endpoint. And it worked now as expected. (I would prefer if someone could look over it as well to be certain and test if my ResponseFormat fix actually impacted other packages. (Many packages have error handling for ResponseFormat / warnings for it, but since it always returned undefined those we're never invoked (from what I know, I did not check other packages besides mistral and a bit openai)

Tasks

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • Formatting issues have been fixed (run pnpm prettier-fix in the project root)

Future Work

People would now need to go around and update all other packages to move away from the depricated mode field. This should lay the first step to make ResponseFormat usuable.

Related Issues

Did not check.

@Autumnlight02 Autumnlight02 changed the title Feat(mistral) use actual respone format Feat(mistral) use actual response format May 14, 2025
@lgrammel
Copy link
Collaborator

this is great! we have switch dev to the v5 branch. would you mind making the change against v5 instead?

@Autumnlight02
Copy link
Author

Sure can do (will do in a new PR tonight). Do we happen to have an ETA for v5? My company is running into issues during testing, and we would like to use this asap.

(Also thank you for the quick reply)

@lgrammel
Copy link
Collaborator

We can fix on main and v5. Having 2 prs works!

@lgrammel
Copy link
Collaborator

also, can you add a test?

@Autumnlight02
Copy link
Author

Could you point me to a file I can use as a test base? (So I know in which way I should exactly write the test?)

@lgrammel
Copy link
Collaborator

mistral-chat-language-model.test.ts should contain related tests. you can add a new test case.

@Autumnlight02
Copy link
Author

@lgrammel Fixed a bug and added a test case. Good to merge now.

Comment on lines +2 to +3
'@ai-sdk/mistral': minor
'ai': minor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls change to patch

Comment on lines +540 to +543
responseFormat: {
schema: outputStrategy.jsonSchema,
type: 'json',
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the object json mode mode.schema should be used. pls remove

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But is the mode not depricated?
image

The reason why I added responseFormat there was that I've seen that mistral (and I assume others) handle it with a warning, but responseFormat was from what Ive seen never set if you passed on an schema. if I remove this I have to modify my code to handle the schema by the depricated mode field.

If you are still set on removal of this I can do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants