Documentation
¶
Overview ¶
Package kimi provides a Genkit plugin for Moonshot AI's Kimi models.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ModelRef ¶
func ModelRef(id string, config *ChatConfig) ai.ModelRef
ModelRef names a Kimi model and carries the config to generate with, so the config is typed at the call site instead of an any the model checks at runtime. A nil config leaves the request's config unset.
ai.WithModel(kimi.ModelRef("kimi-k3", &kimi.ChatConfig{
ReasoningEffort: "high",
}))
id is the model ID, with or without the provider prefix.
Types ¶
type ChatConfig ¶
type ChatConfig struct {
compat_oai.RequestConfig
// MaxOutputTokens is the maximum number of tokens to generate, sent as the
// API's max_completion_tokens; Moonshot deprecated max_tokens. The default
// and the ceiling vary by model.
MaxOutputTokens int `` /* 202-byte string literal not displayed */
// StopSequences stop generation when produced by the model, up to five of
// at most 32 bytes each. The schema enforces the per-entry limit in
// characters; Moonshot counts bytes.
StopSequences []string `` /* 183-byte string literal not displayed */
// LogProbs requests log probabilities for the output tokens.
LogProbs *bool `json:"logProbs,omitempty" jsonschema_description:"Requests log probabilities for the output tokens."`
// TopLogProbs is how many of the most likely tokens to return log
// probabilities for at each position, from 0 to 20; it requires LogProbs.
TopLogProbs *int `` /* 205-byte string literal not displayed */
// Thinking controls the reasoning mode of thinking-capable Kimi models,
// sent as the API's thinking field.
Thinking *ThinkingConfig `` /* 142-byte string literal not displayed */
// ReasoningEffort adjusts how hard the Kimi K3 generation thinks, from
// [ReasoningEffortLow] to [ReasoningEffortMax], the default.
ReasoningEffort ReasoningEffort `` /* 171-byte string literal not displayed */
}
ChatConfig is the per-request config for Kimi models: the generation fields the K-series accepts plus the Moonshot-specific controls. See https://platform.kimi.ai/docs/api/chat.
Moonshot documents temperature, topP, and the frequency and presence penalties for the legacy moonshot-v1 family only, so the K-series models this plugin serves do not take them and they are deliberately absent.
func (ChatConfig) ApplyToChatCompletion ¶
func (c ChatConfig) ApplyToChatCompletion(params *openai.ChatCompletionNewParams)
ApplyToChatCompletion implements compat_oai.ChatConfig: the generation fields land on their chat completion counterparts, reasoning effort on the SDK's reasoning_effort, and thinking rides as Moonshot's extra request field.
type Kimi ¶
type Kimi struct {
// APIKey is the Moonshot API key. If empty, KIMI_API_KEY and then
// MOONSHOT_API_KEY are consulted.
APIKey string
// Opts contains additional OpenAI client request options, such as
// [option.WithBaseURL] for a different endpoint (KIMI_BASE_URL and
// MOONSHOT_BASE_URL work too). Options supplied here are applied after
// the plugin defaults, so they win on overlap.
Opts []option.RequestOption
// Models overrides what the plugin knows about a Kimi model, keyed by
// model ID, bare or provider-prefixed. Every Kimi model already works
// without an entry: known IDs carry curated capabilities and the rest take
// the Kimi defaults. Supply an entry only to correct or extend what the
// plugin resolves, most often for a model released after this version of
// the plugin.
//
// &kimi.Kimi{Models: map[string]ai.ModelOptions{
// "kimi-k3": {Supports: &ai.ModelSupports{Multiturn: true, Tools: true}},
// }}
//
// Fields left at their zero value keep what the plugin resolves, so an
// entry can pin one capability without restating the label or the
// versions. Entries apply to the models Init registers as well as the
// ones [Kimi.ListActions] advertises and [Kimi.ResolveAction] builds,
// which is the way to describe a curated model differently: Init has
// already registered those and nothing can re-register them.
Models map[string]ai.ModelOptions
// contains filtered or unexported fields
}
Kimi configures the Moonshot AI Kimi plugin.
func (*Kimi) ListActions ¶
func (k *Kimi) ListActions(ctx context.Context) []api.ActionDesc
ListActions lists the models the configured Kimi endpoint exposes, described by the plugin's config schema and capabilities.
func (*Kimi) ResolveAction ¶
ResolveAction dynamically builds a model exposed by the Kimi endpoint, described by the plugin's config schema and capabilities.
type ReasoningEffort ¶
type ReasoningEffort string
ReasoningEffort is how hard the Kimi K3 generation thinks before it answers. Moonshot documents three levels, with ReasoningEffortMax the default.
const ( // ReasoningEffortLow is the fastest, shallowest reasoning. ReasoningEffortLow ReasoningEffort = "low" // ReasoningEffortHigh is deeper reasoning, below the default. ReasoningEffortHigh ReasoningEffort = "high" // ReasoningEffortMax is the deepest reasoning, and the default. ReasoningEffortMax ReasoningEffort = "max" )
type ThinkingConfig ¶
type ThinkingConfig struct {
// Type turns thinking [ThinkingTypeEnabled] or [ThinkingTypeDisabled].
Type ThinkingType `json:"type,omitempty" jsonschema:"enum=enabled,enum=disabled" jsonschema_description:"Turns thinking enabled or disabled."`
// Keep controls how much reasoning is preserved across turns, "all" or
// unset. It is not an enum in the schema: Moonshot documents one value
// today, and a list of one would reject whatever it adds next.
Keep string `json:"keep,omitempty" jsonschema_description:"How much reasoning is preserved across turns: all, or unset for the default."`
}
ThinkingConfig configures the reasoning of thinking-capable Kimi models.
type ThinkingType ¶
type ThinkingType string
ThinkingType turns the reasoning of thinking-capable Kimi models on or off.
const ( // ThinkingTypeEnabled turns thinking on. ThinkingTypeEnabled ThinkingType = "enabled" // ThinkingTypeDisabled turns thinking off. ThinkingTypeDisabled ThinkingType = "disabled" )