- Refactored AI gateway to utilize new cost management structures for usage tracking. - Replaced deprecated token extraction methods with a unified cost parsing approach. - Enhanced usage fallback mechanisms and introduced detailed usage metrics in responses. - Added new metering functionality to record AI usage and costs effectively. - Updated tests to reflect changes in usage parsing and cost calculations. - Introduced new API endpoints for retrieving AI usage summaries and pricing information.
83 lines
2.9 KiB
Go
83 lines
2.9 KiB
Go
package ai
|
|
|
|
import "time"
|
|
|
|
type ModelCatalogEntry struct {
|
|
ModelID string `json:"model_id"`
|
|
Label string `json:"label"`
|
|
Enabled bool `json:"enabled"`
|
|
}
|
|
|
|
type AssistantPolicy struct {
|
|
Enabled bool `json:"enabled"`
|
|
OpenWebUIInternalURL string `json:"openwebui_internal_url"`
|
|
PublicPath string `json:"public_path"`
|
|
EmbedDefaultTemporary bool `json:"embed_default_temporary"`
|
|
DefaultModel string `json:"default_model"`
|
|
EnabledTools []string `json:"enabled_tools"`
|
|
ChatSyncEnabled bool `json:"chat_sync_enabled"`
|
|
ChatNCPath string `json:"chat_nc_path"`
|
|
Models []ModelCatalogEntry `json:"models,omitempty"`
|
|
}
|
|
|
|
type QuotaLimits struct {
|
|
DailyLimitMicroEUR *int64 `json:"llm_daily_cost_limit_micro_eur,omitempty"`
|
|
MonthlyLimitMicroEUR *int64 `json:"llm_monthly_cost_limit_micro_eur,omitempty"`
|
|
WarnThresholdPct int `json:"llm_cost_warn_threshold_pct,omitempty"`
|
|
// Deprecated legacy fields
|
|
RequestsPerDay int `json:"llm_requests_per_day"`
|
|
TokensPerMonth int64 `json:"llm_tokens_per_month"`
|
|
}
|
|
|
|
type ChatMessage struct {
|
|
Role string `json:"role"`
|
|
Content string `json:"content,omitempty"`
|
|
ToolCalls []any `json:"tool_calls,omitempty"`
|
|
Attachments []any `json:"attachments,omitempty"`
|
|
}
|
|
|
|
type ChatMeta struct {
|
|
Model string `json:"model,omitempty"`
|
|
TokensUsed int64 `json:"tokens_used,omitempty"`
|
|
Context string `json:"context,omitempty"`
|
|
}
|
|
|
|
type ChatRecord struct {
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
Source string `json:"source"`
|
|
OpenWebUIChatID string `json:"openwebui_chat_id,omitempty"`
|
|
Messages []ChatMessage `json:"messages"`
|
|
Meta ChatMeta `json:"meta"`
|
|
}
|
|
|
|
type ChatListItem struct {
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
Source string `json:"source"`
|
|
}
|
|
|
|
type SessionContext struct {
|
|
App string `json:"app"`
|
|
Temporary bool `json:"temporary"`
|
|
MessageID string `json:"message_id,omitempty"`
|
|
AccountID string `json:"account_id,omitempty"`
|
|
DrivePath string `json:"drive_path,omitempty"`
|
|
FileID string `json:"file_id,omitempty"`
|
|
ContactID string `json:"contact_id,omitempty"`
|
|
Subject string `json:"subject,omitempty"`
|
|
Snippet string `json:"snippet,omitempty"`
|
|
}
|
|
|
|
type SessionResponse struct {
|
|
SessionID string `json:"session_id"`
|
|
EmbedURL string `json:"embed_url"`
|
|
TokenSecret string `json:"token_secret,omitempty"`
|
|
Temporary bool `json:"temporary"`
|
|
MCPURL string `json:"mcp_url,omitempty"`
|
|
EnabledTools []string `json:"enabled_tools,omitempty"`
|
|
}
|