优化ai初始化逻辑
This commit is contained in:
@@ -35,7 +35,7 @@ type Infrastructure struct {
|
||||
storage database.Storage
|
||||
repos *Repositories
|
||||
lora *LoraComponents
|
||||
aiManager infra_ai.AI
|
||||
ai infra_ai.AI
|
||||
tokenGenerator token.Generator
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ func initInfrastructure(ctx context.Context, cfg *config.Config) (*Infrastructur
|
||||
tokenGenerator := token.NewTokenGenerator([]byte(cfg.App.JWTSecret))
|
||||
|
||||
// 初始化 AI
|
||||
aiManager, err := infra_ai.NewGeminiAI(logs.AddCompName(ctx, "GeminiAI"), &cfg.AI)
|
||||
ai, err := initAI(ctx, cfg.AI)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("初始化 AI 管理器失败: %w", err)
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func initInfrastructure(ctx context.Context, cfg *config.Config) (*Infrastructur
|
||||
storage: storage,
|
||||
repos: repos,
|
||||
lora: lora,
|
||||
aiManager: aiManager,
|
||||
ai: ai,
|
||||
tokenGenerator: tokenGenerator,
|
||||
}, nil
|
||||
}
|
||||
@@ -248,7 +248,7 @@ func initDomainServices(ctx context.Context, cfg *config.Config, infra *Infrastr
|
||||
recipeCoreService,
|
||||
recipeGenerateManager,
|
||||
infra.repos.recipeRepo,
|
||||
infra.aiManager,
|
||||
infra.ai,
|
||||
)
|
||||
|
||||
return &DomainServices{
|
||||
@@ -519,3 +519,12 @@ func initStorage(ctx context.Context, cfg config.DatabaseConfig) (database.Stora
|
||||
logs.GetLogger(ctx).Info("数据库初始化完成。")
|
||||
return storage, nil
|
||||
}
|
||||
|
||||
func initAI(ctx context.Context, cfg config.AIConfig) (infra_ai.AI, error) {
|
||||
switch cfg.Model {
|
||||
case models.AI_MODEL_GEMINI:
|
||||
return infra_ai.NewGeminiAI(ctx, cfg.Gemini)
|
||||
default:
|
||||
return infra_ai.NewNoneAI(ctx), nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user