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.
73 lines
No EOL
1.5 KiB
Go
73 lines
No EOL
1.5 KiB
Go
//go:build cgo && sqlite_fts5
|
|
|
|
package bench
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
)
|
|
|
|
func openMattn(b *testing.B) *sql.DB {
|
|
b.Helper()
|
|
tmpDir := b.TempDir()
|
|
dsn := filepath.Join(tmpDir, "bench.db")
|
|
db, err := sql.Open("sqlite3", dsn+"?_journal_mode=WAL&_synchronous=NORMAL")
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
db.SetMaxOpenConns(1)
|
|
if _, err := db.ExecContext(context.Background(), schema); err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
b.Cleanup(func() { _ = db.Close() })
|
|
return db
|
|
}
|
|
|
|
func BenchmarkInsert_Mattn(b *testing.B) {
|
|
rows := loadChunks(b, dataPath)
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
db := openMattn(b)
|
|
if err := insertAll(context.Background(), db, rows); err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func BenchmarkQuery_Mattn(b *testing.B) {
|
|
db := openMattn(b)
|
|
rows := loadChunks(b, dataPath)
|
|
if err := insertAll(context.Background(), db, rows); err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
ctx := context.Background()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
for _, q := range queries {
|
|
if _, _, err := runQuery(ctx, db, q); err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func BenchmarkRoundTrip_Mattn(b *testing.B) {
|
|
rows := loadChunks(b, dataPath)
|
|
ctx := context.Background()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
db := openMattn(b)
|
|
if err := insertAll(ctx, db, rows); err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
for _, q := range queries {
|
|
if _, _, err := runQuery(ctx, db, q); err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
} |