feat(ai): add Groq/OpenAI-compat provider as default, keep Gemini as option
This commit is contained in:
+13
-11
@@ -1,7 +1,7 @@
|
||||
// internal/ai/provider.go
|
||||
// Дата: 2026-03-12
|
||||
// Дата: 2026-03-12 (обновлён 2026-03-12: добавлен Groq / OpenAI-compat)
|
||||
// Интерфейс LLMProvider — абстракция над любым LLM-бэкендом.
|
||||
// Сейчас реализован Google Gemini. В будущем — облачный LLM (drop-in замена).
|
||||
// Реализации: Google Gemini, Groq (OpenAI-compat), облачный LLM (stub).
|
||||
|
||||
package ai
|
||||
|
||||
@@ -18,13 +18,17 @@ type LLMProvider interface {
|
||||
|
||||
// Config — конфигурация анализатора, читается из env-переменных.
|
||||
type Config struct {
|
||||
// Provider: "google" или "cloud" (в будущем)
|
||||
// Provider: "groq" (по умолчанию), "google", "cloud"
|
||||
Provider string
|
||||
// HintLevel: 0–5, если 0 — AI не вызывается
|
||||
HintLevel int
|
||||
// Google Gemini
|
||||
// Groq / OpenAI-совместимые провайдеры
|
||||
GroqAPIKey string
|
||||
GroqModel string // по умолчанию "llama-3.3-70b-versatile"
|
||||
GroqEndpoint string // по умолчанию https://api.groq.com/openai/v1/chat/completions
|
||||
// Google Gemini (геоблок в РФ)
|
||||
GoogleAPIKey string
|
||||
GoogleModel string // по умолчанию "gemini-pro"
|
||||
GoogleModel string // по умолчанию "gemini-2.0-flash"
|
||||
// Будущий облачный LLM
|
||||
CloudEndpoint string
|
||||
CloudToken string
|
||||
@@ -34,6 +38,8 @@ type Config struct {
|
||||
// При добавлении нового провайдера — только сюда добавить case.
|
||||
func NewProvider(cfg Config) (LLMProvider, error) {
|
||||
switch cfg.Provider {
|
||||
case "groq":
|
||||
return NewOpenAICompatProvider(cfg.GroqEndpoint, cfg.GroqAPIKey, cfg.GroqModel)
|
||||
case "google":
|
||||
model := cfg.GoogleModel
|
||||
if model == "" {
|
||||
@@ -43,11 +49,7 @@ func NewProvider(cfg Config) (LLMProvider, error) {
|
||||
case "cloud":
|
||||
return NewCloudLLMProvider(cfg.CloudEndpoint, cfg.CloudToken)
|
||||
default:
|
||||
// По умолчанию google, если AI_PROVIDER не задан
|
||||
model := cfg.GoogleModel
|
||||
if model == "" {
|
||||
model = "gemini-2.0-flash"
|
||||
}
|
||||
return NewGeminiProvider(cfg.GoogleAPIKey, model)
|
||||
// По умолчанию groq — работает из РФ без геоблоков
|
||||
return NewOpenAICompatProvider(cfg.GroqEndpoint, cfg.GroqAPIKey, cfg.GroqModel)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user