Skip to content

feat: Add Moonshot (Kimi) provider for K2.5 and legacy models#407

Open
howardpen9 wants to merge 1 commit intoBeehiveInnovations:mainfrom
howardpen9:feat/moonshot-kimi-provider
Open

feat: Add Moonshot (Kimi) provider for K2.5 and legacy models#407
howardpen9 wants to merge 1 commit intoBeehiveInnovations:mainfrom
howardpen9:feat/moonshot-kimi-provider

Conversation

@howardpen9
Copy link
Copy Markdown

Summary

Adds native Moonshot/Kimi as a first-class provider, following the existing XAI provider pattern exactly.

  • Provider class: MoonshotModelProvider using RegistryBackedProviderMixin + OpenAICompatibleProvider
  • 4 models via JSON config: kimi-k2.5 (262K ctx, thinking, vision), kimi-k2-0905-preview, moonshot-v1-128k, moonshot-v1-32k
  • Alias resolution: kimikimi-k2.5, moonshotkimi-k2.5, moonshot-128kmoonshot-v1-128k, etc.
  • Model restrictions: MOONSHOT_ALLOWED_MODELS env var support
  • 15 unit tests covering initialization, validation, capabilities, restrictions, and alias-before-API-call

Motivation

Community requested Kimi/Moonshot support (Issue #198). Moonshot API is OpenAI-compatible at https://api.moonshot.cn/v1, making integration straightforward via the existing OpenAICompatibleProvider base class.

Kimi K2.5 is a 1T MoE model with 262K context, extended thinking, vision, and function calling — competitive with frontier models for code and reasoning tasks.

Changes

Action File Description
Create providers/moonshot.py Provider class (~85 lines)
Create providers/registries/moonshot.py Model registry (~15 lines)
Create conf/moonshot_models.json 4 model definitions
Create tests/test_moonshot_provider.py 15 unit tests
Modify providers/shared/provider_type.py Add MOONSHOT enum value
Modify providers/registry.py Add to priority order + key mapping
Modify providers/__init__.py Add export
Modify server.py Add registration in configure_providers()
Modify .env.example Add MOONSHOT_API_KEY entry

Test plan

  • All 15 new Moonshot tests pass (pytest tests/test_moonshot_provider.py -v)
  • Full test suite passes (881 passed, 4 skipped)
  • code_quality_checks.sh passes (ruff + black + isort + tests)
  • Manual verification with real Moonshot API key (tested locally)

Closes #198

🤖 Generated with Claude Code

Add native Moonshot/Kimi provider following the existing XAI provider
pattern. Supports Kimi K2.5 (262K context, extended thinking, vision)
and legacy Moonshot V1 models (128K/32K).

- Provider class with RegistryBackedProviderMixin + OpenAICompatibleProvider
- JSON model config with 4 models and alias resolution
- Model restrictions support via MOONSHOT_ALLOWED_MODELS
- 15 comprehensive unit tests (all passing)

Closes BeehiveInnovations#198

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the platform's AI model capabilities by integrating native support for Moonshot (Kimi) models. It establishes a new provider, defines model configurations with aliases, and incorporates robust mechanisms for model selection and restriction. The changes ensure that Kimi's advanced models, including the K2.5, are fully accessible and manageable within the existing provider framework, enhancing the system's versatility and responsiveness to community requests.

Highlights

  • New Moonshot (Kimi) Provider: Introduced a native MoonshotModelProvider for Kimi models, leveraging the existing OpenAICompatibleProvider pattern for seamless integration.
  • Model Definitions and Aliases: Added configuration for four Moonshot models (kimi-k2.5, kimi-k2-0905-preview, moonshot-v1-128k, moonshot-v1-32k) including aliases for convenient access (e.g., 'kimi' maps to 'kimi-k2.5').
  • Model Restrictions and Routing: Implemented support for MOONSHOT_ALLOWED_MODELS environment variable to restrict available models and defined logic for preferred model selection based on tool categories (e.g., EXTENDED_REASONING, FAST_RESPONSE).
  • Comprehensive Unit Testing: Included 15 new unit tests covering provider initialization, model validation, capability retrieval, restriction enforcement, and alias resolution before API calls.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .env.example
    • Added MOONSHOT_API_KEY entry to the example environment variables.
  • conf/moonshot_models.json
    • Created a new JSON configuration file defining Moonshot (Kimi) models, their capabilities, and aliases.
  • providers/init.py
    • Imported and exported the new MoonshotModelProvider.
  • providers/moonshot.py
    • Added the MoonshotModelProvider class, implementing the integration for Moonshot's OpenAI-compatible API.
  • providers/registries/moonshot.py
    • Created MoonshotModelRegistry to load model capabilities from moonshot_models.json.
  • providers/registry.py
    • Updated the ModelProviderRegistry to include ProviderType.MOONSHOT in the priority order and map its API key.
  • providers/shared/provider_type.py
    • Added MOONSHOT as a new ProviderType enum value.
  • server.py
    • Modified configure_providers to check for MOONSHOT_API_KEY, import MoonshotModelProvider, register it, and include it in model restriction validation.
  • tests/test_moonshot_provider.py
    • Added a new test file with 15 unit tests for the MoonshotModelProvider.
Activity
  • The author has implemented a new MoonshotModelProvider and its associated registry and configuration.
  • Comprehensive unit tests (15 total) have been added to validate the new provider's functionality, including initialization, model validation, capability retrieval, restrictions, and alias resolution.
  • The author has confirmed that all new Moonshot tests pass, the full test suite passes, and code quality checks are successful.
  • Manual verification with a real Moonshot API key was performed locally by the author.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request successfully integrates Moonshot (Kimi) as a new first-class provider, following the established XAI provider pattern. The changes are comprehensive, covering environment variable configuration, model definition, provider implementation, and registry updates. The addition of 15 unit tests ensures the new provider's functionality, including initialization, model validation, capability retrieval, restriction handling, and crucial alias resolution before API calls. The code is clean, consistent with existing patterns, and appears to be well-structured. No issues, bugs, or improvement opportunities meeting the specified severity criteria (medium, high, critical) were identified.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 27c0256a90

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread providers/registry.py
ProviderType.OPENAI, # Direct OpenAI access
ProviderType.AZURE, # Azure-hosted OpenAI deployments
ProviderType.XAI, # Direct X.AI GROK access
ProviderType.MOONSHOT, # Direct Moonshot Kimi access
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Wire Moonshot into centralized model restriction parsing

Adding Moonshot to provider priority means auto-mode selection and get_available_models(respect_restrictions=True) will consider Moonshot models, but ModelRestrictionService.ENV_VARS (in utils/model_restrictions.py) still has no ProviderType.MOONSHOT entry. In environments that set MOONSHOT_ALLOWED_MODELS, restricted Moonshot models are still advertised/selected and only fail later when request-time validation runs in OpenAICompatibleProvider._ensure_model_allowed, which can break auto-mode flows with avoidable runtime ValueErrors.

Useful? React with 👍 / 👎.

def __init__(self, config_path: str | None = None) -> None:
super().__init__(
env_var_name="MOONSHOT_MODELS_CONFIG_PATH",
default_filename="moonshot_models.json",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Include moonshot_models.json in packaged data files

This registry depends on conf/moonshot_models.json, but the packaging manifest still enumerates only the older conf JSON files in [tool.setuptools.data-files] (pyproject.toml), so wheel installs omit the new Moonshot manifest. In a packaged deployment the provider will initialize with an empty model registry, causing Moonshot model listing/validation to fail even when MOONSHOT_API_KEY is configured.

Useful? React with 👍 / 👎.

@howardpen9
Copy link
Copy Markdown
Author

123

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

It's time to add "kimi k2" and "doubao-seed-1.6" to the model provider.

1 participant