Skip to content

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

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

Conversation

zachmayer
Copy link
Contributor

@zachmayer zachmayer commented Jul 15, 2025

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.

@zachmayer zachmayer marked this pull request as draft July 16, 2025 14:55
@zachmayer zachmayer marked this pull request as ready for review July 16, 2025 15:36
@zachmayer zachmayer changed the title feat: add o3-pro, grok-4, kimi-k2 model names feat: add o3-pro, grok-4, kimi-k2 Jul 16, 2025
@zachmayer
Copy link
Contributor Author

@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!)

@DouweM DouweM self-assigned this Jul 16, 2025
@DouweM
Copy link
Contributor

DouweM commented Jul 16, 2025

@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 MoonshotAIProvider, "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 on OpenAIModelProfile 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
@zachmayer zachmayer force-pushed the feat/add-kimi-grok-o3pro-clean branch from 4c4ebf7 to dcd7d87 Compare July 17, 2025 14:13
@zachmayer zachmayer changed the title feat: add o3-pro, grok-4, kimi-k2 feat: add MoonshotAI provider with Kimi-K2 model support Jul 17, 2025
@zachmayer
Copy link
Contributor Author

Copy link
Contributor

@DouweM DouweM 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?

Copy link
Contributor

hyperlint-ai bot commented Jul 17, 2025

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

@zachmayer
Copy link
Contributor Author

I added a moonshot example to the open ai docs

Copy link
Contributor

@DouweM DouweM 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?

@zachmayer
Copy link
Contributor Author

I'll make these updates and fix the conflicts.

@zachmayer
Copy link
Contributor Author

@DouweM Ok, I think I covered all your feedback! let me know how it looks.

@zachmayer
Copy link
Contributor Author

zachmayer commented Jul 23, 2025

CI / test on 3.10 (pull_request) I think this error is unrelated to my PR, but I am not sure. it passes now that I synced main.

openai_client: AsyncOpenAI | None = None,
http_client: AsyncHTTPClient | None = None,
) -> None:
api_key = api_key or os.getenv('MOONSHOT_API_KEY')
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick, but I think the prefix here should be consistent with the class name, so either MOONSHOTAI_API_KEY, or MoonshotProvider. I wouldn't mind the latter, as we also have e.g. TogetherProvider instead of TogetherAIProvider. But then again most/all providers seem to use the moonshotai/ prefix for model names, so perhaps MOONSHOTAI_API_KEY is best.

openai_supports_sampling_settings=True,
)

monkeypatch.setattr(OpenAIModelProfile, 'from_profile', fake_from_profile, raising=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a bit more brittle mocking and monkeypatching here than I'd like, can we build a real OpenAIModelProfile with the options we want, and actually pass that to OpenAIModel(..., profile=...)?

Also this should be on tests/models/test_openai.py! See test_model_profile_strict_not_supported for an example.

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.

2 participants