From c5c6ccd607414cb816b5d3d4171d0e87d51a931e Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Sun, 9 Mar 2025 22:33:07 +0800 Subject: [PATCH] refactor: update LLM provider and model data structures Restructured LLMProvider and removed LLMModel: - Added collection tag to LLMProvider - Renamed and reorganized provider fields - Removed separate LLMModel struct - Simplified model and provider attributes --- core/models/models/llm_model.go | 41 ------------------------------ core/models/models/llm_provider.go | 21 +++++---------- 2 files changed, 7 insertions(+), 55 deletions(-) delete mode 100644 core/models/models/llm_model.go diff --git a/core/models/models/llm_model.go b/core/models/models/llm_model.go deleted file mode 100644 index f47757ac..00000000 --- a/core/models/models/llm_model.go +++ /dev/null @@ -1,41 +0,0 @@ -package models - -import ( - "go.mongodb.org/mongo-driver/bson/primitive" -) - -// LLMModel represents a specific model within an LLM provider -type LLMModel struct { - BaseModel[LLMModel] `bson:",inline"` - ProviderId primitive.ObjectID `json:"provider_id" bson:"provider_id"` // Reference to the provider - ModelId string `json:"model_id" bson:"model_id"` // Provider's model ID - Name string `json:"name" bson:"name"` // Model name - DisplayName string `json:"display_name" bson:"display_name"` // Display name for UI - Description string `json:"description,omitempty" bson:"description,omitempty"` // Description of the model - IsEnabled bool `json:"is_enabled" bson:"is_enabled"` // Whether this model is enabled - Priority int `json:"priority" bson:"priority"` // Priority for sorting in UI - ModelFamily string `json:"model_family,omitempty" bson:"model_family,omitempty"` // Family this model belongs to (e.g., "gpt-4", "claude") - ContextSize int `json:"context_size" bson:"context_size"` // Context window size in tokens - MaxOutputTokens int `json:"max_output_tokens" bson:"max_output_tokens"` // Maximum output tokens - SupportedFeatures []string `json:"supported_features" bson:"supported_features"` // Features supported by this model - DefaultParameters map[string]interface{} `json:"default_parameters" bson:"default_parameters"` // Default parameters for this model - TokenPricing *TokenPricing `json:"token_pricing,omitempty" bson:"token_pricing,omitempty"` // Pricing information -} - -// TokenPricing represents the pricing structure for tokens used by an LLM model -type TokenPricing struct { - InputTokenPrice float64 `json:"input_token_price" bson:"input_token_price"` // Price per input token (USD per 1M tokens) - OutputTokenPrice float64 `json:"output_token_price" bson:"output_token_price"` // Price per output token (USD per 1M tokens) - Currency string `json:"currency" bson:"currency"` // Currency for pricing, default is USD -} - -// GetModelColName returns the collection name for the model -func (m *LLMModel) GetModelColName() string { - return "llm_models" -} - -// Validate validates the model -func (m *LLMModel) Validate() error { - // Basic validation can be implemented here - return nil -} diff --git a/core/models/models/llm_provider.go b/core/models/models/llm_provider.go index cf4a5b1a..b3fe910f 100644 --- a/core/models/models/llm_provider.go +++ b/core/models/models/llm_provider.go @@ -2,24 +2,17 @@ package models // LLMProvider represents a language model provider such as OpenAI, Anthropic, etc. type LLMProvider struct { + any `collection:"llm_providers"` BaseModel[LLMProvider] `bson:",inline"` - Name string `json:"name" bson:"name"` // Provider name (e.g., "openai", "anthropic", "gemini") - DisplayName string `json:"display_name" bson:"display_name"` // Display name for UI + Key string `json:"key" bson:"key"` // Provider key (e.g., "openai", "anthropic", "gemini") + Name string `json:"name" bson:"name"` // Display name for UI Description string `json:"description,omitempty" bson:"description,omitempty"` // Description of the provider - IsEnabled bool `json:"is_enabled" bson:"is_enabled"` // Whether this provider is enabled + Models []string `json:"models" bson:"models"` // Models supported by this provider + ApiKey string `json:"api_key" bson:"api_key"` // API key for the provider + ApiBaseUrl string `json:"api_base_url" bson:"api_base_url"` // API base URL for the provider + Enabled bool `json:"enabled" bson:"enabled"` // Whether this provider is enabled Priority int `json:"priority" bson:"priority"` // Priority for sorting in UI ConfigSchema string `json:"config_schema" bson:"config_schema"` // JSON schema for configuration DefaultConfig string `json:"default_config" bson:"default_config"` // Default configuration as JSON SupportedFeatures []string `json:"supported_features" bson:"supported_features"` // Features supported by this provider (e.g., "function_calling", "streaming") } - -// GetModelColName returns the collection name for the provider model -func (p *LLMProvider) GetModelColName() string { - return "llm_providers" -} - -// Validate validates the provider model -func (p *LLMProvider) Validate() error { - // Basic validation can be implemented here - return nil -}