feat(summary): send complete articles within user budget (#39)
This commit is contained in:
@ -79,7 +79,7 @@ func TestTicket36DTOThroughLayaAndSummaryWithStrictModelTruncation(t *testing.T)
|
||||
}
|
||||
articles := []any{}
|
||||
for _, url := range request.URLs {
|
||||
articles = append(articles, map[string]any{"url": url, "content": "Synthetic editorial detail.", "content_truncated": true, "published_at": nil})
|
||||
articles = append(articles, map[string]any{"url": url, "content": "Synthetic editorial detail.", "content_truncated": false, "content_state": "complete", "published_at": nil})
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"articles": articles})
|
||||
}))
|
||||
@ -100,7 +100,7 @@ func TestTicket36DTOThroughLayaAndSummaryWithStrictModelTruncation(t *testing.T)
|
||||
results := []any{}
|
||||
for _, state := range body.States {
|
||||
if mode == "title_content" {
|
||||
if state["content"] != "Synthetic editorial detail." || state["content_truncated"] != true {
|
||||
if state["content"] != "Synthetic editorial detail." || state["content_truncated"] != nil {
|
||||
t.Error("content/limit flag missing from Laya")
|
||||
}
|
||||
} else if state["content"] != nil || state["content_truncated"] != nil {
|
||||
@ -113,7 +113,7 @@ func TestTicket36DTOThroughLayaAndSummaryWithStrictModelTruncation(t *testing.T)
|
||||
})}
|
||||
repo := &contentRepo{mode: mode}
|
||||
provider := &contentProvider{}
|
||||
uc := generation.NewUseCase(generation.Dependencies{Repository: repo, Decider: ranker, Summarizer: generationSummarizer{provider: provider}, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: enrichedFeed{bloomberg.New(service.URL)}}})
|
||||
uc := generation.NewUseCase(generation.Dependencies{Repository: repo, Decider: ranker, Summarizer: generationSummarizer{providerName: "gemini", model: "gemini-2.5-flash", provider: provider}, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: enrichedFeed{bloomberg.New(service.URL)}}})
|
||||
result, err := uc.Generate(context.Background(), "fixture")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -126,7 +126,7 @@ func TestTicket36DTOThroughLayaAndSummaryWithStrictModelTruncation(t *testing.T)
|
||||
if result.Summary == nil || provider.calls != 1 {
|
||||
t.Fatal(result.Outcome)
|
||||
}
|
||||
contains := strings.Contains(provider.prompt, "Synthetic editorial detail.") && strings.Contains(provider.prompt, `"content_truncated":true`)
|
||||
contains := strings.Contains(provider.prompt, "Synthetic editorial detail.") && !strings.Contains(provider.prompt, `"content_truncated":true`)
|
||||
if contains != (mode == "title_content") {
|
||||
t.Fatal("summary mode/limit metadata incorrect")
|
||||
}
|
||||
@ -143,7 +143,7 @@ func TestTicket36DTOThroughLayaAndSummaryWithStrictModelTruncation(t *testing.T)
|
||||
}
|
||||
|
||||
func TestTicket36ReviewRankingContentBudget(t *testing.T) {
|
||||
c := generation.Candidate{Article: scraper.Article{Title: "Preserved title", Content: strings.Repeat("é漢🙂<&", 4096)}}
|
||||
c := generation.Candidate{Article: scraper.Article{Title: "Preserved title", ContentState: scraper.ContentComplete, Content: strings.Repeat("é漢🙂<&", 4096)}}
|
||||
state := layaArticleState([]map[string]string{{"name": "Preserved identity", "symbol": "FIX"}}, c, "title_content")
|
||||
data, err := json.Marshal(state)
|
||||
if err != nil || len(data) > layaStateByteBudget {
|
||||
@ -165,35 +165,18 @@ func TestTicket36ReviewSummaryAggregateBudget(t *testing.T) {
|
||||
p := &contentProvider{}
|
||||
candidates := make([]generation.Candidate, 200)
|
||||
for i := range candidates {
|
||||
candidates[i] = generation.Candidate{ID: fmt.Sprintf("id-%03d", i), Article: scraper.Article{Title: fmt.Sprintf("title-%03d", i), Content: strings.Repeat("漢🙂<&", 4096)}}
|
||||
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{provider: p}).Summarize(context.Background(), "fr", nil, candidates)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(p.prompt) > 24*1024 || !utf8.ValidString(p.prompt) {
|
||||
t.Fatalf("prompt bytes=%d exceeds 24KiB", len(p.prompt))
|
||||
}
|
||||
t.Logf("summary_prompt_bytes=%d budget=%d articles=%d", len(p.prompt), 24*1024, len(candidates))
|
||||
if strings.Count(p.prompt, `"content_truncated":true`) != len(candidates) {
|
||||
t.Fatal("missing explicit excerpt flags")
|
||||
}
|
||||
last := -1
|
||||
for i := range candidates {
|
||||
if !strings.Contains(p.prompt, candidates[i].ID) {
|
||||
t.Fatal("candidate ID lost")
|
||||
}
|
||||
at := strings.Index(p.prompt, candidates[i].Article.Title)
|
||||
if at <= last {
|
||||
t.Fatal("title/order lost")
|
||||
}
|
||||
last = at
|
||||
_, 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")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestTicket36ReviewImmutableMetadataTooLargeNeverCallsProvider(t *testing.T) {
|
||||
p := &contentProvider{}
|
||||
_, err := (generationSummarizer{provider: p}).Summarize(context.Background(), "fr", nil, []generation.Candidate{{ID: "preserved", Article: scraper.Article{Title: strings.Repeat("title", 6000)}}})
|
||||
_, err := (generationSummarizer{providerName: "gemini", model: "gemini-2.5-flash", provider: p}).Summarize(context.Background(), "fr", nil, []generation.Candidate{{ID: "preserved", Article: scraper.Article{Title: strings.Repeat("title", 60000)}}})
|
||||
if err == nil || p.calls != 0 {
|
||||
t.Fatal("oversized immutable prompt sent")
|
||||
}
|
||||
@ -203,7 +186,7 @@ func TestTicket36ReviewImmutableMetadataTooLargeNeverCallsProvider(t *testing.T)
|
||||
calls++
|
||||
return nil, fmt.Errorf("unexpected transport")
|
||||
})}
|
||||
got, err := r.Rank(context.Background(), "title_content", []models.UserAsset{{Name: "identity"}}, []generation.Candidate{{ID: "one", Article: scraper.Article{Title: strings.Repeat("title", 200), Content: "available body"}}})
|
||||
got, err := r.Rank(context.Background(), "title_content", []models.UserAsset{{Name: "identity"}}, []generation.Candidate{{ID: "one", Article: scraper.Article{Title: strings.Repeat("title", 200), ContentState: scraper.ContentComplete, Content: "available body"}}})
|
||||
if err == nil || got != nil || calls != 0 {
|
||||
t.Fatal("oversized immutable state sent")
|
||||
}
|
||||
@ -232,7 +215,7 @@ func TestTicket36ReviewSerializedHTTPStatesAreBounded(t *testing.T) {
|
||||
data, _ := json.Marshal(map[string]any{"results": results})
|
||||
return &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(string(data))), Header: make(http.Header)}, nil
|
||||
})}
|
||||
got, err := r.Rank(context.Background(), "title_content", []models.UserAsset{{Name: "exact identity", Symbol: "FIX"}}, []generation.Candidate{{ID: "one", Article: scraper.Article{Title: "exact title", Content: strings.Repeat("漢<&🙂", 4096)}}})
|
||||
got, err := r.Rank(context.Background(), "title_content", []models.UserAsset{{Name: "exact identity", Symbol: "FIX"}}, []generation.Candidate{{ID: "one", Article: scraper.Article{Title: "exact title", ContentState: scraper.ContentComplete, Content: strings.Repeat("漢<&🙂", 4096)}}})
|
||||
if err != nil || len(got) != 1 || states != 1 {
|
||||
t.Fatalf("states=%d err=%v", states, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user