Collect costs for dispatched model attempts
This commit is contained in:
@@ -1,11 +1,25 @@
|
||||
package observation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math"
|
||||
|
||||
"go.maximumdirect.net/promptkit/internal/domain"
|
||||
)
|
||||
|
||||
type costContextKey struct{}
|
||||
|
||||
// WithCostAccumulator carries one invocation's cost state.
|
||||
func WithCostAccumulator(ctx context.Context, accumulator *CostAccumulator) context.Context {
|
||||
return context.WithValue(ctx, costContextKey{}, accumulator)
|
||||
}
|
||||
|
||||
// CostFromContext returns the current invocation's cost state, if installed.
|
||||
func CostFromContext(ctx context.Context) *CostAccumulator {
|
||||
value, _ := ctx.Value(costContextKey{}).(*CostAccumulator)
|
||||
return value
|
||||
}
|
||||
|
||||
// ResolveCost applies reported-cost precedence over a configured-zero fallback.
|
||||
func ResolveCost(reported *float64, zeroCost bool) domain.ObservedCost {
|
||||
if reported != nil && !math.IsNaN(*reported) && !math.IsInf(*reported, 0) {
|
||||
|
||||
Reference in New Issue
Block a user