llm

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package llm provides local large language model clients. The Ollama client talks to a local Ollama server, so under the default policy no data leaves the machine.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyResponse = errors.New("llm: empty response")

ErrEmptyResponse indicates the model returned no content.

View Source
var ErrModel = errors.New("llm: model error")

ErrModel indicates the Ollama server is unreachable or reported an error.

Functions

This section is empty.

Types

type Anthropic added in v0.1.17

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

Anthropic is a minimal Claude Messages API client. It exists for the explicitly opted-in cloud path: the caller is responsible for checking the egress policy and redacting the payload before any call. The API key is never logged and travels only in the request header.

func NewAnthropic added in v0.1.17

func NewAnthropic(apiKey string, opts ...AnthropicOption) *Anthropic

NewAnthropic returns a Claude client. It panics on an empty key: the caller must have read it from the environment before constructing the client.

func (*Anthropic) Chat added in v0.1.17

func (a *Anthropic) Chat(ctx context.Context, system, user string) (string, error)

Chat sends the system and user prompts to Claude and returns the text reply.

type AnthropicOption added in v0.1.17

type AnthropicOption func(*Anthropic)

AnthropicOption configures the client.

func WithAnthropicBaseURL added in v0.1.17

func WithAnthropicBaseURL(u string) AnthropicOption

WithAnthropicBaseURL overrides the API root, mainly for tests.

func WithAnthropicModel added in v0.1.17

func WithAnthropicModel(model string) AnthropicOption

WithAnthropicModel overrides the default model.

type Doer

type Doer interface {
	// Do performs the request and returns the response.
	Do(req *http.Request) (*http.Response, error)
}

Doer performs an HTTP request. *http.Client satisfies it; tests inject a stub.

type Ollama

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

Ollama calls a local Ollama chat model.

func New

func New(model string, opts ...Option) *Ollama

New returns an Ollama client for model, defaulting the model when empty.

func (*Ollama) Chat

func (o *Ollama) Chat(ctx context.Context, system, user string) (string, error)

Chat sends a system and user message and returns the assistant content. It requests a JSON-formatted reply.

func (*Ollama) Embed

func (o *Ollama) Embed(ctx context.Context, text string) ([]float32, error)

Embed returns the embedding vector for text using the configured embed model.

type OpenAI added in v0.1.17

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

OpenAI is a minimal chat-completions client. The wire format is the de facto standard spoken by OpenAI and by local servers like LM Studio, llamafile, and vLLM, so one client covers them all via the base URL. It exists for the explicitly opted-in cloud path: the caller is responsible for checking the egress policy and redacting the payload before any call. The API key is never logged and travels only in the request header.

func NewOpenAI added in v0.1.17

func NewOpenAI(apiKey string, opts ...OpenAIOption) *OpenAI

NewOpenAI returns an OpenAI-compatible client. The key may be empty when the server does not require one, as local servers usually do not.

func (*OpenAI) Chat added in v0.1.17

func (o *OpenAI) Chat(ctx context.Context, system, user string) (string, error)

Chat sends the system and user prompts and returns the text reply.

type OpenAIOption added in v0.1.17

type OpenAIOption func(*OpenAI)

OpenAIOption configures the client.

func WithOpenAIBaseURL added in v0.1.17

func WithOpenAIBaseURL(u string) OpenAIOption

WithOpenAIBaseURL points the client at a compatible server, such as a local LM Studio or vLLM instance.

func WithOpenAIModel added in v0.1.17

func WithOpenAIModel(model string) OpenAIOption

WithOpenAIModel overrides the default model.

type Option

type Option func(*Ollama)

Option configures an Ollama client.

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL overrides the server address.

func WithEmbedModel

func WithEmbedModel(name string) Option

WithEmbedModel overrides the embedding model.

func WithHTTPClient

func WithHTTPClient(d Doer) Option

WithHTTPClient sets the HTTP doer.

Jump to

Keyboard shortcuts

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