feat(generation): enforce prompt budget with whole article eviction (#47)
This commit is contained in:
@ -4,27 +4,21 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/tradarr/backend/internal/generation"
|
||||
"github.com/tradarr/backend/internal/scraper"
|
||||
"github.com/tradarr/backend/internal/summarybudget"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTicket39FixtureCapacityStillEnforcesAdmission(t *testing.T) {
|
||||
func TestTicket39FixtureUsesAccountBudgetWithoutModelCapacity(t *testing.T) {
|
||||
provider := &incident37Provider{}
|
||||
lookup := func(source, model string) (summarybudget.Profile, bool) {
|
||||
return summarybudget.Profile{ContextWindowTokens: 8192, InputLimitTokens: 8192, OutputReserveTokens: 1024, Counter: summarybudget.UTF8UpperBound, FramingTokens: 1024}, source == "ollama" && model == "fake-summary"
|
||||
}
|
||||
a := fullGenerationSummarizer{provider: provider, providerName: "ollama", model: "fake-summary", profileLookup: lookup}
|
||||
req := generation.SummaryRequest{Language: "en", Budget: 250000}
|
||||
_, usage, err := a.SummarizeWithBudget(context.Background(), req)
|
||||
if err != nil || provider.calls != 1 || usage.EffectiveTokens != 7168 {
|
||||
t.Fatal("explicit fixture capacity not used", err)
|
||||
a := fullGenerationSummarizer{provider: provider, providerName: "ollama", model: "unrecognized"}
|
||||
req := generation.SummaryRequest{Budget: 250000, Candidates: []generation.Candidate{{Article: scraper.Article{Content: "body"}}}}
|
||||
_, usage, _, err := a.SummarizeWithBudget(context.Background(), req)
|
||||
if err != nil || provider.calls != 1 || usage.EffectiveTokens != 250000 || provider.options.NumCtx != 0 {
|
||||
t.Fatal("model capacity applied", err)
|
||||
}
|
||||
req.Budget = 1
|
||||
if _, _, err = a.SummarizeWithBudget(context.Background(), req); !errors.Is(err, summarybudget.ErrExceeded) || provider.calls != 1 {
|
||||
t.Fatal("fixture bypassed budget admission")
|
||||
}
|
||||
a.model = "unrecognized"
|
||||
if _, _, err = a.SummarizeWithBudget(context.Background(), req); !errors.Is(err, summarybudget.ErrUnknown) || provider.calls != 1 {
|
||||
t.Fatal("fixture bypassed unknown-capacity guard")
|
||||
if _, _, _, err = a.SummarizeWithBudget(context.Background(), req); !errors.Is(err, summarybudget.ErrFixedContextExceeded) || provider.calls != 1 {
|
||||
t.Fatal("budget bypassed")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user