zai

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package zai provides a Z.ai GLM API provider implementation for Iris.

Index

Constants

View Source
const (
	// GLM-4.7 series (latest flagship)
	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-4 32B
	ModelGLM4_32B core.ModelID = "glm-4-32b-0414-128k"
)

Model constants for Z.ai GLM models.

View Source
const DefaultBaseURL = "https://api.z.ai/api/coding/paas/v4"

DefaultBaseURL is the default base URL for the Z.ai API (coding endpoint).

Variables

View Source
var ErrToolArgsInvalidJSON = errors.New("tool args invalid json")

ErrToolArgsInvalidJSON is returned when tool call arguments contain invalid JSON.

Functions

func GetModelInfo

func GetModelInfo(id core.ModelID) *core.ModelInfo

GetModelInfo returns the ModelInfo for a given model ID, or nil if not found.

Types

type Config

type Config struct {
	// APIKey is the API key for authentication.
	APIKey string

	// 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 is the request timeout. Zero means no timeout.
	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 WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL sets the base URL for the API.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets a custom HTTP client.

func WithHeaders

func WithHeaders(headers http.Header) Option

WithHeaders sets additional headers to include in requests.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the request timeout.

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 New

func New(apiKey string, opts ...Option) *Zai

New creates a new Z.ai provider with the given API key and options.

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) ID

func (p *Zai) ID() string

ID returns the provider identifier.

func (*Zai) Models

func (p *Zai) Models() []core.ModelInfo

Models returns the list of available models.

func (*Zai) StreamChat

func (p *Zai) StreamChat(ctx context.Context, req *core.ChatRequest) (*core.ChatStream, error)

StreamChat sends a streaming chat request.

func (*Zai) Supports

func (p *Zai) Supports(feature core.Feature) bool

Supports reports whether the provider supports the given feature.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL