fix: estimate image gen tokens from prompt length instead of hardcoding
This commit is contained in:
@@ -558,10 +558,16 @@ func (s *Server) handleImageGenerations(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Estimate tokens from prompt text (~4 chars per token)
|
||||||
|
promptTokens := uint32(len(req.Prompt) / 4)
|
||||||
|
if promptTokens < 1 {
|
||||||
|
promptTokens = 1
|
||||||
|
}
|
||||||
|
|
||||||
s.logRequest(startTime, clientID, providerName, req.Model, &models.Usage{
|
s.logRequest(startTime, clientID, providerName, req.Model, &models.Usage{
|
||||||
PromptTokens: 1,
|
PromptTokens: promptTokens,
|
||||||
CompletionTokens: uint32(len(resp.Data)),
|
CompletionTokens: uint32(len(resp.Data)),
|
||||||
TotalTokens: 1 + uint32(len(resp.Data)),
|
TotalTokens: promptTokens + uint32(len(resp.Data)),
|
||||||
}, nil, false)
|
}, nil, false)
|
||||||
|
|
||||||
c.JSON(http.StatusOK, resp)
|
c.JSON(http.StatusOK, resp)
|
||||||
|
|||||||
Reference in New Issue
Block a user