ai

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package ai provides AI integration for embeddings and LLM.

Package ai provides provider-neutral AI integration for embeddings and LLM.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DuplicateCheckInput

type DuplicateCheckInput struct {
	CurrentIssue  *IssueInput
	SimilarIssues []SimilarIssueInput
}

DuplicateCheckInput represents input for duplicate detection.

type DuplicateResult

type DuplicateResult struct {
	IsDuplicate   bool              `json:"is_duplicate"`
	DuplicateOf   int               `json:"duplicate_of"` // Issue number
	Confidence    float64           `json:"confidence"`   // 0.0-1.0
	Reasoning     string            `json:"reasoning"`
	RelatedIssues []RelatedIssueRef `json:"related_issues"` // LLM classification of all candidates
}

DuplicateResult holds duplicate detection analysis.

type Embedder

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

Embedder generates embeddings using Gemini or OpenAI.

func NewEmbedder

func NewEmbedder(apiKey, model string) (*Embedder, error)

NewEmbedder creates a new embedder.

func (*Embedder) Close

func (e *Embedder) Close() error

Close closes underlying provider clients.

func (*Embedder) Dimensions

func (e *Embedder) Dimensions() int

Dimensions returns the dimensionality of the embeddings.

func (*Embedder) Embed

func (e *Embedder) Embed(ctx context.Context, text string) ([]float32, error)

Embed generates an embedding for a single text. It retries on transient errors (429/5xx) with exponential backoff.

func (*Embedder) EmbedBatch

func (e *Embedder) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)

EmbedBatch generates embeddings for multiple texts in parallel. It uses up to maxBatchConcurrency concurrent requests to the embedding API.

func (*Embedder) Model

func (e *Embedder) Model() string

Model returns the resolved model.

func (*Embedder) Provider

func (e *Embedder) Provider() string

Provider returns the resolved provider.

type ExplainTransferInput

type ExplainTransferInput struct {
	IssueTitle    string
	IssueBody     string
	TargetRepo    string
	SimilarIssues []SimilarIssueInput // From target repo
}

ExplainTransferInput holds the data needed to generate a transfer explanation.

type IssueInput

type IssueInput struct {
	Title  string
	Body   string
	Author string
	Labels []string
}

IssueInput represents the issue data needed for analysis.

type LLMClient

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

LLMClient provides LLM-based analysis using Gemini or OpenAI.

func NewLLMClient

func NewLLMClient(apiKey string, model ...string) (*LLMClient, error)

NewLLMClient creates a new LLM client.

func (*LLMClient) AnalyzeIssue

func (l *LLMClient) AnalyzeIssue(ctx context.Context, issue *IssueInput) (*TriageResult, error)

AnalyzeIssue performs triage analysis on an issue. It retries on transient errors (429/5xx) with exponential backoff.

func (*LLMClient) AssessQuality

func (l *LLMClient) AssessQuality(ctx context.Context, issue *IssueInput) (*QualityResult, error)

AssessQuality evaluates issue completeness and clarity. It retries on transient errors (429/5xx) with exponential backoff.

func (*LLMClient) Close

func (l *LLMClient) Close() error

Close closes underlying provider clients.

func (*LLMClient) DetectDuplicate

func (l *LLMClient) DetectDuplicate(ctx context.Context, input *DuplicateCheckInput) (*DuplicateResult, error)

DetectDuplicate analyzes semantic similarity for duplicate detection. It retries on transient errors (429/5xx) with exponential backoff.

func (*LLMClient) ExplainTransfer

func (l *LLMClient) ExplainTransfer(ctx context.Context, input *ExplainTransferInput) (string, error)

ExplainTransfer generates a brief explanation of why an issue should be transferred.

func (*LLMClient) GenerateResponse

func (l *LLMClient) GenerateResponse(ctx context.Context, similar []SimilarIssueInput) (string, error)

GenerateResponse creates a comment for similar issues. It retries on transient errors (429/5xx) with exponential backoff.

func (*LLMClient) Model

func (l *LLMClient) Model() string

