Documentation
¶
Overview ¶
Package zai provides a Z.ai GLM API provider implementation for Iris.
Index ¶
- Constants
- Variables
- func GetModelInfo(id core.ModelID) *core.ModelInfo
- type Config
- type Option
- type Zai
- func (p *Zai) Chat(ctx context.Context, req *core.ChatRequest) (*core.ChatResponse, error)
- func (p *Zai) ID() string
- func (p *Zai) Models() []core.ModelInfo
- func (p *Zai) StreamChat(ctx context.Context, req *core.ChatRequest) (*core.ChatStream, error)
- func (p *Zai) Supports(feature core.Feature) bool
Constants ¶
const ( // GLM-5 series (latest) ModelGLM52 core.ModelID = "glm-5.2" ModelGLM51 core.ModelID = "glm-5.1" ModelGLM5 core.ModelID = "glm-5" ModelGLM5Turbo core.ModelID = "glm-5-turbo" ModelGLM5VTurbo core.ModelID = "glm-5v-turbo" // GLM-4.7 series ModelGLM47 core.ModelID = "glm-4.7" ModelGLM47Flash core.ModelID = "glm-4.7-flash" ModelGLM47FlashX core.ModelID = "glm-4.7-flashx" // GLM-4.6 series ModelGLM46 core.ModelID = "glm-4.6" ModelGLM46V core.ModelID = "glm-4.6v" ModelGLM46VFlash core.ModelID = "glm-4.6v-flash" ModelGLM46VFlashX core.ModelID = "glm-4.6v-flashx" // GLM-4.5 series ModelGLM45 core.ModelID = "glm-4.5" ModelGLM45V core.ModelID = "glm-4.5v" ModelGLM45X core.ModelID = "glm-4.5-x" ModelGLM45Air core.ModelID = "glm-4.5-air" ModelGLM45AirX core.ModelID = "glm-4.5-airx" ModelGLM45Flash core.ModelID = "glm-4.5-flash" // GLM Specialized ModelGLMForCoding core.ModelID = "glm-for-coding" // GLM-4 32B ModelGLM4_32B core.ModelID = "glm-4-32b-0414-128k" )
Model constants for Z.ai GLM models.
const DefaultAPIKeyEnvVar = "ZAI_API_KEY"
DefaultAPIKeyEnvVar is the environment variable name for the Z.ai API key.
const DefaultBaseURL = "https://api.z.ai/api/coding/paas/v4"
DefaultBaseURL is the default base URL for the Z.ai API (coding endpoint).
Variables ¶
var ErrAPIKeyNotFound = errors.New("zai: ZAI_API_KEY environment variable not set")
ErrAPIKeyNotFound is returned when the API key environment variable is not set.
var ErrToolArgsInvalidJSON = errors.New("tool args invalid json")
ErrToolArgsInvalidJSON is returned when tool call arguments contain invalid JSON.
Functions ¶
func GetModelInfo ¶
GetModelInfo returns a copy of the ModelInfo for a given model ID, or nil if not found. The returned pointer references a fresh copy whose fields (including the Capabilities slice) do not alias the package's static catalog, so mutating it cannot affect subsequent GetModelInfo or Models calls.
Types ¶
type Config ¶
type Config struct {
// APIKey is the API key for authentication.
// Stored as Secret to prevent accidental logging.
APIKey core.Secret
// BaseURL is the base URL for the API. Defaults to DefaultBaseURL.
BaseURL string
// HTTPClient is the HTTP client to use for requests.
HTTPClient *http.Client
// Headers are additional headers to include in requests.
Headers http.Header
// Timeout sets the timeout for this provider's direct (non-chat)
// operations — embeddings, files, images, batch, and vector stores.
// Chat and streaming honor core.WithTimeout and context deadlines.
Timeout time.Duration
}
Config holds the configuration for the Z.ai provider.
type Option ¶
type Option func(*Config)
Option is a functional option for configuring the Z.ai provider.
func WithAPIKey ¶ added in v0.17.0
WithAPIKey sets the API key, overriding any value passed to New.
func WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client.
func WithHeader ¶ added in v1.0.0
WithHeader adds an extra header to include in requests.
func WithHeaders ¶
WithHeaders sets additional headers to include in requests.
func WithTimeout ¶
WithTimeout sets the timeout for this provider's direct (non-chat) operations — embeddings, files, images, batch, and vector stores. Chat and streaming honor core.WithTimeout and context deadlines.
type Zai ¶
type Zai struct {
// contains filtered or unexported fields
}
Zai is an LLM provider implementation for the Z.ai GLM API. Zai is safe for concurrent use.
func NewFromEnv ¶ added in v0.10.0
NewFromEnv creates a new Z.ai provider using the ZAI_API_KEY environment variable. This is a convenience factory for quick setup:
provider, err := zai.NewFromEnv()
if err != nil {
log.Fatal(err)
}
client := core.NewClient(provider)
func (*Zai) Chat ¶
func (p *Zai) Chat(ctx context.Context, req *core.ChatRequest) (*core.ChatResponse, error)
Chat sends a non-streaming chat request.
func (*Zai) StreamChat ¶
func (p *Zai) StreamChat(ctx context.Context, req *core.ChatRequest) (*core.ChatStream, error)
StreamChat sends a streaming chat request.