Skip to content

Commit

Permalink
add basic pricing based on max out tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
kyriediculous committed Aug 1, 2024
1 parent 03e0059 commit a39333c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion server/ai_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,13 @@ func handleAIRequest(ctx context.Context, w http.ResponseWriter, r *http.Request
return orch.LlmGenerate(ctx, v)
}

// TODO: handle tokens for pricing
if v.MaxTokens == nil {
respondWithError(w, "MaxTokens not specified", http.StatusBadRequest)
return
}

// TODO: Improve pricing
outPixels = int64(*v.MaxTokens)
default:
respondWithError(w, "Unknown request type", http.StatusBadRequest)
return
Expand Down
8 changes: 6 additions & 2 deletions server/ai_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,12 @@ func submitLlmGenerate(ctx context.Context, params aiRequestParams, sess *AISess
return nil, err
}

// TODO: calculate payment
setHeaders, balUpdate, err := prepareAIPayment(ctx, sess, 0)
// TODO: Improve pricing
if req.MaxTokens == nil {
req.MaxTokens = new(int)
*req.MaxTokens = 256
}
setHeaders, balUpdate, err := prepareAIPayment(ctx, sess, int64(*req.MaxTokens))
if err != nil {
if monitor.Enabled {
monitor.AIRequestError(err.Error(), "llm-generate", *req.ModelId, sess.OrchestratorInfo)
Expand Down

0 comments on commit a39333c

Please sign in to comment.