feat(ai): add personal summary models and retire Q&A

Add an admin-managed provider model catalog with per-user summary selection, migration backfill, and generation snapshots. Retire report creation and messaging while preserving owner-scoped history.

Refs #15 #16

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 20:45:21 +01:00
parent ac17d27f51
commit 989996fbd6
53 changed files with 2228 additions and 979 deletions

View File

@ -11,10 +11,13 @@ import (
"sync"
"github.com/tradarr/backend/internal/ai"
"github.com/tradarr/backend/internal/generation"
"github.com/tradarr/backend/internal/models"
"github.com/tradarr/backend/internal/scraper"
)
type Fixtures struct {
SummaryModelID string `json:"summaryModelID"`
IndexQuery string `json:"indexQuery"`
IndexName string `json:"indexName"`
IndexSymbol string `json:"indexSymbol"`
@ -27,10 +30,11 @@ type Fixtures struct {
}
func DefaultFixtures() Fixtures {
return Fixtures{"E2E index", "E2E Financial Index", "E2EIDX", "BBG000E2E001", "E2E synthesized financial summary", "E2E private article title", "https://fixture.invalid/private-article", "E2E private article body", "pending-candidate-id"}
return Fixtures{"00000000-0000-0000-0000-000000001203", "E2E index", "E2E Financial Index", "E2EIDX", "BBG000E2E001", "E2E synthesized financial summary", "E2E private article title", "https://fixture.invalid/private-article", "E2E private article body", "pending-candidate-id"}
}
type Event struct {
Model string `json:"model,omitempty"`
Kind string `json:"kind"`
Symbols []string `json:"symbols,omitempty"`
CandidateID string `json:"candidate_id,omitempty"`
@ -83,6 +87,7 @@ func (f *Fakes) Handler() http.Handler {
var req struct {
Prompt string `json:"prompt"`
Format string `json:"format"`
Model string `json:"model"`
}
if r.Method != "POST" || json.NewDecoder(r.Body).Decode(&req) != nil {
http.Error(w, "invalid fixture provider", 400)
@ -113,7 +118,7 @@ func (f *Fakes) Handler() http.Handler {
encoded, _ := json.Marshal(map[string]any{"ranked_article_ids": []string{id}})
response = string(encoded)
} else {
f.record(Event{Kind: "layaSummaryCalls"})
f.record(Event{Kind: "layaSummaryCalls", Model: req.Model})
}
_ = json.NewEncoder(w).Encode(map[string]string{"response": response})
})
@ -158,6 +163,7 @@ func (s FakeScraper) Scrape(ctx context.Context, symbols []string) ([]scraper.Ar
}
type FakeProvider struct {
Model string
URL string
Client *http.Client
}
@ -168,7 +174,11 @@ func (p FakeProvider) Summarize(ctx context.Context, prompt string, opts ai.GenO
if err := ValidateURL(p.URL, false); err != nil {
return "", err
}
body := map[string]any{"prompt": prompt, "model": "fake-laya", "stream": false}
model := p.Model
if model == "" {
model = "fake-laya"
}
body := map[string]any{"prompt": prompt, "model": model, "stream": false}
if opts.JSONMode {
body["format"] = "json"
}
@ -191,3 +201,29 @@ func (p FakeProvider) Summarize(ctx context.Context, prompt string, opts ai.GenO
err = json.NewDecoder(resp.Body).Decode(&result)
return result.Response, err
}
// FakeLayaRanker is explicitly test-only. No production Laya implementation is
// inferred from an Ollama/provider role; the real adapter remains unavailable.
type FakeLayaRanker struct{ Provider FakeProvider }
func (f FakeLayaRanker) Rank(ctx context.Context, mode string, assets []models.UserAsset, candidates []generation.Candidate) ([]generation.Candidate, error) {
articles := []models.Article{}
byID := map[string]generation.Candidate{}
labels := []string{}
for _, a := range assets {
labels = append(labels, a.Name+" ("+a.Symbol+")")
}
for _, c := range candidates {
articles = append(articles, models.Article{ID: c.ID, Title: c.Article.Title, Content: c.Article.Content})
byID[c.ID] = c
}
ranked, err := ai.RankArticles(ctx, f.Provider, labels, articles, 20, mode)
if err != nil {
return nil, err
}
result := []generation.Candidate{}
for _, a := range ranked {
result = append(result, byID[a.ID])
}
return result, nil
}