Model returns the resolved model.

func (*LLMClient) Provider

func (l *LLMClient) Provider() string

Provider returns the resolved provider.

func (*LLMClient) RouteIssue

func (l *LLMClient) RouteIssue(ctx context.Context, input *RouteIssueInput) (*RouterResult, error)

RouteIssue analyzes issue intent and ranks repositories by relevance. It retries on transient errors (429/5xx) with exponential backoff.

type Provider

type Provider string

Provider identifies the active AI provider.

const (
	ProviderGemini Provider = "gemini"
	ProviderOpenAI Provider = "openai"
)

func ResolveProvider

func ResolveProvider(apiKey string) (Provider, string, error)

ResolveProvider selects provider/key using environment variables and config key.

Selection order: 1. If both GEMINI_API_KEY and OPENAI_API_KEY are set, Gemini wins. 2. If only one env key is set, that provider is selected. 3. If no env keys are set, fallback to config api key.

type QualityResult

type QualityResult struct {
	Score       float64  `json:"score"`       // 0.0 (poor) to 1.0 (excellent)
	Assessment  string   `json:"assessment"`  // "excellent"|"good"|"needs-improvement"|"poor"
	Issues      []string `json:"issues"`      // Missing elements
	Suggestions []string `json:"suggestions"` // How to improve
	Reasoning   string   `json:"reasoning"`
}

QualityResult holds issue quality assessment.

type RelatedIssueRef

type RelatedIssueRef struct {
	Number       int    `json:"number"`
	Title        string `json:"title,omitempty"`
	Relationship string `json:"relationship"` // "duplicate" | "related" | "distinct"
}

RelatedIssueRef captures the LLM's classification of a candidate issue.

type RepositoryCandidate

type RepositoryCandidate struct {
	Org         string
	Repo        string
	Description string
	Definition  string // Full repository documentation (README, etc.)
}

RepositoryCandidate represents a repository option for routing.

type RepositoryRanking

type RepositoryRanking struct {
	Org        string  `json:"org"`
	Repo       string  `json:"repo"`
	Confidence float64 `json:"confidence"` // 0.0-1.0
	Reasoning  string  `json:"reasoning"`
}

RepositoryRanking represents a repository match with confidence.

type RetryConfig

type RetryConfig struct {
	MaxRetries  int           // Maximum number of retry attempts (default: 5)
	BaseDelay   time.Duration // Initial delay before first retry (default: 1s)
	MaxDelay    time.Duration // Maximum delay cap (default: 60s)
	JitterRatio float64       // Jitter as fraction of delay, 0.0-1.0 (default: 0.25)
}

RetryConfig holds configuration for exponential backoff retry.

func DefaultRetryConfig

func DefaultRetryConfig() RetryConfig

DefaultRetryConfig returns sensible defaults for Gemini API retries. Defaults: 5 retries, 1s base delay, 60s max delay, 25% jitter.

type RouteIssueInput

type RouteIssueInput struct {
	Issue        *IssueInput
	Repositories []RepositoryCandidate
	CurrentRepo  string // Current repository (org/repo) where issue was created
}

RouteIssueInput represents input for repository routing.

type RouterResult

type RouterResult struct {
	Rankings  []RepositoryRanking
	BestMatch *RepositoryRanking
}

RouterResult holds repository routing analysis.

type SimilarIssueInput

type SimilarIssueInput struct {
	Number     int
	Title      string
	Body       string // Full text content from vector DB
	URL        string
	Similarity float64
	State      string
}

SimilarIssueInput represents a similar issue found.

type TriageResult

type TriageResult struct {
	Quality         string   `json:"quality"` // "good", "needs-improvement", "poor"
	SuggestedLabels []string `json:"suggested_labels"`
	Reasoning       string   `json:"reasoning"`
	IsDuplicate     bool     `json:"is_duplicate"`
	DuplicateReason string   `json:"duplicate_reason"`
}

TriageResult holds the result of issue triage analysis.

Jump to

Keyboard shortcuts

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