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 ¶
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 ¶
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.
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.
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 |