llmclient

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL string
	APIKey  string
}

Client targets one OpenAI-compatible chat-completions provider. BaseURL is the API root (no trailing slash), e.g. "https://api.groq.com/openai/v1" or a self-hosted vLLM endpoint. APIKey is sent as a bearer token; empty means the endpoint needs no auth (local servers).

func (Client) CompleteRaw

func (c Client) CompleteRaw(
	ctx context.Context,
	model string,
	messages []Message,
	tools []ToolDef,
	maxTokens int,
) (Message, Usage, error)

CompleteRaw runs a non-streaming completion with optional tools and returns the full assistant message. When the model wants tools, the returned message's ToolCalls is non-empty and Content is usually blank.

func (Client) CompleteWithUsage

func (c Client) CompleteWithUsage(
	ctx context.Context,
	model string,
	messages []Message,
	maxTokens int,
) (string, Usage, error)

CompleteWithUsage runs a non-streaming completion and returns the assistant text plus token usage.

func (Client) FetchModels

func (c Client) FetchModels() ([]ModelEntry, error)

FetchModels returns all chat-capable models from the provider.

func (Client) Stream

func (c Client) Stream(
	ctx context.Context,
	model string,
	messages []Message,
	maxTokens int,
) (<-chan string, <-chan Usage, <-chan error)

Stream runs a streaming completion (no tools) and returns the content token channel, a usage channel, and an error channel.

type Message

type Message struct {
	Role       string     `json:"role"`
	Content    string     `json:"content"`
	ToolCalls  []ToolCall `json:"tool_calls,omitempty"`
	ToolCallID string     `json:"tool_call_id,omitempty"`
	Name       string     `json:"name,omitempty"`
}

Message is one chat message. ToolCalls is populated on an assistant message that requested tools; ToolCallID + Name tag a tool-result message sent back to the model.

type ModelEntry

type ModelEntry struct {
	ID                  string `json:"id"`
	OwnedBy             string `json:"owned_by"`
	ContextWindow       int    `json:"context_window"`
	MaxCompletionTokens int    `json:"max_completion_tokens"`
}

type RateLimitError

type RateLimitError struct {
	RetrySeconds int
	Raw          string
}

RateLimitError is returned when the provider responds with 429.

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

type ToolCall

type ToolCall struct {
	ID       string           `json:"id"`
	Type     string           `json:"type"`
	Function ToolCallFunction `json:"function"`
}

ToolCall is a tool invocation the model asked for.

type ToolCallFunction

type ToolCallFunction struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

type ToolDef

type ToolDef struct {
	Type     string       `json:"type"`
	Function ToolFunction `json:"function"`
}

ToolDef is a tool offered to the model in a request.

type ToolFunction

type ToolFunction struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	Parameters  json.RawMessage `json:"parameters"`
}

type Usage

type Usage struct {
	PromptTokens     int    `json:"prompt_tokens"`
	CompletionTokens int    `json:"completion_tokens"`
	FinishReason     string `json:"-"`
}

Jump to

Keyboard shortcuts

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