feat: add configurable AgentRouter AI provider
This commit is contained in:
@@ -43,7 +43,8 @@ func main() {
|
||||
defer redisClient.Close()
|
||||
repository := growthreport.NewRepository(pool)
|
||||
coordinator := growthreport.NewCoordinator(redisClient, growthreport.CoordinatorConfig{CreatePerMinute: cfg.AICreatePerMinute, UncachedPerDay: cfg.AIUncachedScopesPerDay, DailyRequests: cfg.AIDailyRequestBudget, DailyTokens: cfg.AIDailyTokenBudget, MaxConcurrent: cfg.AIMaxConcurrent})
|
||||
growthService := growthreport.NewService(repository, coordinator, growthreport.ServiceConfig{Enabled: cfg.AIGrowthEnabled, Model: cfg.AvalAIModel, PromptVersion: "1.0.0", SchemaVersion: "1.0.0"})
|
||||
provider := cfg.SelectedAIProvider()
|
||||
growthService := growthreport.NewService(repository, coordinator, growthreport.ServiceConfig{Enabled: cfg.AIGrowthEnabled, Model: provider.Model, PromptVersion: "1.0.5", SchemaVersion: "1.0.1"})
|
||||
insightRepository := insight.NewRepository(pool)
|
||||
insightService := insight.NewService(insightRepository, insight.NewPostgreSQLBuilder(pool))
|
||||
appServer := api.NewServer(identity.New(pool), analytics.New(pool, cfg.CursorSecret), logger, cfg.FrontendOrigin, cfg.CookieSecure, growthService)
|
||||
|
||||
@@ -41,21 +41,30 @@ func main() {
|
||||
defer redisClient.Close()
|
||||
repository := growthreport.NewRepository(pool)
|
||||
coordinator := growthreport.NewCoordinator(redisClient, growthreport.CoordinatorConfig{CreatePerMinute: cfg.AICreatePerMinute, UncachedPerDay: cfg.AIUncachedScopesPerDay, DailyRequests: cfg.AIDailyRequestBudget, DailyTokens: cfg.AIDailyTokenBudget, MaxConcurrent: cfg.AIMaxConcurrent})
|
||||
avalai := growthreport.NewAvalAIClient(growthreport.AvalAIConfig{BaseURL: cfg.AvalAIBaseURL, APIKey: cfg.AvalAIAPIKey, Model: cfg.AvalAIModel, Timeout: 30 * time.Second}, &http.Client{})
|
||||
processor := growthreport.NewProcessor(repository, growthreport.NewPostgreSQLBuilder(pool), avalai, coordinator, cfg.AIGrowthEnabled && cfg.AvalAIAPIKey != "")
|
||||
sharedProvider := aiprovider.New(aiprovider.Config{BaseURL: cfg.AvalAIBaseURL, APIKey: cfg.AvalAIAPIKey, Model: cfg.AvalAIModel, Timeout: 30 * time.Second}, &http.Client{})
|
||||
provider := cfg.SelectedAIProvider()
|
||||
var growthGenerator growthreport.CopyGenerator
|
||||
var sharedProvider aiprovider.Generator
|
||||
if provider.Name == config.AIProviderAgentRouter {
|
||||
growthGenerator = growthreport.NewAgentRouterClient(growthreport.AgentRouterConfig{BaseURL: provider.BaseURL, APIKey: provider.APIKey, Model: provider.Model, Timeout: 90 * time.Second}, &http.Client{})
|
||||
sharedProvider = aiprovider.NewAgentRouter(aiprovider.Config{BaseURL: provider.BaseURL, APIKey: provider.APIKey, Model: provider.Model, Timeout: 90 * time.Second}, &http.Client{})
|
||||
} else {
|
||||
growthGenerator = growthreport.NewAvalAIClient(growthreport.AvalAIConfig{BaseURL: provider.BaseURL, APIKey: provider.APIKey, Model: provider.Model, Timeout: 30 * time.Second}, &http.Client{})
|
||||
sharedProvider = aiprovider.New(aiprovider.Config{BaseURL: provider.BaseURL, APIKey: provider.APIKey, Model: provider.Model, Timeout: 30 * time.Second}, &http.Client{})
|
||||
}
|
||||
aiAvailable := provider.APIKey != "" && provider.Model != ""
|
||||
processor := growthreport.NewProcessor(repository, growthreport.NewPostgreSQLBuilder(pool), growthGenerator, coordinator, cfg.AIGrowthEnabled && aiAvailable)
|
||||
var insightService *insight.Service
|
||||
if cfg.AIPageInsightsEnabled && cfg.AvalAIAPIKey != "" {
|
||||
if cfg.AIPageInsightsEnabled && aiAvailable {
|
||||
insightService = insight.NewService(insight.NewRepository(pool), insight.NewPostgreSQLBuilder(pool), insight.NewAvalAIGenerator(sharedProvider)).WithBudget(cfg.AIPageInsightsDailyRequestBudget, cfg.AIPageInsightsDailyTokenBudget)
|
||||
} else {
|
||||
insightService = insight.NewService(insight.NewRepository(pool), insight.NewPostgreSQLBuilder(pool))
|
||||
}
|
||||
var coachGenerator coach.Generator
|
||||
if cfg.AICoachEnabled && cfg.AvalAIAPIKey != "" {
|
||||
if cfg.AICoachEnabled && aiAvailable {
|
||||
coachGenerator = coach.NewAvalAIGenerator(sharedProvider)
|
||||
}
|
||||
coachService := coach.NewService(coach.NewRepository(pool), coachGenerator).WithBudget(cfg.AICoachDailyRequestBudget, cfg.AICoachDailyTokenBudget)
|
||||
logger.Info("growth worker ready", "ai_enabled", cfg.AIGrowthEnabled && cfg.AvalAIAPIKey != "")
|
||||
logger.Info("growth worker ready", "ai_enabled", cfg.AIGrowthEnabled && aiAvailable, "ai_provider", provider.Name, "ai_model", provider.Model)
|
||||
poll := time.NewTicker(time.Second)
|
||||
defer poll.Stop()
|
||||
cleanup := time.NewTicker(24 * time.Hour)
|
||||
|
||||
Reference in New Issue
Block a user