feat(qa): add synthesis conversations with source retention (#52)
This commit is contained in:
@ -17,6 +17,12 @@ type GenerationHistory struct {
|
||||
|
||||
// SaveGeneration deliberately accepts no article data and commits both rows together.
|
||||
func (r *Repository) SaveGeneration(ctx context.Context, userID, id string, summary *Summary, outcome json.RawMessage, createdAt time.Time) error {
|
||||
return r.saveGeneration(ctx, userID, id, summary, outcome, createdAt, nil, 0, false)
|
||||
}
|
||||
func (r *Repository) SaveGenerationWithQASources(ctx context.Context, userID, id string, summary *Summary, outcome json.RawMessage, createdAt time.Time, sources []SummarySourceArticle, days int) error {
|
||||
return r.saveGeneration(ctx, userID, id, summary, outcome, createdAt, sources, days, true)
|
||||
}
|
||||
func (r *Repository) saveGeneration(ctx context.Context, userID, id string, summary *Summary, outcome json.RawMessage, createdAt time.Time, sources []SummarySourceArticle, days int, withQA bool) error {
|
||||
tx, err := r.db.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -27,6 +33,11 @@ func (r *Repository) SaveGeneration(ctx context.Context, userID, id string, summ
|
||||
if _, err = tx.ExecContext(ctx, `INSERT INTO summaries (id,user_id,content,ai_provider_id,generated_at,summary_model_id,provider_name,model_name) VALUES ($1,$2,$3,$4,$5,$6,$7,$8)`, summary.ID, userID, summary.Content, summary.AIProviderID, summary.GeneratedAt, summary.SummaryModelID, summary.ProviderName, summary.ModelName); err != nil {
|
||||
return err
|
||||
}
|
||||
if withQA {
|
||||
if err = r.saveQASources(ctx, tx, userID, summary, sources, days); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
summaryID = &summary.ID
|
||||
}
|
||||
if _, err = tx.ExecContext(ctx, `INSERT INTO summary_generations (id,user_id,summary_id,outcome,created_at) VALUES ($1,$2,$3,$4,$5)`, id, userID, summaryID, string(outcome), createdAt); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user