llm

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 10 Imported by: 0 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

Overview

Package llm provides a minimal OpenAI-compatible chat completions client for executing map, filter, and reduce calls.

Index

Constants

View Source
const (
	// DefaultBaseURL is used when no custom OpenAI-compatible endpoint is set.
	DefaultBaseURL = "https://openrouter.ai/api/v1"
	// DefaultTimeout is the per-request HTTP timeout.
	DefaultTimeout = 90 * time.Second
)

Variables

This section is empty.

Functions

func EstimateTokens

func EstimateTokens(s string) int

EstimateTokens approximates token count (~4 bytes per token) for budgeting.

func IsRetryable

func IsRetryable(err error) bool

IsRetryable reports whether err is transient (429, 5xx, or network timeout).

Types

type APIError

type APIError struct {
	StatusCode int
	Body       string
}

APIError represents an HTTP error returned by the completions endpoint.

func (*APIError) Error

func (e *APIError) Error() string

type Client

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

Client calls an OpenAI-compatible /chat/completions endpoint.

func NewClient

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

NewClient constructs a Client targeting baseURL (defaults to DefaultBaseURL).

func (*Client) Complete

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

Complete sends a chat completion request and returns the first choice text.

type Request

type Request struct {
	Model    string
	System   string
	Prompt   string
	JSONMode bool
}

Request configures a single chat completion call.

type Response

type Response struct {
	Text             string
	PromptTokens     int
	CompletionTokens int
}

Response holds the assistant text and reported token usage.

type Runner

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

Runner executes prompts via any external CLI command reading the prompt from stdin and returning stdout.

func NewRunner

func NewRunner(command string) (*Runner, error)

NewRunner parses command into an executable and base arguments.

func (*Runner) Complete

func (r *Runner) Complete(ctx context.Context, req Request) (Response, error)

Complete runs the configured CLI command with req.Prompt on stdin.

type RunnerError

type RunnerError struct {
	Command string
	Err     error
	Output  string
}

RunnerError represents a non-zero exit or launch failure from a CLI runner.

func (*RunnerError) Error

func (e *RunnerError) Error() string

func (*RunnerError) Unwrap

func (e *RunnerError) Unwrap() error

Jump to

Keyboard shortcuts

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