feat: optimize ILLMService interface to support different models for each component

- Add LLMServiceConfig to support mixed model configuration
- Enable Planner, Asserter, Querier to use different optimal models
- Provide recommended configurations for various use cases
- Maintain backward compatibility with existing API
- Update documentation to reflect current state without iteration history
- Merge test files and add comprehensive configuration tests
- Resolve circular dependency by moving config to option package
This commit is contained in:
lilong.129
2025-06-11 12:18:31 +08:00
parent 50414ec74d
commit fbc888655f
6 changed files with 444 additions and 708 deletions

View File

@@ -11,6 +11,7 @@ func NewAIServiceOptions(opts ...AIServiceOption) *AIServiceOptions {
type AIServiceOptions struct {
CVService CVServiceType
LLMService LLMServiceType
LLMConfig *LLMServiceConfig // New field for advanced LLM configuration
}
type AIServiceOption func(*AIServiceOptions)
@@ -48,3 +49,65 @@ func WithLLMService(modelType LLMServiceType) AIServiceOption {
opts.LLMService = modelType
}
}
// LLMServiceConfig defines configuration for different LLM service components
type LLMServiceConfig struct {
PlannerModel LLMServiceType `json:"planner_model"` // Model type for planner component
AsserterModel LLMServiceType `json:"asserter_model"` // Model type for asserter component
QuerierModel LLMServiceType `json:"querier_model"` // Model type for querier component
}
// NewLLMServiceConfig creates a new LLMServiceConfig with the same model for all components
func NewLLMServiceConfig(modelType LLMServiceType) *LLMServiceConfig {
return &LLMServiceConfig{
PlannerModel: modelType,
AsserterModel: modelType,
QuerierModel: modelType,
}
}
// WithPlannerModel sets the model type for planner component
func (c *LLMServiceConfig) WithPlannerModel(modelType LLMServiceType) *LLMServiceConfig {
c.PlannerModel = modelType
return c
}
// WithAsserterModel sets the model type for asserter component
func (c *LLMServiceConfig) WithAsserterModel(modelType LLMServiceType) *LLMServiceConfig {
c.AsserterModel = modelType
return c
}
// WithQuerierModel sets the model type for querier component
func (c *LLMServiceConfig) WithQuerierModel(modelType LLMServiceType) *LLMServiceConfig {
c.QuerierModel = modelType
return c
}
// WithLLMConfig sets the advanced LLM configuration
func WithLLMConfig(config *LLMServiceConfig) AIServiceOption {
return func(opts *AIServiceOptions) {
opts.LLMConfig = config
}
}
// RecommendedConfigurations provides some recommended model configurations for different use cases
func RecommendedConfigurations() map[string]*LLMServiceConfig {
return map[string]*LLMServiceConfig{
"cost_effective": NewLLMServiceConfig(DOUBAO_1_5_THINKING_VISION_PRO_250428).
WithPlannerModel(DOUBAO_1_5_UI_TARS_250328).
WithAsserterModel(DOUBAO_1_5_THINKING_VISION_PRO_250428).
WithQuerierModel(DOUBAO_1_5_THINKING_VISION_PRO_250428),
"high_performance": NewLLMServiceConfig(OPENAI_GPT_4O),
"mixed_optimal": NewLLMServiceConfig(DOUBAO_1_5_THINKING_VISION_PRO_250428).
WithPlannerModel(DOUBAO_1_5_UI_TARS_250328). // Best for UI understanding
WithAsserterModel(OPENAI_GPT_4O). // Best for reasoning
WithQuerierModel(DEEPSEEK_R1_250528), // Cost-effective for queries
"ui_focused": NewLLMServiceConfig(DOUBAO_1_5_UI_TARS_250328),
"reasoning_focused": NewLLMServiceConfig(DOUBAO_1_5_THINKING_VISION_PRO_250428),
}
}