Help us shape the future of Go! Take the 2026 Go Developer Survey

zai

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package zai implements ai.Model against Z.AI's OpenAI-compatible Chat Completions API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewProviderConfig

func NewProviderConfig() openai.ProviderConfig

NewProviderConfig returns reusable Z.AI endpoint and environment configuration.

Types

type Model

type Model struct {
	*ai.ModelWrapper
	// contains filtered or unexported fields
}

Model calls Z.AI GLM models and preserves their reasoning across turns.

func NewModel

func NewModel(name string, options ...Option) *Model

NewModel creates a model for a Z.AI GLM model, such as glm-5.3-flash.

func (*Model) Request

func (model *Model) Request(
	ctx context.Context, messages []ai.ModelMessage, params ai.ModelRequestParams,
) (*ai.ModelResponse, error)

Request implements ai.Model.

func (*Model) StreamRequest

func (model *Model) StreamRequest(
	ctx context.Context, messages []ai.ModelMessage, params ai.ModelRequestParams,
) (iter.Seq2[ai.ModelStreamEvent, error], error)

StreamRequest implements ai.StreamingModel.

type Option

type Option func(*config)

Option configures a Z.AI model.

func WithAPIKey

func WithAPIKey(key string) Option

WithAPIKey sets the API key. The default is ZAI_API_KEY.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL points the model at a Z.AI-compatible endpoint.

func WithDefaultSettings

func WithDefaultSettings(settings ai.ModelSettings) Option

WithDefaultSettings sets request defaults overridden by agent and run settings.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets the HTTP client used for requests.

func WithProvider

func WithProvider(provider openai.ProviderConfig) Option

WithProvider configures a gateway while retaining Z.AI request semantics.

type Settings

type Settings struct {
	// Common contains portable generation settings.
	Common ai.ModelSettings
	// ClearThinking controls whether GLM clears retained reasoning before generation.
	ClearThinking *bool
}

Settings combines portable settings with Z.AI-specific settings.

func (Settings) Build

func (settings Settings) Build() (ai.ModelSettings, error)

Build returns detached portable settings accepted by agents and direct requests.

Jump to

Keyboard shortcuts

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