ai

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 17 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

Overview

Package ai provides AI-powered test case generation for gotests.

Index

Constants

View Source
const (
	// MaxResponseSize is the maximum size of HTTP responses (1MB)
	MaxResponseSize = 1 * 1024 * 1024
	// MaxFunctionBodySize is the maximum size of function body in prompts (100KB)
	MaxFunctionBodySize = 100 * 1024
)

Variables

This section is empty.

Functions

func ValidateGeneratedTest

func ValidateGeneratedTest(testCode, pkgName string) error

ValidateGeneratedTest checks if the generated test code compiles. Uses in-memory parsing and type-checking without writing files.

Types

type Config

type Config struct {
	Provider       string // Provider name: "ollama", "openai", "claude"
	Model          string // Model name (e.g., "qwen2.5-coder:0.5b")
	Endpoint       string // API endpoint URL
	APIKey         string // API key (for cloud providers)
	MinCases       int    // Minimum number of test cases to generate (default: 3)
	MaxCases       int    // Maximum number of test cases to generate (default: 10)
	MaxRetries     int    // Maximum number of retry attempts (default: 3)
	RequestTimeout int    // HTTP request timeout in seconds (default: 60)
	HealthTimeout  int    // Health check timeout in seconds (default: 2)
}

Config holds configuration for AI providers.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default AI configuration.

type OllamaProvider

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

OllamaProvider implements the Provider interface for Ollama.

func NewOllamaProvider

func NewOllamaProvider(cfg *Config) (*OllamaProvider, error)

NewOllamaProvider creates a new Ollama provider with the given config. Returns an error if the endpoint URL is invalid or unsafe.

func (*OllamaProvider) GenerateTestCases

func (o *OllamaProvider) GenerateTestCases(ctx context.Context, fn *models.Function) ([]TestCase, error)

GenerateTestCases generates test cases using Ollama. Now uses Go code generation instead of JSON for better small-model compatibility.

func (*OllamaProvider) IsAvailable

func (o *OllamaProvider) IsAvailable() bool

IsAvailable checks if Ollama is running and accessible.

func (*OllamaProvider) Name

func (o *OllamaProvider) Name() string

Name returns the provider name.

type Provider

type Provider interface {
	// GenerateTestCases generates test cases for the given function.
	GenerateTestCases(ctx context.Context, fn *models.Function) ([]TestCase, error)

	// IsAvailable checks if the provider is available and configured.
	IsAvailable() bool

	// Name returns the provider name for logging/debugging.
	Name() string
}

Provider is the interface for AI test case generation backends.

type TestCase

type TestCase struct {
	Name        string            // Test case name (e.g., "positive_numbers")
	Description string            // Optional description
	Args        map[string]string // Parameter name -> Go code value
	Want        map[string]string // Return value name -> Go code value
	WantErr     bool              // Whether an error is expected
}

TestCase represents a single generated test case.

Jump to

Keyboard shortcuts

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