ai

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCodeReviewPrompt

func GetCodeReviewPrompt() string

func GetCodeReviewPromptWithStyleGuide

func GetCodeReviewPromptWithStyleGuide(styleGuideRules string) string

func GetPRSummaryPrompt

func GetPRSummaryPrompt() string

Types

type AnthropicClient

type AnthropicClient struct {
	*BaseClient
}

func NewAnthropicClient

func NewAnthropicClient(config Config) *AnthropicClient

func (*AnthropicClient) GenerateCodeReview

func (c *AnthropicClient) GenerateCodeReview(prTitle, prDescription, diff string) (*ReviewResult, error)

func (*AnthropicClient) GenerateCodeReviewWithStyleGuide

func (c *AnthropicClient) GenerateCodeReviewWithStyleGuide(prTitle, prDescription, diff, styleGuide string) (*ReviewResult, error)

func (*AnthropicClient) GeneratePRSummary

func (c *AnthropicClient) GeneratePRSummary(prTitle, prDescription, diff string) (*PRSummary, error)

func (*AnthropicClient) GenerateResponse

func (c *AnthropicClient) GenerateResponse(prompt string) (string, error)

type AnthropicMessage

type AnthropicMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type AnthropicRequest

type AnthropicRequest struct {
	Model     string             `json:"model"`
	MaxTokens int                `json:"max_tokens"`
	Messages  []AnthropicMessage `json:"messages"`
	System    string             `json:"system,omitempty"`
}

type AnthropicResponse

type AnthropicResponse struct {
	Content []struct {
		Type string `json:"type"`
		Text string `json:"text"`
	} `json:"content"`
	Error *struct {
		Type    string `json:"type"`
		Message string `json:"message"`
	} `json:"error,omitempty"`
}

type BaseClient

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

Base HTTP client for LLM providers

func NewBaseClient

func NewBaseClient(apiKey, model, baseURL string, headers map[string]string) *BaseClient

type ChatCompletionRequest

type ChatCompletionRequest struct {
	Model       string        `json:"model"`
	Messages    []ChatMessage `json:"messages"`
	Temperature *float64      `json:"temperature,omitempty"`
	MaxTokens   *int          `json:"max_tokens,omitempty"`
}

type ChatCompletionResponse

type ChatCompletionResponse struct {
	Choices []struct {
		Message struct {
			Role    string `json:"role"`
			Content string `json:"content"`
		} `json:"message"`
		FinishReason string `json:"finish_reason"`
	} `json:"choices"`
	Error *struct {
		Message string `json:"message"`
		Type    string `json:"type"`
		Code    string `json:"code"`
	} `json:"error,omitempty"`
}

type ChatMessage

type ChatMessage struct {
	Role    string `json:"role"` // "system", "user", "assistant"
	Content string `json:"content"`
}

type Client

type Client interface {
	GeneratePRSummary(prTitle, prDescription, diff string) (*PRSummary, error)
	GenerateCodeReview(prTitle, prDescription, diff string) (*ReviewResult, error)
	GenerateCodeReviewWithStyleGuide(prTitle, prDescription, diff, styleGuide string) (*ReviewResult, error)
	GenerateResponse(prompt string) (string, error) // For conversational responses
}

func NewClient

func NewClient(config Config) (Client, error)

type Comment

type Comment struct {
	File            string `json:"file"`
	StartLine       int    `json:"start_line"`
	EndLine         int    `json:"end_line"`
	HighlightedCode string `json:"highlighted_code"`
	Header          string `json:"header"`
	Content         string `json:"content"`
	Label           string `json:"label"` // e.g. "bug", "security"
	Critical        bool   `json:"critical"`
	SuggestedCode   string `json:"suggested_code,omitempty"` // GitHub suggestion block content
}

type Config

type Config struct {
	Provider string
	APIKey   string
	Model    string
	BaseURL  string
}

type GoogleClient

type GoogleClient struct {
	*BaseClient
}

func NewGoogleClient

func NewGoogleClient(config Config) *GoogleClient

func (*GoogleClient) GenerateCodeReview

func (c *GoogleClient) GenerateCodeReview(prTitle, prDescription, diff string) (*ReviewResult, error)

func (*GoogleClient) GenerateCodeReviewWithStyleGuide

func (c *GoogleClient) GenerateCodeReviewWithStyleGuide(prTitle, prDescription, diff, styleGuide string) (*ReviewResult, error)

func (*GoogleClient) GeneratePRSummary

