Documentation
¶
Overview ¶
Package zhipu exposes Zhipu AI chat and embedding adapters. NewChat targets its OpenAI-compatible endpoint; NewMessages targets its Anthropic-compatible endpoint.
GLM's OpenAI-compatible endpoint documents a narrower temperature range than OpenAI's: "temperature 参数的区间为 (0,1),do_sample = False (temperature = 0) 在 OpenAI 调用中并不适用". The endpoint is not documented as clamping an out-of-range value, so nothing is refused here on its behalf — but Core's wider range is not all usable there, and 0 in particular does not mean what it means on OpenAI.
Index ¶
Constants ¶
const ( OpenAIRequestExtensionKey = "zhipu/openai_request" OpenAIResponseExtensionKey = "zhipu/openai_response" OpenAIStreamChunkExtensionKey = "zhipu/openai_stream_chunk" AnthropicRequestExtensionKey = "zhipu/anthropic_request" AnthropicResponseExtensionKey = "zhipu/anthropic_response" AnthropicStreamEventExtensionKey = "zhipu/anthropic_stream_event" )
Namespacing preserves provider-specific data without promoting it into the shared Core protocol or colliding with another provider.
const ( // BaseURL is the BigModel v4 OpenAI-compatible endpoint. BaseURL = "https://open.bigmodel.cn/api/paas/v4" // BaseURLAnthropic is the Anthropic-compatible endpoint Zhipu // exposes for GLM-4.5 / GLM-4.6. The anthropic-sdk-go client // appends "v1/messages" so the full URL resolves to // https://open.bigmodel.cn/api/anthropic/v1/messages. BaseURLAnthropic = "https://open.bigmodel.cn/api/anthropic" )
const ( ModelGLM52 = "glm-5.2" ModelGLM5Turbo = "glm-5-turbo" ModelGLM47 = "glm-4.7" ModelGLM47FlashX = "glm-4.7-flashx" )
Current chat model ids. See https://docs.bigmodel.cn/cn/guide/start/model-overview.
const ( // ModelEmbedding3 produces 2048-dim vectors by default; the // output_dimension parameter (passed through embedding.Options.Dimensions) // can truncate down to 256 / 512 / 1024. ModelEmbedding3 = "embedding-3" )
Embedding model ids.
const (
Provider = "Zhipu"
)
Provider is the stable backend name for host-side attribution.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chat ¶ added in v0.13.0
type Chat = openai.ChatCompletions
Chat implements Zhipu's OpenAI-compatible endpoint.
type ChatConfig ¶ added in v0.13.0
type ChatConfig struct {
APIKey string
DefaultOptions corechat.Options
BaseURL string
HTTPClient *http.Client
}
ChatConfig binds provider access and defaults shared by every chat call.
func (ChatConfig) Validate ¶ added in v0.13.0
func (c ChatConfig) Validate() error
type EmbeddingModel ¶
type EmbeddingModel = openai.EmbeddingModel
EmbeddingModel is the shared protocol type itself rather than a wrapper, so this provider adds no second public surface for callers to choose between.
func NewEmbeddingModel ¶
func NewEmbeddingModel(ctx context.Context, config EmbeddingModelConfig) (*EmbeddingModel, error)
NewEmbeddingModel rejects an invalid provider binding before the first embedding call.
type EmbeddingModelConfig ¶
type EmbeddingModelConfig struct {
APIKey string
DefaultOptions embedding.Options
BaseURL string
HTTPClient *http.Client
}
EmbeddingModelConfig binds provider access and defaults shared by every embedding call.
func (EmbeddingModelConfig) Validate ¶
func (e EmbeddingModelConfig) Validate() error
type Messages ¶ added in v0.13.0
Messages implements Zhipu's Anthropic-compatible endpoint.
func NewMessages ¶ added in v0.13.0
func NewMessages(ctx context.Context, config MessagesConfig) (*Messages, error)
NewMessages rejects an invalid provider binding before the first Messages call.
type MessagesConfig ¶ added in v0.13.0
type MessagesConfig struct {
APIKey string
DefaultOptions corechat.Options
BaseURL string
HTTPClient *http.Client
}
MessagesConfig binds provider access and defaults shared by every Messages call.
func (MessagesConfig) Validate ¶ added in v0.13.0
func (m MessagesConfig) Validate() error