Document invocation observation and cost reporting

This commit is contained in:
2026-11-22 18:38:11 +00:00
parent d4509b163e
commit 20c5ea47af
22 changed files with 231 additions and 52 deletions

View File

@@ -1,12 +1,29 @@
package promptkit_test
import (
"context"
"math"
"testing"
"go.maximumdirect.net/promptkit"
)
func TestDuplicateContextAndRequestGroupEnrollment(t *testing.T) {
charge := .5
engine := costEngine(t, false, nil, promptkit.WithLLMClient(observationClientFunc(func(context.Context, promptkit.GenerateRequest) (*promptkit.GenerateResponse, error) {
return &promptkit.GenerateResponse{Content: "ok", CostUSD: &charge}, nil
})))
var group promptkit.ExecutionGroup
ctx := promptkit.WithExecutionObserver(context.Background(), group.Observe)
if _, err := engine.Run(ctx, promptkit.RunRequest{PromptID: "prompt", Observer: group.Observe}); err != nil {
t.Fatal(err)
}
got := group.Snapshot()
if len(got.Members) != 1 || got.Attempts != 1 || got.CostUSD.Value != .5 {
t.Fatalf("summary=%+v", got)
}
}
func TestCacheHitRatioUsesCompleteConsistentCounts(t *testing.T) {
known := func(v int) promptkit.ObservedTokenCount {
return promptkit.ObservedTokenCount{Value: v, Known: true, Complete: true}