feat(providers): add Kimi (Moonshot AI) provider support#71
feat(providers): add Kimi (Moonshot AI) provider support#71aispatialomics wants to merge 1 commit into
Conversation
Add native Kimi provider via Anthropic-compatible Messages API: - New KimiProcessor class and process_kimi() handler (R + Python) - get_provider() recognizes kimi-* and moonshot* model prefixes - Default endpoint https://api.kimi.com/coding/v1/messages - API key read from KIMI_API_KEY environment variable - KimiProcessor.extract_usage() and process_kimi(usage_sink=) support the token-usage capture introduced in 2.0.6 Adapted to the 2.0.6 provider-registry refactor (shared built-in pattern constant plus dispatch table with consistency checks on both the R and Python sides). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
cafferychen777
left a comment
There was a problem hiding this comment.
Thanks for adding Kimi support. The direction is welcome, but the current implementation mixes two different Kimi products and is based on provider-dispatch code that has since changed on main. Please update the PR before merge.
- Target one API product consistently
For mLLMCelltype, please target the Kimi Open Platform rather than the Kimi Code membership endpoint:
- Endpoint:
https://api.moonshot.cn/v1/chat/completions - Authentication:
Authorization: Bearer <MOONSHOT_API_KEY> - Default model:
kimi-k2.6 - Model prefixes:
kimi-andmoonshot- - Protocol: OpenAI-compatible Chat Completions
The current combination of https://api.kimi.com/coding/v1/messages with kimi-k2.7 and moonshot-v1-8k is not a valid contract. The Kimi Code endpoint uses separate credentials and accepts kimi-for-coding or kimi-for-coding-highspeed; the Open Platform uses api.moonshot.cn and models such as kimi-k2.6 and moonshot-v1-*.
Official references:
- https://www.kimi.com/code/docs/en/
- https://www.kimi.com/code/docs/en/kimi-code/faq.html
- https://platform.kimi.com/docs/models
- https://platform.kimi.com/docs/api/chat
If Kimi Code support is also desired, please implement it later as a separate kimi_code provider so its endpoint, credentials, and model IDs cannot be mixed with Open Platform requests.
- Rebase onto the latest
mainand follow the current registries
The PR currently conflicts with main in the R registry/dispatch files and in Python dispatch construction.
For R:
- Add one
kimientry to.BUILTIN_PROVIDER_SPECSwith the pattern,KimiProcessor, and display name. - Implement a thin
KimiProcessorthat reusesprivate$post_chat_completions_request()andprivate$extract_chat_completions_content(). - Remove
process_kimi.R. - Do not restore
get_builtin_provider_processors(). - Do not add another provider-name map to
BaseAPIProcessor; display names are derived from.BUILTIN_PROVIDER_SPECS.
For Python:
- Add the provider configuration in
config.py. - Export
process_kimifromproviders/__init__.py. - Implement
process_kimiusing the existingbuild_chat_completions_body()andcall_openai_compatible_api()helpers. - Do not manually edit the dispatch map in
functions.py; the current runtime registry is built and validated automatically.
This should make Kimi a small provider-specific wrapper instead of duplicating the Anthropic implementation in both languages.
- Add provider-specific tests
Please add tests for both Python and R covering:
- provider detection for
kimi-k2.6andmoonshot-v1-8k - default model, endpoint, and API-key environment variable
- request URL, Bearer header, model, messages, and thinking policy
- response parsing and normalized usage
- custom endpoint handling
- malformed/error responses
- registry consistency
The existing test suites pass, but no current test exercises the new Kimi code. In the present PR, python/mllmcelltype/providers/kimi.py is only 25% covered.
- Keep release history accurate
Version 2.0.6 has already been released. Please put this feature under the next development-version NEWS section rather than adding it retroactively to the 2.0.6 release notes.
After the rebase and rewrite, please run:
cd python && ruff check mllmcelltype testscd python && pytest --cov=mllmcelltype tests/cd R && Rscript -e "devtools::test()"
Please also complete the PR description and testing checklist with the actual environment and results. Once these changes are pushed, I will review the updated implementation again.
Add native Kimi provider via Anthropic-compatible Messages API:
Adapted to the 2.0.6 provider-registry refactor (shared built-in pattern constant plus dispatch table with consistency checks on both the R and Python sides).
Description
What does this PR do?
Why is this change needed?
Related Issues
Type of Change
Testing
Test Environment:
Checklist