Report costs for ordinary runs
This commit is contained in:
@@ -137,6 +137,9 @@ func NewRunnerWithRepairer(
|
||||
}
|
||||
|
||||
func (r *Runner) Run(ctx context.Context, req domain.RunRequest) (*domain.RunResult, error) {
|
||||
if observation.CostFromContext(ctx) == nil {
|
||||
ctx = observation.WithCostAccumulator(ctx, &observation.CostAccumulator{})
|
||||
}
|
||||
recorder := observation.FromContext(ctx)
|
||||
runID := ""
|
||||
if recorder != nil {
|
||||
@@ -274,7 +277,7 @@ func (r *Runner) executePreparedRun(
|
||||
exchange = domain.CaptureExchange(parent, runID, prepared.Messages[parent.MessageCount():], genResp.Content)
|
||||
}
|
||||
|
||||
return &domain.RunResult{
|
||||
result := &domain.RunResult{
|
||||
Exchange: exchange,
|
||||
ParentRunID: prepared.ParentRunID,
|
||||
RunID: runID,
|
||||
@@ -295,7 +298,11 @@ func (r *Runner) executePreparedRun(
|
||||
StartTime: start,
|
||||
EndTime: end,
|
||||
Duration: end.Sub(start),
|
||||
}, nil
|
||||
}
|
||||
if cost := observation.CostFromContext(ctx); cost != nil {
|
||||
result.CostUSD = cost.Observed()
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func wrapGenerationError(err error) error {
|
||||
|
||||
Reference in New Issue
Block a user