Documentation
¶
Overview ¶
Package zai provides a Genkit plugin for Z.ai's GLM 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 GLM 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(zai.ModelRef("glm-5", &zai.ChatConfig{
Thinking: &zai.ThinkingConfig{Type: "enabled"},
}))
id is the model ID, with or without the provider prefix.
Types ¶
type ChatConfig ¶
type ChatConfig struct {
compat_oai.RequestConfig
// Temperature controls the degree of randomness in token selection, from
// 0 to 1; the default varies by model.
Temperature *float64 `` /* 182-byte string literal not displayed */
// TopP is the nucleus sampling threshold, from 0.01 to 1.
TopP *float64 `` /* 126-byte string literal not displayed */
// MaxOutputTokens is the maximum number of tokens to generate, sent as the
// API's max_tokens; Z.ai documents up to 131072.
MaxOutputTokens int `` /* 181-byte string literal not displayed */
// StopSequences stop generation when produced by the model, up to four.
StopSequences []string `` /* 145-byte string literal not displayed */
// Thinking controls the chain-of-thought mode of GLM 4.5 and later
// models, sent as the API's thinking field.
Thinking *ThinkingConfig `` /* 140-byte string literal not displayed */
// DoSample turns sampling off when set to false, making temperature and
// TopP inert; sent as the API's do_sample.
DoSample *bool `` /* 145-byte string literal not displayed */
}
ChatConfig is the per-request config for GLM models: the generation fields Z.ai accepts plus the Z.ai-specific controls. See https://docs.z.ai/api-reference/llm/chat-completion.
Z.ai documents no penalties, log probabilities, or seed, so those are deliberately absent, and its temperature range stops at 1 rather than the 2 OpenAI allows.
func (ChatConfig) ApplyToChatCompletion ¶
func (c ChatConfig) ApplyToChatCompletion(params *openai.ChatCompletionNewParams)
ApplyToChatCompletion implements compat_oai.ChatConfig: the generation fields land on their chat completion counterparts and the Z.ai controls ride as extra request fields.
type ThinkingConfig ¶
type ThinkingConfig struct {
// Type turns thinking [ThinkingTypeEnabled] (the default) or
// [ThinkingTypeDisabled].
Type ThinkingType `` /* 136-byte string literal not displayed */
// ClearThinking controls whether the reasoning content is cleared from
// the response, sent as the API's clear_thinking; Z.ai defaults it to
// true.
ClearThinking *bool `` /* 167-byte string literal not displayed */
}
ThinkingConfig configures the chain-of-thought mode of GLM models.
type ThinkingType ¶
type ThinkingType string
ThinkingType turns the chain-of-thought of GLM models on or off.
const ( // ThinkingTypeEnabled turns thinking on, which is Z.ai's default. ThinkingTypeEnabled ThinkingType = "enabled" // ThinkingTypeDisabled turns thinking off. ThinkingTypeDisabled ThinkingType = "disabled" )
type ZAI ¶
type ZAI struct {
// APIKey is the Z.ai API key. If empty, ZAI_API_KEY is consulted.
APIKey string
// Opts contains additional OpenAI client request options, such as
// [option.WithBaseURL] for a different endpoint (ZAI_BASE_URL works 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 GLM model, keyed by
// model ID, bare or provider-prefixed. Every GLM model already works
// without an entry: known IDs carry curated capabilities and the rest take
// the GLM 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.
//
// &zai.ZAI{Models: map[string]ai.ModelOptions{
// "glm-5.1": {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 [ZAI.ListActions] advertises and [ZAI.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
}
ZAI configures the Z.ai GLM plugin.
func (*ZAI) ListActions ¶
func (z *ZAI) ListActions(ctx context.Context) []api.ActionDesc
ListActions lists the models the configured Z.ai endpoint exposes, described by the plugin's config schema and capabilities.
func (*ZAI) ResolveAction ¶
ResolveAction dynamically builds a model exposed by the Z.ai endpoint, described by the plugin's config schema and capabilities.