- Notifications
You must be signed in to change notification settings - Fork1k
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 ourterms of service andprivacy 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?
Conversation
Uh oh!
There was an error while loading.Please reload this page.
@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
todcd7d87
CompareI made 2 PRs: |
Uh oh!
There was an error while loading.Please reload this page.
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?
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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 theHyperlint 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 |
Uh oh!
There was an error while loading.Please reload this page.
# 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 thetool_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 thanstrict
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 thejson_schema
response_format
, justjson_object
, so we can setsupports_json_object_output
toTrue
(they're bothFalse
by default).
I don't see anything aboutstrict
on tool definitions though, so I think we can drop that.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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 thejson_schema
response_format
, justjson_object
, so we can setsupports_json_object_output
toTrue
(they're bothFalse
by default).
I don't see anything aboutstrict
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[ |
Uh oh!
There was an error while loading.Please reload this page.
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.