Skip to content

Commit

Permalink
fix price calculation when http responses are not okay
Browse files Browse the repository at this point in the history
  • Loading branch information
spikelu2016 committed Mar 28, 2024
1 parent 9e4a3d6 commit a4b8991
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions internal/message/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ func (h *Handler) decorateEvent(m Message) error {
e.Event.PromptTokenCount = tks

e.Event.CompletionTokenCount = completiontks
e.Event.CostInUsd = completionCost + cost
if e.Event.Status == http.StatusOK {
e.Event.CostInUsd = completionCost + cost
}
}

if e.Event.Path == "/api/providers/azure/openai/deployments/:deployment_id/chat/completions" {
Expand Down Expand Up @@ -359,7 +361,10 @@ func (h *Handler) decorateEvent(m Message) error {

e.Event.PromptTokenCount = tks
e.Event.CompletionTokenCount = completiontks
e.Event.CostInUsd = cost + completionCost

if e.Event.Status == http.StatusOK {
e.Event.CostInUsd = cost + completionCost
}
}
}

Expand All @@ -386,7 +391,9 @@ func (h *Handler) decorateEvent(m Message) error {

e.Event.PromptTokenCount = tks
e.Event.CompletionTokenCount = completiontks
e.Event.CostInUsd = cost + completionCost
if e.Event.Status == http.StatusOK {
e.Event.CostInUsd = cost + completionCost
}
}
}

Expand Down

0 comments on commit a4b8991

Please sign in to comment.