ai

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAvailableModels

func GetAvailableModels(provider Provider) []string

GetAvailableModels returns a list of available models for a given provider

func GetDefaultModel

func GetDefaultModel(provider Provider) string

GetDefaultModel returns the default model for a given provider

func GetSupportedProviders

func GetSupportedProviders() []string

GetSupportedProviders returns a list of supported AI providers

func ValidateProvider

func ValidateProvider(provider string) error

ValidateProvider checks if the provider is supported

Types

type AISummary

type AISummary struct {
	TotalAnalyzed        int `json:"total_analyzed"`
	SuccessfullyAnalyzed int `json:"successfully_analyzed"`
	AnalysisErrors       int `json:"analysis_errors"`
	LikelyFalsePositives int `json:"likely_false_positives"`
	LikelyTruePositives  int `json:"likely_true_positives"`
	HighConfidence       int `json:"high_confidence"`   // >= 0.8
	MediumConfidence     int `json:"medium_confidence"` // >= 0.6 && < 0.8
	LowConfidence        int `json:"low_confidence"`    // < 0.6
}

AISummary provides statistics about AI analysis results

func GetSummary

func GetSummary(enhancedFindings []EnhancedFinding) AISummary

GetSummary returns a summary of AI analysis results

type Analyzer

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

Analyzer handles AI-powered analysis of findings

func NewAnalyzer

func NewAnalyzer(client Client, maxWorkers int, timeout time.Duration) *Analyzer

NewAnalyzer creates a new AI analyzer

func (*Analyzer) AnalyzeFindings

func (a *Analyzer) AnalyzeFindings(ctx context.Context, findings []rules.Finding) ([]EnhancedFinding, error)

AnalyzeFindings analyzes multiple findings using AI

func (*Analyzer) AnalyzeSingleFinding

func (a *Analyzer) AnalyzeSingleFinding(ctx context.Context, finding rules.Finding) (*EnhancedFinding, error)

AnalyzeSingleFinding analyzes a single finding using AI

func (*Analyzer) Close

func (a *Analyzer) Close() error

Close cleans up the analyzer

type ClaudeClient

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

ClaudeClient implements the Client interface for Anthropic Claude API

func NewClaudeClient

func NewClaudeClient(config Config) (*ClaudeClient, error)

NewClaudeClient creates a new Claude client

func (*ClaudeClient) Close

func (c *ClaudeClient) Close() error

Close cleans up resources

func (*ClaudeClient) GetProvider

func (c *ClaudeClient) GetProvider() Provider

GetProvider returns the provider name

func (*ClaudeClient) VerifyFinding

func (c *ClaudeClient) VerifyFinding(ctx context.Context, finding rules.Finding) (*VerificationResult, error)

VerifyFinding analyzes a finding using Claude

type Client

type Client interface {
	// VerifyFinding analyzes a security finding and determines if it's likely a false positive
	VerifyFinding(ctx context.Context, finding rules.Finding) (*VerificationResult, error)

	// GetProvider returns the provider name
	GetProvider() Provider

	// Close cleans up any resources
	Close() error
}

Client interface for AI providers

func NewClient

func NewClient(config Config) (Client, error)

NewClient creates a new AI client based on the provider

type Config

type Config struct {
	Provider Provider `yaml:"provider"`
	APIKey   string   `yaml:"api_key"`
	BaseURL  string   `yaml:"base_url,omitempty"` // Custom endpoint for self-hosted models
	Model    string   `yaml:"model,omitempty"`    // Specific model to use

	// Request configuration
	MaxTokens   int     `yaml:"max_tokens,omitempty"`
	Temperature float64 `yaml:"temperature,omitempty"`
	Timeout     int     `yaml:"timeout,omitempty"` // seconds
}

Config holds configuration for AI clients

type EnhancedFinding

type EnhancedFinding struct {
	rules.Finding
	AIVerification *VerificationResult `json:"ai_verification,omitempty"`
	AIError        string              `json:"ai_error,omitempty"`
}

EnhancedFinding represents a finding enhanced with AI verification

type GeminiClient

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

GeminiClient implements the Client interface for Google Gemini API

func NewGeminiClient

func NewGeminiClient(config Config) (*GeminiClient, error)

NewGeminiClient creates a new Gemini client

func (*GeminiClient) Close

func (c *GeminiClient) Close() error

Close cleans up resources

func (*GeminiClient) GetProvider

func (c *GeminiClient) GetProvider() Provider

GetProvider returns the provider name

func (*GeminiClient) VerifyFinding

func (c *GeminiClient) VerifyFinding(ctx context.Context, finding rules.Finding) (*VerificationResult, error)

VerifyFinding analyzes a finding using Gemini

type GrokClient

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

GrokClient implements the Client interface for xAI Grok API

func NewGrokClient

func NewGrokClient(config Config) (*GrokClient, error)

NewGrokClient creates a new Grok client

func (*GrokClient) Close

func (c *GrokClient) Close() error

Close cleans up resources

func (*GrokClient) GetProvider

func (c *GrokClient) GetProvider() Provider

GetProvider returns the provider name

func (*GrokClient) VerifyFinding

func (c *GrokClient) VerifyFinding(ctx context.Context, finding rules.Finding) (*VerificationResult, error)

VerifyFinding analyzes a finding using Grok

type OpenAIClient

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

OpenAIClient implements the Client interface for OpenAI API

func NewOpenAIClient

func NewOpenAIClient(config Config) (*OpenAIClient, error)

NewOpenAIClient creates a new OpenAI client

func (*OpenAIClient) Close

func (c *OpenAIClient) Close() error

Close cleans up resources

func (*OpenAIClient) GetProvider

func (c *OpenAIClient) GetProvider() Provider

GetProvider returns the provider name

func (*OpenAIClient) VerifyFinding

func (c *OpenAIClient) VerifyFinding(ctx context.Context, finding rules.Finding) (*VerificationResult, error)

VerifyFinding analyzes a finding using OpenAI

type PerplexityClient

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

PerplexityClient implements the Client interface for Perplexity AI API

func NewPerplexityClient

func NewPerplexityClient(config Config) (*PerplexityClient, error)

NewPerplexityClient creates a new Perplexity client

func (*PerplexityClient) Close

func (c *PerplexityClient) Close() error

Close cleans up resources

func (*PerplexityClient) GetProvider

func (c *PerplexityClient) GetProvider() Provider

GetProvider returns the provider name

func (*PerplexityClient) VerifyFinding

func (c *PerplexityClient) VerifyFinding(ctx context.Context, finding rules.Finding) (*VerificationResult, error)

VerifyFinding analyzes a finding using Perplexity

type Provider

type Provider string

Provider represents different AI providers

const (
	ProviderOpenAI     Provider = "openai"
	ProviderGemini     Provider = "gemini"
	ProviderClaude     Provider = "claude"
	ProviderGrok       Provider = "grok"
	ProviderPerplexity Provider = "perplexity"
)

type VerificationResult

type VerificationResult struct {
	IsLikelyFalsePositive bool    `json:"is_likely_false_positive"`
	Confidence            float64 `json:"confidence"` // 0.0 to 1.0
	Reasoning             string  `json:"reasoning"`
	Severity              string  `json:"suggested_severity,omitempty"`
}

VerificationResult represents the AI's assessment of a finding

Jump to

Keyboard shortcuts

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