Skip to content

Feat: Add id and finish_reason to ModelResponse #1761

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

Conversation

davide-andreoli
Copy link
Contributor

Add id and finish_reason to ModelResponse

Description

Following issue #886, this update adds id and finish_reasons to ModelResponse.

Below the details:

  • id: id of the request, defaults to a random UUID
  • finish_reasons: list of reasons why the generation ended, defaults to an empty list

Gemini implementation

Included in the PR there is an implementation of the fields for Gemini.

The handling of finish_reasons aligns with the current approach for other response parts, where only the first candidate's reason is considered. Note that only those finish reasons defined in the Literal type will be included.

Implementations for other model providers are currently missing due to lack of testing access.

Testing

The changes were validated using my API key, and the behavior matches expectations.

Impact

This update potentially affects all providers. However, with sensible default values in place, the change should have no immediate impact. Provider-specific implementations can be added independently later.

@DouweM
Copy link
Contributor

DouweM commented May 19, 2025

@davide-andreoli We just added a new vendor_id attribute in #1547! Can you please rebase on top of that and remove any changes that are no longer necessary?

Copy link
Contributor

hyperlint-ai bot commented May 20, 2025

PR Change Summary

Enhanced the ModelResponse structure by adding new fields for improved request tracking and response clarity.

  • Added id field to ModelResponse for unique request identification.
  • Introduced finish_reason field to ModelResponse to provide reasons for generation termination.
  • Updated Gemini implementation to include the new fields in the response.
  • Ensured backward compatibility with sensible default values for new fields.

Modified Files

  • docs/agents.md
  • docs/direct.md
  • docs/message-history.md
  • docs/models/index.md
  • docs/tools.md

How can I customize these reviews?

Check out the Hyperlint AI Reviewer docs for more information on how to customize the review.

If you just want to ignore it on this PR, you can add the hyperlint-ignore label to the PR. Future changes won't trigger a Hyperlint review.

Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add hyperlint-ignore to the PR to ignore the link check for this PR.

@davide-andreoli
Copy link
Contributor Author

Hello @DouweM I’ve rebased, but it looks like the changes didn’t apply cleanly and are pulling in intermediate commits. Sorry about that, it's my first time rebasing.
I think it might be clearer if I open a dedicated PR to add finish_reason to ModelResponse and vendor_id for Gemini.
Let me know if that works for you.

@DouweM
Copy link
Contributor

DouweM commented May 21, 2025

@davide-andreoli That works, sorry for the trouble. I'll close this then and will await the new PR.

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

Successfully merging this pull request may close these issues.

7 participants