-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: add MoonshotAI provider with Kimi-K2 model support #2211
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
base: main
Are you sure you want to change the base?
feat: add MoonshotAI provider with Kimi-K2 model support #2211
Conversation
@zachmayer Thanks Zach! As you suggested, can you please split this up into separate PRs so the more straightforward ones can be merged more quickly? Pretty commit history is not that important, we'll end up squashing on merge anyway. Also, from the Maybe we can keep this PR for the MoonshotAIProvider as I already started talking about it :) |
- Add MoonshotAIProvider with OpenAI-compatible API - Implements OpenAI-style interface with custom base URL - Supports tool definitions but not strict tool validation - Add moonshotai:kimi-k2-0711-preview as known model - Configure to use OpenAIModel for compatibility - Add comprehensive tests for provider functionality - Update CLI and model name tests
4c4ebf7
to
dcd7d87
Compare
I made 2 PRs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zachmayer Thank you! In addition to these comments, can you please add some docs?
PR Change SummaryAdded a new MoonshotAI provider to support Kimi-K2 models, enhancing compatibility with OpenAI's API.
Modified Files
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 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 |
I added a moonshot example to the open ai docs |
|
||
# As the MoonshotAI API is OpenAI-compatible, let's assume we also need OpenAIJsonSchemaTransformer, | ||
# unless json_schema_transformer is set explicitly. | ||
# Also, MoonshotAI does not support strict tool definitions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually the case or was it just a misinterpretation of the tool_choice=required
thing? If so, we can drop this from the comment and drop the field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at their docs:
- https://platform.moonshot.ai/docs/guide/use-json-mode-feature-of-kimi-api
- https://platform.moonshot.ai/docs/api/chat?utm_source=chatgpt.com#request-body
When you set response_format to {"type": "json_object"}, you must explicitly guide the model to output JSON-formatted content in the prompt and specify the exact format of the JSON, otherwise it may result in unexpected outcomes.
My reading of this is that they don't support strict: mode. You can ask it for a json object, but you need to verybally describe the fields you want in the object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh hmmm, this parameter is different than strict
for output schemas though. Now I'm not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah look like they don't support the json_schema
response_format
, just json_object
, so we can set supports_json_object_output
to True
(they're both False
by default).
I don't see anything about strict
on tool definitions though, so I think we can drop that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you look at the merge conflict as well please?
|
||
# As the MoonshotAI API is OpenAI-compatible, let's assume we also need OpenAIJsonSchemaTransformer, | ||
# unless json_schema_transformer is set explicitly. | ||
# Also, MoonshotAI does not support strict tool definitions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah look like they don't support the json_schema
response_format
, just json_object
, so we can set supports_json_object_output
to True
(they're both False
by default).
I don't see anything about strict
on tool definitions though, so I think we can drop that.
) | ||
from pydantic_ai.providers import Provider | ||
|
||
MoonshotModelName = Literal[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with the provider class:
MoonshotModelName = Literal[ | |
MoonshotAIModelName = Literal[ |
This PR adds a new MoonshotAI provider for Kimi models.
Related PRs:
Changes
The provider follows the same pattern as other OpenAI-compatible providers like DeepSeek and Grok.
As requested by @DouweM, I've split the original large PR into 3 focused PRs for easier review.