OpenAI: Add Usage to v1/embeddings (#5886)

* add prompt tokens to embed response

* rm slog

* metrics

* types

* prompt n

* clean up

* reset submodule

* add tokens to v1/embeddings

* separate usage
This commit is contained in:
royjhan 2024-08-01 18:49:37 -04:00 committed by GitHub
parent f561eecfb8
commit 6f133a0bdd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -164,9 +164,15 @@ type ListCompletion struct {
} }
type EmbeddingList struct { type EmbeddingList struct {
Object string `json:"object"` Object string `json:"object"`
Data []Embedding `json:"data"` Data []Embedding `json:"data"`
Model string `json:"model"` Model string `json:"model"`
Usage EmbeddingUsage `json:"usage,omitempty"`
}
type EmbeddingUsage struct {
PromptTokens int `json:"prompt_tokens"`
TotalTokens int `json:"total_tokens"`
} }
func NewError(code int, message string) ErrorResponse { func NewError(code int, message string) ErrorResponse {
@ -332,6 +338,10 @@ func toEmbeddingList(model string, r api.EmbedResponse) EmbeddingList {
Object: "list", Object: "list",
Data: data, Data: data,
Model: model, Model: model,
Usage: EmbeddingUsage{
PromptTokens: r.PromptEvalCount,
TotalTokens: r.PromptEvalCount,
},
} }
} }