provider

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout is the default timeout for API requests.

View Source
const TimeoutEnvVar = "HOWTO_TIMEOUT"

TimeoutEnvVar is the environment variable to override the default timeout.

Variables

View Source
var (
	OpenAI = &Provider{
		Name:         "OpenAI",
		Endpoint:     "https://api.openai.com/v1/chat/completions",
		DefaultModel: "gpt-4o",
		EnvVar:       "OPENAI_API_KEY",
		AuthType:     AuthBearer,
	}

	Anthropic = &Provider{
		Name:         "Anthropic",
		Endpoint:     "https://api.anthropic.com/v1/messages",
		DefaultModel: "claude-sonnet-4-20250514",
		EnvVar:       "ANTHROPIC_API_KEY",
		AuthType:     AuthAPIKey,
	}

	Gemini = &Provider{
		Name:         "Gemini",
		Endpoint:     "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions",
		DefaultModel: "gemini-2.0-flash",
		EnvVar:       "GEMINI_API_KEY",
		AuthType:     AuthBearer,
	}

	DeepSeek = &Provider{
		Name:         "DeepSeek",
		Endpoint:     "https://api.deepseek.com/chat/completions",
		DefaultModel: "deepseek-chat",
		EnvVar:       "DEEPSEEK_API_KEY",
		AuthType:     AuthBearer,
	}

	GitHubCopilot = &Provider{
		Name:         "GitHub Copilot",
		Endpoint:     "",
		DefaultModel: "gpt-4",
		EnvVar:       "",
		AuthType:     AuthCLI,
	}
)

Providers configuration.

Functions

func CleanCopilotResponse

func CleanCopilotResponse(response string) string

CleanCopilotResponse removes markdown formatting from Copilot's response.

func GetTimeout

func GetTimeout(flagTimeout time.Duration) time.Duration

GetTimeout returns the configured timeout duration. It checks the HOWTO_TIMEOUT environment variable first, then falls back to the provided default or DefaultTimeout.

func IsCopilotAvailable

func IsCopilotAvailable() bool

IsCopilotAvailable checks if GitHub Copilot CLI is available.

Types

type APIError

type APIError struct {
	Message string `json:"message"`
}

APIError represents an API error response.

type AnthropicMessage

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

AnthropicMessage represents a message in Anthropic format.

type AnthropicRequest

type AnthropicRequest struct {
	Model     string             `json:"model"`
	MaxTokens int                `json:"maxTokens"`
	Messages  []AnthropicMessage `json:"messages"`
}

AnthropicRequest represents an Anthropic API request.

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"`
}

AnthropicResponse represents an Anthropic API response.

type AuthType

type AuthType int

AuthType defines how the provider authenticates requests.

const (
	// AuthBearer uses "Authorization: Bearer <token>" header.
	AuthBearer AuthType = iota
	// AuthAPIKey uses a custom API key header or query param.
	AuthAPIKey
	// AuthCLI uses an external CLI tool (like gh copilot).
	AuthCLI
)

type ChatRequest

type ChatRequest struct {
	Model     string    `json:"model"`
	Messages  []Message `json:"messages"`
	MaxTokens int       `json:"maxTokens"`
}

ChatRequest represents a chat completion request.

type ChatResponse

type ChatResponse struct {
	Choices []struct {
		Message Message `json:"message"`
	} `json:"choices"`
	Error *APIError `json:"error,omitempty"`
}

ChatResponse represents a chat completion response.

type Message

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

Message represents a chat message.

type Provider

type Provider struct {
	Name         string
	Endpoint     string
	DefaultModel string
	EnvVar       string
	AuthType     AuthType
	Configured   bool
}

Provider represents an AI provider configuration.

func Detect

func Detect() (*Provider, string)

Detect automatically detects the first available provider.

func GetByName

func GetByName(name string) (*Provider, string, error)

GetByName returns a provider by name.

func (*Provider) Query

func (p *Provider) Query(ctx context.Context, apiKey, model, promptText string) (string, error)

Query sends a chat completion request to the provider.

type ProviderInfo

type ProviderInfo struct {
	Name         string
	DefaultModel string
	EnvVar       string
	Configured   bool
}

ProviderInfo contains provider information for display.

func ListAll

func ListAll() []ProviderInfo

ListAll returns information about all providers.

Jump to

Keyboard shortcuts

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