Fix usage

This commit is contained in:
Adrien Bouvais 2024-05-22 20:06:07 +02:00
parent cae9dfa5fc
commit d5ab5a8e7c
5 changed files with 19 additions and 11 deletions

View File

@ -165,11 +165,12 @@ func RequestAnthropic(model string, messages []Message, maxTokens int, temperatu
var usedModelInfo ModelInfo
edgeClient.QuerySingle(edgeCtx, `
Select ModelInfo {
SELECT ModelInfo {
inputPrice,
outputPrice
}
FILTER .name = <str>$0
FILTER .modelID = <str>$0
LIMIT 1
`, &usedModelInfo, model)
var inputCost float32 = float32(chatCompletionResponse.Usage.InputTokens) * usedModelInfo.InputPrice

View File

@ -172,11 +172,12 @@ func RequestGoogle(model string, messages []Message, temperature float64) (Opena
var usedModelInfo ModelInfo
edgeClient.QuerySingle(edgeCtx, `
Select ModelInfo {
SELECT ModelInfo {
inputPrice,
outputPrice
}
Filter ModelInfo.model = <str>$0
FILTER .modelID = <str>$0
LIMIT 1
`, &usedModelInfo, model)
var inputCost float32 = float32(chatCompletionResponse.Usage.PromptTokens) * usedModelInfo.InputPrice

View File

@ -163,11 +163,12 @@ func RequestGroq(model string, messages []Message, temperature float64) (GroqCha
var usedModelInfo ModelInfo
edgeClient.QuerySingle(edgeCtx, `
Select ModelInfo {
SELECT ModelInfo {
inputPrice,
outputPrice
}
Filter ModelInfo.model = <str>$0
FILTER .modelID = <str>$0
LIMIT 1
`, &usedModelInfo, model)
var inputCost float32 = float32(chatCompletionResponse.Usage.PromptTokens) * usedModelInfo.InputPrice

View File

@ -170,11 +170,12 @@ func RequestMistral(model string, messages []Message, temperature float64) (Mist
var usedModelInfo ModelInfo
edgeClient.QuerySingle(edgeCtx, `
Select ModelInfo {
SELECT ModelInfo {
inputPrice,
outputPrice
}
Filter ModelInfo.model = <str>$0
FILTER .modelID = <str>$0
LIMIT 1
`, &usedModelInfo, model)
var inputCost float32 = float32(chatCompletionResponse.Usage.PromptTokens) * usedModelInfo.InputPrice

View File

@ -162,13 +162,17 @@ func RequestOpenai(model string, messages []Message, temperature float64) (Opena
}
var usedModelInfo ModelInfo
edgeClient.QuerySingle(edgeCtx, `
Select ModelInfo {
err = edgeClient.QuerySingle(edgeCtx, `
SELECT ModelInfo {
inputPrice,
outputPrice
}
Filter ModelInfo.model = <str>$0
FILTER .modelID = <str>$0
LIMIT 1
`, &usedModelInfo, model)
if err != nil {
return OpenaiChatCompletionResponse{}, fmt.Errorf("error getting model info: %w", err)
}
var inputCost float32 = float32(chatCompletionResponse.Usage.PromptTokens) * usedModelInfo.InputPrice
var outputCost float32 = float32(chatCompletionResponse.Usage.CompletionTokens) * usedModelInfo.OutputPrice