feat(generation): enforce prompt budget with whole article eviction (#47)
This commit is contained in:
@ -168,8 +168,17 @@ func TestTicket36ReviewSummaryAggregateBudget(t *testing.T) {
|
||||
candidates[i] = generation.Candidate{ID: fmt.Sprintf("id-%03d", i), Article: scraper.Article{Title: fmt.Sprintf("title-%03d", i), ContentState: scraper.ContentComplete, Content: strings.Repeat("漢🙂<&", 4096)}}
|
||||
}
|
||||
_, err := (generationSummarizer{providerName: "gemini", model: "gemini-2.5-flash", provider: p}).Summarize(context.Background(), "fr", nil, candidates)
|
||||
if err == nil || p.calls != 0 {
|
||||
t.Fatal("full aggregate over budget must not be truncated or sent")
|
||||
if err != nil || p.calls != 1 || len(p.prompt)+1024 > 250000 {
|
||||
t.Fatal("budget fitting must retain complete articles within the account ceiling")
|
||||
}
|
||||
var payload struct{ Articles []struct{ Content string } }
|
||||
if json.Unmarshal([]byte(p.prompt[strings.Index(p.prompt, "\n")+1:]), &payload) != nil || len(payload.Articles) == 0 || len(payload.Articles) >= len(candidates) {
|
||||
t.Fatal("missing reduced article set")
|
||||
}
|
||||
for _, a := range payload.Articles {
|
||||
if a.Content != strings.Repeat("漢🙂<&", 4096) {
|
||||
t.Fatal("article body truncated")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user