ai

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidProviders added in v0.3.1

func ValidProviders() []string

ValidProviders returns the list of valid provider type strings

Types

type APIError

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

APIError represents an API error

type Choice

type Choice struct {
	Message Message `json:"message"`
}

Choice represents a response choice

type ClaudeCodeClient added in v0.3.1

type ClaudeCodeClient struct {
	Model           string
	ClaudePath      string // Path to claude executable
	Validated       bool
	ValidationErr   string
	ServiceName     string
	AvailableModels []string
}

ClaudeCodeClient handles Claude Code CLI requests

func NewClaudeCodeClient added in v0.3.1

func NewClaudeCodeClient(model string) *ClaudeCodeClient

NewClaudeCodeClient creates a new Claude Code client

func (*ClaudeCodeClient) AnalyzeLog added in v0.3.1

func (c *ClaudeCodeClient) AnalyzeLog(logMessage, severity, timestamp string, attributes map[string]string) (string, error)

AnalyzeLog sends a log message to Claude Code for analysis

func (*ClaudeCodeClient) AnalyzeLogWithContext added in v0.3.1

func (c *ClaudeCodeClient) AnalyzeLogWithContext(logMessage, severity, timestamp string, attributes map[string]string, previousAnalysis string, question string) (string, error)

AnalyzeLogWithContext sends a log message to Claude Code with chat context

func (*ClaudeCodeClient) CachedModels added in v0.3.1

func (c *ClaudeCodeClient) CachedModels() []string

CachedModels returns the cached list of available models without making API calls

func (*ClaudeCodeClient) GetAvailableModels added in v0.3.1

func (c *ClaudeCodeClient) GetAvailableModels() ([]string, error)

GetAvailableModels returns a list of Claude models Note: Claude Code doesn't expose an API to list models, so we return a static list

func (*ClaudeCodeClient) GetModel added in v0.3.1

func (c *ClaudeCodeClient) GetModel() string

GetModel returns the current model being used

func (*ClaudeCodeClient) GetValidationStatus added in v0.3.1

func (c *ClaudeCodeClient) GetValidationStatus() ValidationStatus

GetValidationStatus returns the validation status of the client

func (*ClaudeCodeClient) SetModel added in v0.3.1

func (c *ClaudeCodeClient) SetModel(model string)

SetModel updates the model being used

func (*ClaudeCodeClient) ValidateConfiguration added in v0.3.1

func (c *ClaudeCodeClient) ValidateConfiguration()

ValidateConfiguration checks if the Claude Code CLI is properly configured

type Client added in v0.3.1

type Client interface {
	// AnalyzeLog sends a log message to the AI for analysis
	AnalyzeLog(logMessage, severity, timestamp string, attributes map[string]string) (string, error)

	// AnalyzeLogWithContext sends a log message with chat context for follow-up questions
	AnalyzeLogWithContext(logMessage, severity, timestamp string, attributes map[string]string, previousAnalysis, question string) (string, error)

	// GetValidationStatus returns the validation status of the client
	GetValidationStatus() ValidationStatus

	// GetAvailableModels fetches the list of available models from the provider (makes API call)
	GetAvailableModels() ([]string, error)

	// SetModel updates the active model being used
	SetModel(model string)

	// GetModel returns the current model being used
	GetModel() string

	// CachedModels returns the cached list of available models without making API calls.
	// This is used by the TUI for model selection.
	CachedModels() []string
}

Client defines the interface for all AI providers. Implementations include OpenAI-compatible APIs and Claude Code CLI.

func NewClient added in v0.3.1

func NewClient(provider ProviderType, model string) (Client, error)

NewClient creates an AI client based on the provider type and model.

When provider is empty (ProviderAuto), it maintains backwards compatibility:

  • If OPENAI_API_KEY is set and valid, returns an OpenAI client
  • Otherwise returns (nil, nil) indicating AI features are disabled

When provider is explicitly set:

  • "openai": Returns OpenAI client (may have Validated=false if OPENAI_API_KEY not set)
  • "claude-code": Returns Claude Code client (may have Validated=false if CLI not found)

Explicit providers always return a client so the TUI can display validation errors. Returns an error only for invalid/unknown provider values.

type Message

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

Message represents a chat message

type ModelInfo

type ModelInfo struct {
	ID     string `json:"id"`
	Object string `json:"object"`
}

ModelInfo represents a single model in the list

type ModelListResponse

type ModelListResponse struct {
	Data []ModelInfo `json:"data"`
}

ModelListResponse represents the /v1/models endpoint response

type OllamaGenerateRequest

type OllamaGenerateRequest struct {
	Model  string `json:"model"`
	Prompt string `json:"prompt"`
	Stream bool   `json:"stream"`
}

OllamaGenerateRequest represents Ollama's /api/generate request

type OllamaGenerateResponse

type OllamaGenerateResponse struct {
	Response string `json:"response"`
	Done     bool   `json:"done"`
}

OllamaGenerateResponse represents Ollama's /api/generate response

type OllamaModel

type OllamaModel struct {
	Name string `json:"name"`
	Size int64  `json:"size"`
}

OllamaModel represents a model in Ollama's response

type OllamaTagsResponse

type OllamaTagsResponse struct {
	Models []OllamaModel `json:"models"`
}

OllamaTagsResponse represents Ollama's /api/tags response

type OpenAIClient

type OpenAIClient struct {
	APIKey          string
	BaseURL         string
	Model           string
	HTTPClient      *http.Client
	Validated       bool
	ValidationErr   string
	ServiceName     string
	AvailableModels []string
	AutoSelectModel bool // True if no model was specified, should auto-select
}

OpenAIClient handles OpenAI API compatible requests

func NewOpenAIClient

func NewOpenAIClient(model string) *OpenAIClient

NewOpenAIClient creates a new OpenAI client with environment variable detection

func (*OpenAIClient) AnalyzeLog

func (c *OpenAIClient) AnalyzeLog(logMessage, severity, timestamp string, attributes map[string]string) (string, error)

AnalyzeLog sends a log message to the AI for analysis

func (*OpenAIClient) AnalyzeLogWithContext

func (c *OpenAIClient) AnalyzeLogWithContext(logMessage, severity, timestamp string, attributes map[string]string, previousAnalysis string, question string) (string, error)

AnalyzeLogWithContext sends a log message to the AI with chat context

func (*OpenAIClient) CachedModels added in v0.3.1

func (c *OpenAIClient) CachedModels() []string

CachedModels returns the cached list of available models without making API calls

func (*OpenAIClient) GetAvailableModels

func (c *OpenAIClient) GetAvailableModels() ([]string, error)

GetAvailableModels fetches the list of available models from the API

func (*OpenAIClient) GetModel added in v0.3.1

func (c *OpenAIClient) GetModel() string

GetModel returns the current model being used

func (*OpenAIClient) GetValidationStatus

func (c *OpenAIClient) GetValidationStatus() ValidationStatus

GetValidationStatus returns the validation status of the client

func (*OpenAIClient) SetModel added in v0.3.1

func (c *OpenAIClient) SetModel(model string)

SetModel updates the model being used

func (*OpenAIClient) ValidateConfiguration

func (c *OpenAIClient) ValidateConfiguration()

ValidateConfiguration checks if the AI client is properly configured

type OpenAIRequest

type OpenAIRequest struct {
	Model    string    `json:"model"`
	Messages []Message `json:"messages"`
}

OpenAIRequest represents the request structure

type OpenAIResponse

type OpenAIResponse struct {
	Choices []Choice `json:"choices"`
	Error   any      `json:"error,omitempty"` // Can be string or object
}

OpenAIResponse represents the API response with flexible error handling

type ProviderType added in v0.3.1

type ProviderType string

ProviderType represents the AI provider type

const (
	// ProviderOpenAI uses OpenAI-compatible APIs (OpenAI, Ollama, LM Studio, etc.)
	ProviderOpenAI ProviderType = "openai"

	// ProviderClaudeCode uses the Claude Code CLI
	ProviderClaudeCode ProviderType = "claude-code"

	// ProviderAuto auto-detects the provider based on environment.
	// This is the default and maintains backwards compatibility:
	// - If OPENAI_API_KEY is set, uses OpenAI client
	// - Otherwise returns nil (AI disabled)
	ProviderAuto ProviderType = ""
)

type ValidationStatus added in v0.3.1

type ValidationStatus struct {
	Validated    bool
	ErrorMessage string
	ServiceName  string
	ModelName    string
}

ValidationStatus contains the validation state of an AI client.

Jump to

Keyboard shortcuts

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