llm

package
v0.0.0-...-0557e7d Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	InputTypeSearchDocument = "search_document"
	InputTypeSearchQuery    = "search_query"
)
View Source
const USDToNano = 1_000_000_000

USDToNano converts USD amounts into fixed-point nano-USD integers.

Variables

View Source
var (
	ErrEmbedNotConfigured = errors.New("ai embeddings are not configured")
	ErrLLMNotConfigured   = errors.New("ai llm is not configured")
	ErrNoEmbeddings       = errors.New("ai returned no embeddings")
	ErrNoCompletion       = errors.New("ai returned no completion")
)

Functions

func CostFromUSD

func CostFromUSD(amount float64) int64

CostFromUSD converts an OpenRouter usage.cost value into fixed-point nano-USD.

func IsConfigured

func IsConfigured() bool

IsConfigured reports whether an AI API key is set for the assistant.

Types

type ChatClient

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

ChatClient calls oroute chat completion APIs for a single model tier.

func NewChatClient

func NewChatClient() *ChatClient

NewChatClient returns the chat LLM client loaded from app.ai.llm config.

func (*ChatClient) Complete

func (c *ChatClient) Complete(ctx context.Context, messages []Message) (string, Usage, error)

Complete sends messages using this client's model and returns the reply and usage.

func (*ChatClient) Stream

func (c *ChatClient) Stream(ctx context.Context, messages []Message, onDelta func(string)) (string, Usage, error)

Stream sends messages and calls onDelta with each piece of the reply as it arrives.

type EmbedClient

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

EmbedClient calls oroute embedding APIs.

func NewEmbedClient

func NewEmbedClient() *EmbedClient

NewEmbedClient returns an embedding client loaded from app.ai.embed config.

func (*EmbedClient) EmbedDocuments

func (c *EmbedClient) EmbedDocuments(ctx context.Context, texts []string, opts EmbedOptions) ([][]float64, Usage, error)

EmbedDocuments generates embeddings optimized for indexing documents.

func (*EmbedClient) EmbedQuery

func (c *EmbedClient) EmbedQuery(ctx context.Context, text string, opts EmbedOptions) ([]float64, Usage, error)

EmbedQuery generates an embedding optimized for search queries.

func (*EmbedClient) Generate

func (c *EmbedClient) Generate(ctx context.Context, texts []string, opts ...EmbedOptions) ([][]float64, Usage, error)

Generate generates float embeddings for the given texts.

type EmbedOptions

type EmbedOptions struct {
	InputType  string
	Dimensions int64
}

EmbedOptions configures an embedding request.

type Message

type Message struct {
	Role    string
	Content string
}

Message is a chat message passed to Complete and Stream.

type Usage

type Usage struct {
	PromptTokens int64
	TotalTokens  int64
	Cost         int64
}

Usage is token and cost usage reported by OpenRouter APIs.

Jump to

Keyboard shortcuts

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