Documentation
¶
Index ¶
Constants ¶
const ( SettingEnabled = "ai.enabled" SettingAutoAnalyze = "ai.auto_analyze" SettingProvider = "ai.provider" SettingBaseURL = "ai.base_url" SettingAPIKey = "ai.api_key" SettingModel = "ai.model" SettingMaxTokens = "ai.max_tokens" SettingTimeoutSecs = "ai.timeout_secs" SettingSystemPrompt = "ai.system_prompt" )
System setting keys written by the admin API.
Variables ¶
var ErrAPIKeyUndecryptable = errors.New("ai api key cannot be decrypted")
ErrAPIKeyUndecryptable is returned by every request of a client whose stored API key could not be decrypted (the secret key changed or is not set). The request is not sent: the stored ciphertext is never a usable bearer token.
Functions ¶
func EffectiveBaseURL ¶ added in v0.15.0
EffectiveBaseURL is the endpoint a client for provider and baseURL talks to, without a trailing slash: baseURL itself, or the provider's default when it is empty (none for azure and custom, which need an explicit one).
Types ¶
type AnalysisResult ¶
type AnalysisResult struct {
ArtifactSummary string `json:"artifact_summary"`
Tags []string `json:"tags"`
LicenseStatus string `json:"license_status"`
LicenseName string `json:"license_name"`
SecurityNotes string `json:"security_notes"`
QuarantineRecommended bool `json:"quarantine_recommended"`
}
AnalysisResult is the structured JSON the LLM must return.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an OpenAI-compatible LLM client.
func (*Client) Analyze ¶
func (c *Client) Analyze(ctx context.Context, manifestText string) (*AnalysisResult, *UsageInfo, error)
Analyze sends manifest text to the LLM and returns structured analysis.
func (*Client) ListModels ¶
ListModels fetches the list of available models from the API.
type Config ¶
type Config struct {
Provider string // "openai", "azure", "ollama", "custom" (any OpenAI-compatible endpoint; BaseURL required)
BaseURL string // override endpoint
APIKey string
Model string
MaxTokens int
TimeoutSecs int
SystemPrompt string
}
Config holds AI client configuration.
type SettingReader ¶ added in v0.6.0
SettingReader reads one system setting; an unset key yields "".
type Settings ¶ added in v0.6.0
Settings is the effective AI configuration: whether analysis runs, whether uploads are analysed unattended, and how to reach the model.
func LoadSettings ¶ added in v0.6.0
func LoadSettings(ctx context.Context, r SettingReader, env Settings) Settings
LoadSettings merges the stored system settings over env (the env/YAML values). Once ai.enabled has been saved the database decides Enabled and every other field uses the stored value when non-empty, falling back to env otherwise; without a saved ai.enabled the env values apply as they are. ai.auto_analyze is independent: the stored value wins whenever it is set.
func LoadSettingsChecked ¶ added in v0.15.0
LoadSettingsChecked is LoadSettings for a caller that must not act on a partial read: LoadSettings reads a key it cannot fetch as unset, so during a database outage it answers with the env values. LoadSettingsChecked returns the first read error as well, and the settings it returns are then not the saved ones.
type UsageInfo ¶
type UsageInfo struct {
PromptTokens int
CompletionTokens int
// Model is the model the provider reports having served the request
// (e.g. a dated snapshot), or the configured model when it reports none.
Model string
}
UsageInfo holds token usage and the serving model from the API response.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package manifest extracts the plain-text package manifest (package.json, METADATA, a .pom, a deb control file, ...) from a stored artifact so it can be sent to the AI analysis model.
|
Package manifest extracts the plain-text package manifest (package.json, METADATA, a .pom, a deb control file, ...) from a stored artifact so it can be sent to the AI analysis model. |