Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
zachmayer wants to merge13 commits intopydantic:main
base:main
Choose a base branch
Loading
fromzachmayer:feat/add-kimi-grok-o3pro-clean

Conversation

zachmayer
Copy link
Contributor

@zachmayerzachmayer commentedJul 15, 2025
edited
Loading

This PR adds a new MoonshotAI provider for Kimi models.

Related PRs:

Changes

  • Add MoonshotAIProvider with OpenAI-compatible API
  • Implements OpenAI-style interface with custom base URL (api.moonshot.ai)
  • Supports tool definitions but disables strict tool validation (as per MoonshotAI docs)
  • 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
  • Uses MOONSHOT_API_KEY environment variable

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.

@zachmayerzachmayer marked this pull request as draftJuly 16, 2025 14:55
@zachmayerzachmayer marked this pull request as ready for reviewJuly 16, 2025 15:36
@zachmayerzachmayer changed the titlefeat: add o3-pro, grok-4, kimi-k2 model namesfeat: add o3-pro, grok-4, kimi-k2Jul 16, 2025
@zachmayer
Copy link
ContributorAuthor

@DouweM@Kludex I think this is ready for review. I'd be happy to split it up into several PRs if you like (or squash the commits!)

@DouweMDouweM self-assigned thisJul 16, 2025
@DouweM
Copy link
Contributor

@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 theMoonshotAIProvider, "Please note that the current version of Kimi API does not support the tool_choice=required parameter." makes me think we'll need a new field onOpenAIModelProfile to stop sending that value in this case and prevent errors. They suggest "you can emphasize the use of a certain tool in the prompt to achieve a similar effect" as a workaround, so I wonder if the default "The final response which ends this conversation" description of the output tool that we require to be called is already sufficient.

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
@zachmayerzachmayerforce-pushed thefeat/add-kimi-grok-o3pro-clean branch from4c4ebf7 todcd7d87CompareJuly 17, 2025 14:13
@zachmayerzachmayer changed the titlefeat: add o3-pro, grok-4, kimi-k2feat: add MoonshotAI provider with Kimi-K2 model supportJul 17, 2025
@zachmayer
Copy link
ContributorAuthor

Copy link
Contributor

@DouweMDouweM left a 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?

zachmayer reacted with thumbs up emoji
@hyperlint-aiHyperlint AI
Copy link
Contributor

PR Change Summary

Added a new MoonshotAI provider to support Kimi-K2 models, enhancing compatibility with OpenAI's API.

  • Introduced MoonshotAIProvider with OpenAI-compatible API
  • Implemented support for Kimi-K2 model
  • Added comprehensive tests for provider functionality
  • Updated CLI and model name tests

Modified Files

  • docs/models/openai.md

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 thehyperlint-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 addhyperlint-ignore to the PR to ignore the link check for this PR.

@zachmayer
Copy link
ContributorAuthor

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
Copy link
Contributor

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

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Looking at their docs:

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.

Copy link
ContributorAuthor

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.

Copy link
Contributor

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_schemaresponse_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.

Copy link
Contributor

@DouweMDouweM left a 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
Copy link
Contributor

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_schemaresponse_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[
Copy link
Contributor

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:

Suggested change
MoonshotModelName=Literal[
MoonshotAIModelName=Literal[

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@DouweMDouweMDouweM requested changes

Assignees

@DouweMDouweM

Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@zachmayer@DouweM

[8]ページ先頭

©2009-2025 Movatter.jp