func (c *GoogleClient) GeneratePRSummary(prTitle, prDescription, diff string) (*PRSummary, error)

func (*GoogleClient) GenerateResponse

func (c *GoogleClient) GenerateResponse(prompt string) (string, error)

type GoogleContent

type GoogleContent struct {
	Role  string       `json:"role"`
	Parts []GooglePart `json:"parts"`
}

type GoogleGenConfig

type GoogleGenConfig struct {
	Temperature     *float64 `json:"temperature,omitempty"`
	MaxOutputTokens *int     `json:"maxOutputTokens,omitempty"`
}

type GooglePart

type GooglePart struct {
	Text string `json:"text"`
}

type GoogleRequest

type GoogleRequest struct {
	Contents          []GoogleContent  `json:"contents"`
	SystemInstruction *GoogleContent   `json:"systemInstruction,omitempty"`
	GenerationConfig  *GoogleGenConfig `json:"generationConfig,omitempty"`
}

type GoogleResponse

type GoogleResponse struct {
	Candidates []struct {
		Content struct {
			Parts []GooglePart `json:"parts"`
			Role  string       `json:"role"`
		} `json:"content"`
		FinishReason string `json:"finishReason"`
	} `json:"candidates"`
	Error *struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
		Status  string `json:"status"`
	} `json:"error,omitempty"`
}

type OpenAIClient

type OpenAIClient struct {
	*BaseClient
}

func NewOpenAIClient

func NewOpenAIClient(config Config) *OpenAIClient

func (*OpenAIClient) GenerateCodeReview

func (c *OpenAIClient) GenerateCodeReview(prTitle, prDescription, diff string) (*ReviewResult, error)

func (*OpenAIClient) GenerateCodeReviewWithStyleGuide

func (c *OpenAIClient) GenerateCodeReviewWithStyleGuide(prTitle, prDescription, diff, styleGuide string) (*ReviewResult, error)

func (*OpenAIClient) GeneratePRSummary

func (c *OpenAIClient) GeneratePRSummary(prTitle, prDescription, diff string) (*PRSummary, error)

func (*OpenAIClient) GenerateResponse

func (c *OpenAIClient) GenerateResponse(prompt string) (string, error)

type OpenRouterClient

type OpenRouterClient struct {
	*BaseClient
}

func NewOpenRouterClient

func NewOpenRouterClient(config Config) *OpenRouterClient

func (*OpenRouterClient) GenerateCodeReview

func (c *OpenRouterClient) GenerateCodeReview(prTitle, prDescription, diff string) (*ReviewResult, error)

func (*OpenRouterClient) GenerateCodeReviewWithStyleGuide

func (c *OpenRouterClient) GenerateCodeReviewWithStyleGuide(prTitle, prDescription, diff, styleGuide string) (*ReviewResult, error)

func (*OpenRouterClient) GeneratePRSummary

func (c *OpenRouterClient) GeneratePRSummary(prTitle, prDescription, diff string) (*PRSummary, error)

func (*OpenRouterClient) GenerateResponse

func (c *OpenRouterClient) GenerateResponse(prompt string) (string, error)

type PRSummary

type PRSummary struct {
	Title       string   `json:"title"` // Max 10 words
	Description string   `json:"description"`
	Type        []string `json:"type"` // e.g., BUG, ENHANCEMENT
	Files       []struct {
		Filename string `json:"filename"`
		Summary  string `json:"summary"` // Max 70 words
		Title    string `json:"title"`   // 5-10 words
	} `json:"files"`
}

type ReviewAction

type ReviewAction string

ReviewAction represents the GitHub review action type

const (
	ReviewActionComment        ReviewAction = "COMMENT"
	ReviewActionApprove        ReviewAction = "APPROVE"
	ReviewActionRequestChanges ReviewAction = "REQUEST_CHANGES"
)

type ReviewResult

type ReviewResult struct {
	Review   ReviewSummary `json:"review"`
	Comments []Comment     `json:"comments"`
}

func (*ReviewResult) GetReviewAction

func (r *ReviewResult) GetReviewAction(autoApproveThreshold int, blockOnCritical bool) ReviewAction

GetReviewAction determines the appropriate GitHub review action based on the review result

type ReviewSummary

type ReviewSummary struct {
	EstimatedEffort  int    `json:"estimated_effort_to_review"` // 1-5
	Score            int    `json:"score"`                      // 0-100
	HasRelevantTests bool   `json:"has_relevant_tests"`
	SecurityConcerns string `json:"security_concerns"`
}

Jump to

Keyboard shortcuts

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