Documentation
¶
Overview ¶
Package glm implements llm.Client for Zhipu AI / z.ai GLM models.
GLM is reached over z.ai's Anthropic-compatible endpoint (https://api.z.ai/api/anthropic), so the wire format is identical to the Anthropic Messages API: the request/response shapes, content blocks, image blocks, thinking blocks, and SSE stream are the same as pkg/llm/claude. This package is a self-contained copy of that engine (per evva's one-package-per-provider convention) with three deltas:
- auth header is "Authorization: Bearer <key>" (z.ai's ANTHROPIC_AUTH_TOKEN scheme) instead of Anthropic's "x-api-key";
- the provider name / default model are GLM's;
- effort is documented against GLM-5.2's two thinking-effort tiers, which z.ai derives from the same output_config.effort value.
Because the image-block path is copied verbatim, the read-file tool's image results (pkg/tools/fs/read.go) are forwarded to GLM as base64 image blocks with no extra wiring; image understanding requires a vision-capable GLM model.
Index ¶
- Constants
- func Factory(cfg llm.APIConfig, model string, opts ...llm.Option) (llm.Client, error)
- type Client
- func (c *Client) Apply(opts ...llm.Option)
- func (c *Client) Complete(ctx context.Context, messages []llm.Message, toolSet []tools.Tool) (llm.Response, error)
- func (c *Client) Model() string
- func (c *Client) Name() string
- func (c *Client) SetModel(m string)
- func (c *Client) Stream(ctx context.Context, messages []llm.Message, toolSet []tools.Tool, ...) (llm.Response, error)
- func (c *Client) SupportsDeferLoading() bool
Constants ¶
const ( DefaultModel = "glm-5.2" DefaultMaxTokens = 4096 )
const ProviderName = "glm"
ProviderName is the registry key under which this client registers. It matches the Name field of constant.GLM. Registered into pkg/llm.DefaultRegistry() by pkg/llm/builtins.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements llm.Client backed by z.ai's Anthropic-compatible Messages API.
func New ¶
New builds a GLM client from provider config and applies the given options. Options can be re-applied at runtime via Apply.
func (*Client) Stream ¶
func (c *Client) Stream(ctx context.Context, messages []llm.Message, toolSet []tools.Tool, sink llm.ChunkSink) (llm.Response, error)
Stream is the chunked variant of Complete. It opens an SSE connection to z.ai's Anthropic-compatible /v1/messages endpoint with "stream": true, parses each event, emits text/thinking deltas through sink as they arrive, and returns the fully assembled Response when the server emits message_stop.
The stream protocol is the Anthropic per-content-block shape:
- message_start carries the request id, model, and initial usage stats.
- content_block_start opens a block of type text | thinking | tool_use.
- content_block_delta carries incremental data (text/thinking/signature/ input_json deltas).
- content_block_stop closes the block.
- message_delta updates the final usage.output_tokens.
- message_stop is the terminator; ping events are keepalives we ignore; error events abort with the server's reason.
The thinking signature is opaque and never streamed to the chunk sink — it ships back verbatim on the next assistant turn (llm.Message.ThinkingSignature).
func (*Client) SupportsDeferLoading ¶
SupportsDeferLoading currently returns false; mirrors pkg/llm/claude.