49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package generation
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"github.com/tradarr/backend/internal/models"
|
|
"strconv"
|
|
)
|
|
|
|
type RepositoryAdapter struct{ Repo *models.Repository }
|
|
|
|
func (r RepositoryAdapter) LoadUserInput(ctx context.Context, id string) (UserInput, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return UserInput{}, err
|
|
}
|
|
p, err := r.Repo.GetUserPreferences(id)
|
|
if err != nil {
|
|
return UserInput{}, err
|
|
}
|
|
assets, err := r.Repo.GetUserAssets(id)
|
|
if err != nil {
|
|
return UserInput{}, err
|
|
}
|
|
sources, err := r.Repo.ListSources()
|
|
if err != nil {
|
|
return UserInput{}, err
|
|
}
|
|
value, err := r.Repo.GetSetting("summary_max_articles")
|
|
if err != nil {
|
|
return UserInput{}, err
|
|
}
|
|
limit, _ := strconv.Atoi(value)
|
|
if value == "" {
|
|
limit = 50
|
|
}
|
|
summaryContext, err := r.Repo.GetSetting("ai_system_prompt")
|
|
if err != nil {
|
|
return UserInput{}, err
|
|
}
|
|
return UserInput{RankingModelID: p.RankingModelID, SummaryContext: summaryContext, SummaryPromptTokenBudget: p.SummaryPromptTokenBudget, SummaryModelID: p.SummaryModelID, Language: p.Language, RankingMode: p.RankingMode, GlobalLimit: limit, Assets: assets, Sources: models.OperationalSources(sources)}, nil
|
|
}
|
|
func (r RepositoryAdapter) SaveGeneration(ctx context.Context, id string, record GenerationRecord) error {
|
|
payload, err := json.Marshal(record.Outcome)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return r.Repo.SaveGeneration(ctx, id, record.Outcome.ID, record.Summary, payload, record.Outcome.CreatedAt)
|
|
}
|