优化ai初始化逻辑
This commit is contained in:
@@ -16,25 +16,25 @@ import (
|
||||
// geminiImpl 是 Gemini AI 服务的实现。
|
||||
type geminiImpl struct {
|
||||
client *genai.GenerativeModel
|
||||
cfg *config.Gemini
|
||||
cfg config.Gemini
|
||||
}
|
||||
|
||||
// NewGeminiAI 创建一个新的 geminiImpl 实例。
|
||||
func NewGeminiAI(ctx context.Context, cfg *config.AIConfig) (AI, error) {
|
||||
func NewGeminiAI(ctx context.Context, cfg config.Gemini) (AI, error) {
|
||||
// 检查 API Key 是否存在
|
||||
if cfg.Gemini.APIKey == "" {
|
||||
if cfg.APIKey == "" {
|
||||
return nil, fmt.Errorf("Gemini API Key 未配置")
|
||||
}
|
||||
|
||||
// 创建 Gemini 客户端
|
||||
genaiClient, err := genai.NewClient(ctx, option.WithAPIKey(cfg.Gemini.APIKey))
|
||||
genaiClient, err := genai.NewClient(ctx, option.WithAPIKey(cfg.APIKey))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("创建 Gemini 客户端失败: %w", err)
|
||||
}
|
||||
|
||||
return &geminiImpl{
|
||||
client: genaiClient.GenerativeModel(cfg.Gemini.ModelName),
|
||||
cfg: &cfg.Gemini,
|
||||
client: genaiClient.GenerativeModel(cfg.ModelName),
|
||||
cfg: cfg,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user