Skip to content

feat(moonshot): add Moonshot (Kimi) ChatModel implementation#817

Open
Narizis wants to merge 3 commits into
cloudwego:mainfrom
Narizis:feat/moonshot-chat-model
Open

feat(moonshot): add Moonshot (Kimi) ChatModel implementation#817
Narizis wants to merge 3 commits into
cloudwego:mainfrom
Narizis:feat/moonshot-chat-model

Conversation

@Narizis
Copy link
Copy Markdown

@Narizis Narizis commented May 3, 2026

Summary

Adds a new components/model/moonshot package that implements model.ToolCallingChatModel for Moonshot AI (Kimi) via its OpenAI-compatible API.

The implementation is a thin wrapper over libs/acl/openai (same shape as components/model/qwen):

  • Default BaseURL set to https://api.moonshot.cn/v1.
  • Generate / Stream / WithTools / BindTools / BindForcedTools forwarded to the shared OpenAI client.
  • Standard OpenAI parameters exposed in ChatModelConfig (model, max_tokens, temperature, top_p, stop, presence/frequency penalty, response_format, user).
  • Moonshot-specific parameters (e.g. partial for prefix completion, context_cache) can be passed through WithExtraFields.

Test plan

  • go build ./... and go vet ./... pass under Go 1.23 inside components/model/moonshot/.
  • End-to-end smoke test against the real Moonshot API (moonshot-v1-8k):
    • Generate returned a valid completion with usage info (33 prompt + 11 completion tokens).
    • Stream returned the same content via streaming chunks.
  • Tool-calling end-to-end against the real API (moonshot-v1-8k) with WithTools:
    • Generate returned a tool_calls entry with the correct function name and JSON arguments.
    • Stream chunks merged via schema.ConcatMessages produced the same tool_calls entry (no Index=nil workaround needed, unlike Qwen / DashScope).
    • Feeding a synthetic tool result back as a schema.Tool message produced the expected final assistant reply.

Thin wrapper over libs/acl/openai exposing the Moonshot OpenAI-compatible
endpoint. Supports Generate / Stream / tool calling / JSON mode, and
provides WithExtraFields / WithExtraHeader as an escape hatch for
Moonshot-specific parameters (e.g. partial, context_cache).
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 3, 2026

CLA assistant check
All committers have signed the CLA.

Narizis added 2 commits May 3, 2026 11:34
Required by the repo's compliant CI check for newly added components.
@Narizis
Copy link
Copy Markdown
Author

Narizis commented May 3, 2026

@shentongmartin @JonXSnow could you take a look when you have a chance?
Thanks! 🙇

@shentongmartin
Copy link
Copy Markdown
Contributor

@shentongmartin @JonXSnow could you take a look when you have a chance? Thanks! 🙇

@Narizis What's the difference between this and the OpenAI ChatModel?

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants