Documentation
¶
Index ¶
- func NewPlugin() plugin.Plugin
- func UpdateProviderModel(provider *AIProvider, dto *ProviderUpdateDTO)
- type AICache
- type AIProvider
- type AIQuota
- type AIRequest
- type AutoTranslator
- type ChatMessage
- type ChatRequestDTO
- type ChatResponseDTO
- type Chatter
- type Config
- type ErrorResponseDTO
- type LocaleProvider
- type PaginatedResponseDTO
- type Plugin
- func (p *Plugin) GetAutoTranslator() *AutoTranslator
- func (p *Plugin) GetRegistry() *providers.ProviderRegistry
- func (p *Plugin) GetService() *Service
- func (p *Plugin) Handler() fiber.Handler
- func (p *Plugin) Initialize(config map[string]interface{}) error
- func (p *Plugin) MigrationDependencies() []string
- func (p *Plugin) MigrationSource() any
- func (p *Plugin) Name() string
- func (p *Plugin) SetLocaleProvider(lp LocaleProvider)
- func (p *Plugin) SetupEndpoints(app *fiber.App) error
- type ProviderCreateDTO
- type ProviderResponseDTO
- type ProviderUpdateDTO
- type ProviderUsageDTO
- type QuotaStatusDTO
- type RequestFilterDTO
- type RequestResponseDTO
- type Service
- type TranslationResult
- type UsageStatsDTO
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UpdateProviderModel ¶
func UpdateProviderModel(provider *AIProvider, dto *ProviderUpdateDTO)
Types ¶
type AICache ¶
type AICache struct {
ID uuid.UUID `db:"id" json:"id"`
CacheKey string `db:"cache_key" json:"cache_key"`
ProviderName string `db:"provider_name" json:"provider_name"`
Model string `db:"model" json:"model"`
RequestType string `db:"request_type" json:"request_type"`
ResponseText string `db:"response_text" json:"response_text"`
PromptTokens int `db:"prompt_tokens" json:"prompt_tokens"`
CompletionTokens int `db:"completion_tokens" json:"completion_tokens"`
TotalTokens int `db:"total_tokens" json:"total_tokens"`
HitCount int `db:"hit_count" json:"hit_count"`
ExpiresAt time.Time `db:"expires_at" json:"expires_at"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt *time.Time `db:"updated_at" json:"updated_at,omitempty"`
}
type AIProvider ¶
type AIProvider struct {
ID uuid.UUID `db:"id" json:"id"`
Name string `db:"name" json:"name"`
DisplayName string `db:"display_name" json:"display_name"`
APIKey string `db:"api_key" json:"-"`
BaseURL *string `db:"base_url" json:"base_url,omitempty"`
Enabled bool `db:"enabled" json:"enabled"`
Priority int `db:"priority" json:"priority"`
MaxTokens int `db:"max_tokens" json:"max_tokens"`
Temperature float64 `db:"temperature" json:"temperature"`
RateLimit int `db:"rate_limit" json:"rate_limit"`
CostPerToken float64 `db:"cost_per_token" json:"cost_per_token"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt *time.Time `db:"updated_at" json:"updated_at,omitempty"`
}
func ToProviderModel ¶
func ToProviderModel(dto *ProviderCreateDTO) *AIProvider
func (AIProvider) TableName ¶
func (AIProvider) TableName() string
type AIQuota ¶
type AIQuota struct {
ID uuid.UUID `db:"id" json:"id"`
UserID uuid.UUID `db:"user_id" json:"user_id"`
DailyLimit int `db:"daily_limit" json:"daily_limit"`
MonthlyLimit int `db:"monthly_limit" json:"monthly_limit"`
DailyTokenLimit int `db:"daily_token_limit" json:"daily_token_limit"`
MonthlyTokenLimit int `db:"monthly_token_limit" json:"monthly_token_limit"`
DailyUsed int `db:"daily_used" json:"daily_used"`
MonthlyUsed int `db:"monthly_used" json:"monthly_used"`
DailyTokensUsed int `db:"daily_tokens_used" json:"daily_tokens_used"`
MonthlyTokensUsed int `db:"monthly_tokens_used" json:"monthly_tokens_used"`
ResetDaily time.Time `db:"reset_daily" json:"reset_daily"`
ResetMonthly time.Time `db:"reset_monthly" json:"reset_monthly"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt *time.Time `db:"updated_at" json:"updated_at,omitempty"`
}
func (*AIQuota) IsExceeded ¶
func (*AIQuota) NeedsReset ¶
func (*AIQuota) ResetDailyCounters ¶
func (q *AIQuota) ResetDailyCounters()
func (*AIQuota) ResetMonthlyCounters ¶
func (q *AIQuota) ResetMonthlyCounters()
type AIRequest ¶
type AIRequest struct {
ID uuid.UUID `db:"id" json:"id"`
UserID *uuid.UUID `db:"user_id" json:"user_id,omitempty"`
ProviderID uuid.UUID `db:"provider_id" json:"provider_id"`
ProviderName string `db:"provider_name" json:"provider_name"`
Model string `db:"model" json:"model"`
RequestType string `db:"request_type" json:"request_type"`
Prompt string `db:"prompt" json:"prompt"`
ResponseText *string `db:"response_text" json:"response_text,omitempty"`
PromptTokens int `db:"prompt_tokens" json:"prompt_tokens"`
CompletionTokens int `db:"completion_tokens" json:"completion_tokens"`
TotalTokens int `db:"total_tokens" json:"total_tokens"`
Cost float64 `db:"cost" json:"cost"`
DurationMs int `db:"duration_ms" json:"duration_ms"`
Status string `db:"status" json:"status"`
ErrorMessage *string `db:"error_message" json:"error_message,omitempty"`
Cached bool `db:"cached" json:"cached"`
IPAddress *string `db:"ip_address" json:"ip_address,omitempty"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
}
type AutoTranslator ¶ added in v0.2.1
type AutoTranslator struct {
// contains filtered or unexported fields
}
func NewAutoTranslator ¶ added in v0.2.1
func NewAutoTranslator(service Chatter, db database.Database, localeProvider LocaleProvider, config *Config) *AutoTranslator
func (*AutoTranslator) Translate ¶ added in v0.2.1
func (t *AutoTranslator) Translate(ctx context.Context, resourceType, resourceID string, userID *uuid.UUID) (*TranslationResult, error)
func (*AutoTranslator) TranslateAsync ¶ added in v0.2.1
type ChatMessage ¶
type ChatRequestDTO ¶
type ChatRequestDTO struct {
Provider string `json:"provider" validate:"required,oneof=anthropic openai gemini mistral auto"`
Model *string `json:"model,omitempty"`
Messages []ChatMessage `json:"messages" validate:"required,min=1,dive"`
Temperature *float64 `json:"temperature,omitempty" validate:"omitempty,gte=0,lte=2"`
MaxTokens *int `json:"max_tokens,omitempty" validate:"omitempty,gt=0"`
Stream bool `json:"stream"`
UseCache bool `json:"use_cache"`
}
type ChatResponseDTO ¶
type ChatResponseDTO struct {
ID uuid.UUID `json:"id"`
Provider string `json:"provider"`
Model string `json:"model"`
Content string `json:"content"`
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
Cost float64 `json:"cost"`
DurationMs int `json:"duration_ms"`
Cached bool `json:"cached"`
CreatedAt time.Time `json:"created_at"`
}
func ToChatResponseDTO ¶
func ToChatResponseDTO(request *AIRequest) *ChatResponseDTO
type Chatter ¶ added in v0.2.1
type Chatter interface {
Chat(ctx context.Context, req *ChatRequestDTO, userID *uuid.UUID) (*ChatResponseDTO, error)
}
Chatter allows Chat calls to be mocked in tests.
type Config ¶
type Config struct {
Database database.Database `json:"-" yaml:"-"`
DefaultProvider string `json:"default_provider" yaml:"default_provider"`
EnabledProviders []string `json:"enabled_providers" yaml:"enabled_providers"`
AnthropicAPIKey string `json:"anthropic_api_key" yaml:"anthropic_api_key"`
AnthropicBaseURL string `json:"anthropic_base_url" yaml:"anthropic_base_url"`
OpenAIAPIKey string `json:"openai_api_key" yaml:"openai_api_key"`
OpenAIBaseURL string `json:"openai_base_url" yaml:"openai_base_url"`
GeminiAPIKey string `json:"gemini_api_key" yaml:"gemini_api_key"`
GeminiBaseURL string `json:"gemini_base_url" yaml:"gemini_base_url"`
MistralAPIKey string `json:"mistral_api_key" yaml:"mistral_api_key"`
MistralBaseURL string `json:"mistral_base_url" yaml:"mistral_base_url"`
EnableCache bool `json:"enable_cache" yaml:"enable_cache"`
CacheTTL int `json:"cache_ttl" yaml:"cache_ttl"`
EnableFallback bool `json:"enable_fallback" yaml:"enable_fallback"`
EnableQuota bool `json:"enable_quota" yaml:"enable_quota"`
MaxTokens int `json:"max_tokens" yaml:"max_tokens"`
DefaultTemperature float64 `json:"default_temperature" yaml:"default_temperature"`
RateLimitPerMin int `json:"rate_limit_per_min" yaml:"rate_limit_per_min"`
RequestTimeout int `json:"request_timeout" yaml:"request_timeout"`
PaginationLimit int `json:"pagination_limit" yaml:"pagination_limit"`
MaxPaginationLimit int `json:"max_pagination_limit" yaml:"max_pagination_limit"`
RequireAuth bool `json:"require_auth" yaml:"require_auth"`
AllowAnonymous bool `json:"allow_anonymous" yaml:"allow_anonymous"`
EnableAudit bool `json:"enable_audit" yaml:"enable_audit"`
RetainAuditDays int `json:"retain_audit_days" yaml:"retain_audit_days"`
AutoTranslate bool `json:"auto_translate" yaml:"auto_translate"`
AllowedResourceTypes []string `json:"allowed_resource_types" yaml:"allowed_resource_types"`
}
func DefaultConfig ¶
func DefaultConfig() Config
func (*Config) GetProviderAPIKey ¶
func (*Config) GetProviderBaseURL ¶
func (*Config) IsProviderEnabled ¶
type ErrorResponseDTO ¶
type LocaleProvider ¶ added in v0.2.1
type PaginatedResponseDTO ¶
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
func (*Plugin) GetAutoTranslator ¶ added in v0.2.1
func (p *Plugin) GetAutoTranslator() *AutoTranslator
func (*Plugin) GetRegistry ¶
func (p *Plugin) GetRegistry() *providers.ProviderRegistry
func (*Plugin) GetService ¶
func (*Plugin) Initialize ¶
func (*Plugin) MigrationDependencies ¶ added in v0.1.1
func (*Plugin) MigrationSource ¶ added in v0.1.1
func (*Plugin) SetLocaleProvider ¶ added in v0.2.1
func (p *Plugin) SetLocaleProvider(lp LocaleProvider)
type ProviderCreateDTO ¶
type ProviderCreateDTO struct {
Name string `json:"name" validate:"required,oneof=anthropic openai gemini mistral"`
DisplayName string `json:"display_name" validate:"required"`
APIKey string `json:"api_key" validate:"required"`
BaseURL *string `json:"base_url,omitempty" validate:"omitempty,url"`
Enabled bool `json:"enabled"`
Priority int `json:"priority" validate:"gte=0"`
MaxTokens int `json:"max_tokens" validate:"required,gt=0"`
Temperature float64 `json:"temperature" validate:"required,gte=0,lte=2"`
RateLimit int `json:"rate_limit" validate:"gte=0"`
}
type ProviderResponseDTO ¶
type ProviderResponseDTO struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
BaseURL *string `json:"base_url,omitempty"`
Enabled bool `json:"enabled"`
Priority int `json:"priority"`
MaxTokens int `json:"max_tokens"`
Temperature float64 `json:"temperature"`
RateLimit int `json:"rate_limit"`
HasAPIKey bool `json:"has_api_key"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}
func ToProviderResponseDTO ¶
func ToProviderResponseDTO(provider *AIProvider) *ProviderResponseDTO
type ProviderUpdateDTO ¶
type ProviderUpdateDTO struct {
DisplayName *string `json:"display_name,omitempty"`
APIKey *string `json:"api_key,omitempty"`
BaseURL *string `json:"base_url,omitempty" validate:"omitempty,url"`
Enabled *bool `json:"enabled,omitempty"`
Priority *int `json:"priority,omitempty" validate:"omitempty,gte=0"`
MaxTokens *int `json:"max_tokens,omitempty" validate:"omitempty,gt=0"`
Temperature *float64 `json:"temperature,omitempty" validate:"omitempty,gte=0,lte=2"`
RateLimit *int `json:"rate_limit,omitempty" validate:"omitempty,gte=0"`
}
type ProviderUsageDTO ¶
type QuotaStatusDTO ¶
type QuotaStatusDTO struct {
DailyLimit int `json:"daily_limit"`
MonthlyLimit int `json:"monthly_limit"`
DailyTokenLimit int `json:"daily_token_limit"`
MonthlyTokenLimit int `json:"monthly_token_limit"`
DailyUsed int `json:"daily_used"`
MonthlyUsed int `json:"monthly_used"`
DailyTokensUsed int `json:"daily_tokens_used"`
MonthlyTokensUsed int `json:"monthly_tokens_used"`
DailyRemaining int `json:"daily_remaining"`
MonthlyRemaining int `json:"monthly_remaining"`
DailyTokensRemaining int `json:"daily_tokens_remaining"`
MonthlyTokensRemaining int `json:"monthly_tokens_remaining"`
ResetDaily time.Time `json:"reset_daily"`
ResetMonthly time.Time `json:"reset_monthly"`
}
func ToQuotaStatusDTO ¶
func ToQuotaStatusDTO(quota *AIQuota) *QuotaStatusDTO
type RequestFilterDTO ¶
type RequestFilterDTO struct {
UserID *uuid.UUID `json:"user_id,omitempty"`
Provider *string `json:"provider,omitempty"`
Status *string `json:"status,omitempty" validate:"omitempty,oneof=success error cached"`
FromDate *time.Time `json:"from_date,omitempty"`
ToDate *time.Time `json:"to_date,omitempty"`
Limit int `json:"limit" validate:"omitempty,gt=0,lte=100"`
Offset int `json:"offset" validate:"omitempty,gte=0"`
}
type RequestResponseDTO ¶
type RequestResponseDTO struct {
ID uuid.UUID `json:"id"`
UserID *uuid.UUID `json:"user_id,omitempty"`
Provider string `json:"provider"`
Model string `json:"model"`
Prompt string `json:"prompt"`
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
Cost float64 `json:"cost"`
DurationMs int `json:"duration_ms"`
Status string `json:"status"`
Cached bool `json:"cached"`
CreatedAt time.Time `json:"created_at"`
}
func ToRequestResponseDTO ¶
func ToRequestResponseDTO(request *AIRequest) *RequestResponseDTO
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) Chat ¶
func (s *Service) Chat(ctx context.Context, req *ChatRequestDTO, userID *uuid.UUID) (*ChatResponseDTO, error)
type TranslationResult ¶ added in v0.2.1
type UsageStatsDTO ¶
type UsageStatsDTO struct {
TotalRequests int `json:"total_requests"`
SuccessfulRequests int `json:"successful_requests"`
FailedRequests int `json:"failed_requests"`
CachedRequests int `json:"cached_requests"`
TotalTokens int `json:"total_tokens"`
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalCost float64 `json:"total_cost"`
AverageDuration int `json:"average_duration_ms"`
ProviderBreakdown map[string]ProviderUsageDTO `json:"provider_breakdown"`
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.