changing to use openrouter
This commit is contained in:
@@ -2,50 +2,11 @@ package agent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"mindforge.cronjob/internal/llm"
|
||||
)
|
||||
|
||||
// Provider represents the LLM provider to use.
|
||||
type Provider string
|
||||
|
||||
const (
|
||||
ProviderOpenAI Provider = "openai"
|
||||
ProviderGemini Provider = "gemini"
|
||||
)
|
||||
|
||||
// providerFromEnv reads the provider for a given agent from an env var,
|
||||
// defaulting to OpenAI if not set or unrecognised.
|
||||
func providerFromEnv(envKey string) Provider {
|
||||
val := strings.ToLower(strings.TrimSpace(os.Getenv(envKey)))
|
||||
if val == string(ProviderGemini) {
|
||||
return ProviderGemini
|
||||
}
|
||||
return ProviderOpenAI
|
||||
}
|
||||
|
||||
// send routes the request to the given LLM provider.
|
||||
func send(provider Provider, systemPrompt, userPrompt string) (string, error) {
|
||||
llmService := llm.NewLLMService()
|
||||
switch provider {
|
||||
case ProviderGemini:
|
||||
geminiModel := os.Getenv("GEMINI_MODEL")
|
||||
if geminiModel == "" {
|
||||
geminiModel = "gemini-3.1-flash-lite-preview"
|
||||
}
|
||||
return llmService.SendGeminiRequest(systemPrompt, userPrompt, geminiModel)
|
||||
default:
|
||||
openaiModel := os.Getenv("OPENAI_MODEL")
|
||||
if openaiModel == "" {
|
||||
openaiModel = "gpt-5-mini"
|
||||
}
|
||||
return llmService.SendOpenAIRequest(systemPrompt, userPrompt, openaiModel)
|
||||
}
|
||||
}
|
||||
|
||||
// SummaryCreatorAgent creates a summary of the git diff for a specific file.
|
||||
func SummaryCreatorAgent(filePath, gitDiff string) (string, error) {
|
||||
fileName := filepath.Base(filePath)
|
||||
@@ -66,7 +27,7 @@ Responda sempre em Português do Brasil (pt-BR).`
|
||||
|
||||
userPrompt := fmt.Sprintf("Caminho do arquivo: %s\nPasta (Assunto Principal): %s\nArquivo (Assunto Específico): %s\n\nGit Diff:\n%s", filePath, folderName, fileName, gitDiff)
|
||||
|
||||
return send(providerFromEnv("SUMMARY_CREATOR_PROVIDER"), systemPrompt, userPrompt)
|
||||
return llm.NewLLMService().Send(systemPrompt, userPrompt)
|
||||
}
|
||||
|
||||
// SummaryFormatterAgent formats a plain text summary into Markdown.
|
||||
@@ -82,5 +43,5 @@ Regras de formatação:
|
||||
|
||||
Responda sempre em Português do Brasil (pt-BR).`
|
||||
|
||||
return send(providerFromEnv("SUMMARY_FORMATTER_PROVIDER"), systemPrompt, summary)
|
||||
return llm.NewLLMService().Send(systemPrompt, summary)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user