Initial implementation of the bot: - cmd/chat-bot: CLI entrypoint (serve, reindex, ask, version) - internal/agent: LLM provider client + agent runner with RAG injection - internal/config: YAML config loader (providers, RAG, persona, server) - internal/i18n: response-language detection (EN/ES) - internal/persona: persona system prompt assembly from YAML - internal/portfolio: heading-based chunker + SQLite FTS5 indexer - internal/server: chi router with /api/chat (SSE), /api/health, /api/info, /api/reindex, middleware (RequestID, Logging, CORS, RateLimit) - internal/streaming: SSE protocol helpers (start, chunk, sources, done, error) - web/: drop-in vanilla-JS chat widget (no build, no deps) + demo + README - bench/: reproducible driver benchmark (modernc vs mattn SQLite) - configs/portfolio-bot.yaml: llama.cpp default provider, SQLite RAG, canine persona - docs/architecture.md / .es.md: aligned with SQLite FTS5 + llama.cpp decisions - data/projects/README*.md: project data documentation - README.md / .es.md: updated for current implementation All tests pass (go test ./...). Bot is functional end-to-end with the configured LLM provider.
52 lines
No EOL
1.4 KiB
Go
52 lines
No EOL
1.4 KiB
Go
package agent
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/VictorVargas/rony-llm-agent/pkg/llm"
|
|
"github.com/VictorVargas/rony-llm-agent/pkg/llm/providers/anthropic"
|
|
"github.com/VictorVargas/rony-llm-agent/pkg/llm/providers/llamacpp"
|
|
"github.com/VictorVargas/rony-llm-agent/pkg/llm/providers/openai"
|
|
|
|
"github.com/VictorVargas/rony-chat-bot/internal/config"
|
|
)
|
|
|
|
// NewClient constructs the upstream LLMClient for a given provider config.
|
|
// "ollama" is handled via the openai-compat adapter: Ollama exposes
|
|
// /v1/chat/completions on its own port, so the provider list stays small.
|
|
func NewClient(p config.Provider) (llm.LLMClient, error) {
|
|
switch p.Type {
|
|
case "llamacpp":
|
|
return llamacpp.New(llamacpp.Config{
|
|
BaseURL: defaultIfEmpty(p.Endpoint, "http://localhost:8080/v1"),
|
|
Model: p.Model,
|
|
ContextWindow: p.ContextSize,
|
|
MaxTokens: p.MaxTokens,
|
|
Temperature: p.Temperature,
|
|
})
|
|
case "ollama", "openai":
|
|
return openai.New(openai.Config{
|
|
BaseURL: defaultIfEmpty(p.Endpoint, "http://localhost:11434/v1"),
|
|
Model: p.Model,
|
|
})
|
|
case "anthropic":
|
|
apiKey := ""
|
|
if p.APIKeyEnv != "" {
|
|
apiKey = os.Getenv(p.APIKeyEnv)
|
|
}
|
|
return anthropic.New(anthropic.Config{
|
|
APIKey: apiKey,
|
|
Model: p.Model,
|
|
})
|
|
default:
|
|
return nil, fmt.Errorf("unknown provider type %q (supported: llamacpp, ollama, openai, anthropic)", p.Type)
|
|
}
|
|
}
|
|
|
|
func defaultIfEmpty(s, def string) string {
|
|
if s == "" {
|
|
return def
|
|
}
|
|
return s
|
|
} |