Document invocation observation and cost reporting
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user