ai

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 15 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

Index

Constants

View Source
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

View Source
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

func EffectiveBaseURL(provider, baseURL string) string

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 NewClient

func NewClient(cfg Config) *Client

NewClient creates a new AI client from config.

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

func (c *Client) ListModels(ctx context.Context) ([]string, error)

ListModels fetches the list of available models from the API.

func (*Client) Model added in v0.6.0

func (c *Client) Model() string

Model returns the configured model name.

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

type SettingReader interface {
	GetSystemSetting(ctx context.Context, key string) (string, error)
}

SettingReader reads one system setting; an unset key yields "".

type Settings added in v0.6.0

type Settings struct {
	Enabled     bool
	AutoAnalyze bool
	Config      Config
}

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

func LoadSettingsChecked(ctx context.Context, r SettingReader, env Settings) (Settings, error)

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.

func (Settings) NewClient added in v0.6.0

func (s Settings) NewClient() *Client

NewClient returns a client for the settings, or nil when AI is disabled.

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.

Jump to

Keyboard shortcuts

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