glm

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package glm provides GLM (Zhipu AI) provider adapter for the OmniLLM unified interface

Package glm provides GLM (Zhipu AI BigModel) API client implementation. GLM uses an OpenAI-compatible API endpoint.

Package glm provides GLM (Zhipu AI) API types (OpenAI-compatible format)

Index

Constants

View Source
const DefaultBaseURL = "https://open.bigmodel.cn/api/paas/v4"

DefaultBaseURL is the Zhipu AI (GLM) API base URL

Variables

This section is empty.

Functions

func NewProvider

func NewProvider(apiKey, baseURL string, httpClient *http.Client) provider.Provider

NewProvider creates a new GLM provider adapter

Types

type Choice

type Choice struct {
	Index        int     `json:"index"`
	Message      Message `json:"message"`
	FinishReason *string `json:"finish_reason"`
}

Choice represents a completion choice in GLM response

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements GLM API client

func New

func New(apiKey, baseURL string, httpClient *http.Client) *Client

New creates a new GLM client

func (*Client) Close

func (c *Client) Close() error

Close closes the client

func (*Client) CreateCompletion

func (c *Client) CreateCompletion(ctx context.Context, req *Request) (*Response, error)

CreateCompletion creates a chat completion

func (*Client) CreateCompletionStream

func (c *Client) CreateCompletionStream(ctx context.Context, req *Request) (*Stream, error)

CreateCompletionStream creates a streaming chat completion

func (*Client) Name

func (c *Client) Name() string

Name returns the provider name

type DeltaChange

type DeltaChange struct {
	Role    string `json:"role,omitempty"`
	Content string `json:"content,omitempty"`
}

DeltaChange represents the actual content change in a stream

type Message

type Message struct {
	Role    string  `json:"role"`
	Content string  `json:"content"`
	Name    *string `json:"name,omitempty"`
}

Message represents a message in GLM format (OpenAI-compatible)

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider represents the GLM provider adapter

func (*Provider) Close

func (p *Provider) Close() error

Close closes the provider

func (*Provider) CreateChatCompletion

CreateChatCompletion creates a chat completion

func (*Provider) CreateChatCompletionStream

func (p *Provider) CreateChatCompletionStream(ctx context.Context, req *provider.ChatCompletionRequest) (provider.ChatCompletionStream, error)

CreateChatCompletionStream creates a streaming chat completion

func (*Provider) Name

func (p *Provider) Name() string

Name returns the provider name

type Request

type Request struct {
	Model            string    `json:"model"`
	Messages         []Message `json:"messages"`
	MaxTokens        *int      `json:"max_tokens,omitempty"`
	Temperature      *float64  `json:"temperature,omitempty"`
	TopP             *float64  `json:"top_p,omitempty"`
	Stream           *bool     `json:"stream,omitempty"`
	Stop             []string  `json:"stop,omitempty"`
	PresencePenalty  *float64  `json:"presence_penalty,omitempty"`
	FrequencyPenalty *float64  `json:"frequency_penalty,omitempty"`
	Seed             *int      `json:"seed,omitempty"`
}

Request represents a GLM API request (OpenAI-compatible format)

type Response

type Response struct {
	ID      string   `json:"id"`
	Object  string   `json:"object"`
	Created int64    `json:"created"`
	Model   string   `json:"model"`
	Choices []Choice `json:"choices"`
	Usage   Usage    `json:"usage"`
}

Response represents a GLM API response (OpenAI-compatible)

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream implements streaming for GLM

func (*Stream) Close

func (s *Stream) Close() error

Close closes the stream

func (*Stream) Recv

func (s *Stream) Recv() (*StreamChunk, error)

Recv receives the next chunk from the stream

type StreamAdapter

type StreamAdapter struct {
	// contains filtered or unexported fields
}

StreamAdapter adapts GLM stream to unified interface

func (*StreamAdapter) Close

func (s *StreamAdapter) Close() error

Close closes the stream

func (*StreamAdapter) Recv

Recv receives the next chunk from the stream

type StreamChunk

type StreamChunk struct {
	ID      string        `json:"id"`
	Object  string        `json:"object"`
	Created int64         `json:"created"`
	Model   string        `json:"model"`
	Choices []StreamDelta `json:"choices"`
	Usage   *Usage        `json:"usage,omitempty"`
}

StreamChunk represents a chunk in GLM streaming response (OpenAI-compatible)

type StreamDelta

type StreamDelta struct {
	Index        int          `json:"index"`
	Delta        *DeltaChange `json:"delta,omitempty"`
	FinishReason *string      `json:"finish_reason"`
}

StreamDelta represents delta content in a streaming chunk

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

Usage represents token usage in GLM response

Jump to

Keyboard shortcuts

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