llm

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 9 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 holds what the provider adapters (openai, anthropic, bedrock) share: request configuration, a classified error type, and the HTTP call that turns a raw response into one of them. Each provider package still owns its own request/response shapes, since those differ per API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnalyzerErrorKind

func AnalyzerErrorKind(err error) string

AnalyzerErrorKind maps a provider error to the AnalyzerError kind vocabulary used across the scanner (config | network | timeout | parse | internal | policy | unavailable)

func Do

func Do(ctx context.Context, client *http.Client, req *http.Request, provider string) ([]byte, error)

Do sends req and classifies the outcome. On a 2xx status it returns the response body; otherwise it returns a *Error and no body, so callers never have to re-derive the error kind from a status code themselves.

Types

type Config

type Config struct {
	Model     string
	BaseURL   string
	APIKeyEnv string
	MaxTokens int
	Timeout   time.Duration
	// AllowInsecureEndpoint permits a plain http:// BaseURL. Off by
	// default: every request to BaseURL carries the API key, and for a
	// source/package scan, part of the scanned content, so a plaintext
	// endpoint sends both where anything on the path can read them. Set
	// from internal/config.LLMConfig.AllowInsecureEndpoint by
	// internal/app.BuildLLMClient - see CheckBaseURL.
	AllowInsecureEndpoint bool
	HTTPClient            *http.Client // overridden in tests
}

Config configures a provider client. BaseURL overrides the provider's default endpoint; tests point it at an httptest.Server. APIKeyEnv is the environment variable name holding the credential - never the credential itself, so a Config can be logged or stored without leaking a secret.

func (Config) CheckBaseURL

func (c Config) CheckBaseURL(base string) error

CheckBaseURL rejects base if it is not HTTPS unless AllowInsecureEndpoint is set. A caller that supplies its own HTTP client owns that transport choice, which also permits local test servers.

func (Config) Client

func (c Config) Client() *http.Client

Client returns the HTTP client to use, applying the configured timeout when the caller did not supply one. Configured model gateways may intentionally be private, so this client opts into private destinations explicitly rather than weakening the package-wide default policy.

type Error

type Error struct {
	Provider   string
	Kind       ErrorKind
	Message    string
	StatusCode int
	RetryAfter time.Duration
}

Error is a provider failure. Message is built from status codes and response shape only - never from request headers - so it can never carry the API key.

func (*Error) Error

func (e *Error) Error() string

type ErrorKind

type ErrorKind string

ErrorKind classifies a provider failure so analyzers can react to the kind without parsing message text

const (
	ErrTimeout   ErrorKind = "timeout"
	ErrRateLimit ErrorKind = "rate_limited"
	ErrMalformed ErrorKind = "malformed_response"
	ErrAuth      ErrorKind = "auth"
	ErrProvider  ErrorKind = "provider"
)

Directories

Path Synopsis
Package anthropic implements analyzer.LLMClient with the Anthropic Messages API
Package anthropic implements analyzer.LLMClient with the Anthropic Messages API
Package bedrock implements analyzer.LLMClient against Anthropic Claude models hosted on AWS Bedrock, calling bedrock-runtime InvokeModel directly over net/http with a hand-rolled SigV4 signature
Package bedrock implements analyzer.LLMClient against Anthropic Claude models hosted on AWS Bedrock, calling bedrock-runtime InvokeModel directly over net/http with a hand-rolled SigV4 signature
Package openai implements analyzer.LLMClient against the OpenAI chat completions API
Package openai implements analyzer.LLMClient against the OpenAI chat completions API

Jump to

Keyboard shortcuts

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