From 57609a5e8a42cff235437f1ce080f92c5d80a3f8 Mon Sep 17 00:00:00 2001 From: CornHusker89 Date: Tue, 1 Oct 2024 09:47:15 -0700 Subject: [PATCH 1/3] add context tokens from api response to cost calculation --- ketchupbot-discord/GalaxyGPT.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ketchupbot-discord/GalaxyGPT.cs b/ketchupbot-discord/GalaxyGPT.cs index b1191b2..4d44d95 100644 --- a/ketchupbot-discord/GalaxyGPT.cs +++ b/ketchupbot-discord/GalaxyGPT.cs @@ -145,6 +145,8 @@ await message.ReplyAsync(""" if (verbose) { + if (int.TryParse(apiResponse.ContextTokens, out int contextTokens)) + answerMessage.AppendLine($"Context Tokens: {contextTokens}"); if (int.TryParse(apiResponse.QuestionTokens, out int questionTokens)) answerMessage.AppendLine($"Question Tokens: {questionTokens}"); if (int.TryParse(apiResponse.ResponseTokens, out int responseTokens)) @@ -153,7 +155,7 @@ await message.ReplyAsync(""" // NOTE: These numbers are hardcoded and not necessarily representative of the actual costs, as the model can change if (questionTokens != 0 && responseTokens != 0) answerMessage.AppendLine( - $"Cost: ${Math.Round(questionTokens * 0.00000015 + responseTokens * 0.0000006, 10)}"); + $"Cost: {Math.Round(contextTokens * 0.000015 + questionTokens * 0.000015 + responseTokens * 0.00006, 7)} Cents"); if (apiResponse.Duration != null) answerMessage.AppendLine( From d8bac64520e7d875d37927b8068c8c4dfeadde6f Mon Sep 17 00:00:00 2001 From: CornHusker89 Date: Tue, 1 Oct 2024 10:25:33 -0700 Subject: [PATCH 2/3] oops forgor to add property --- ketchupbot-discord/ApiResponse.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ketchupbot-discord/ApiResponse.cs b/ketchupbot-discord/ApiResponse.cs index d74b6d6..7f2cf02 100644 --- a/ketchupbot-discord/ApiResponse.cs +++ b/ketchupbot-discord/ApiResponse.cs @@ -7,6 +7,8 @@ public class ApiResponse public required string Answer { get; init; } public string? Context { get; init; } + [JsonPropertyName("context_tokens")] public string? ContextTokens { get; init; } + [JsonPropertyName("question_tokens")] public string? QuestionTokens { get; init; } [JsonPropertyName("response_tokens")] public string? ResponseTokens { get; init; } From a4bcde1282a64b39a1f14fb73f21fc1cce8dc0cc Mon Sep 17 00:00:00 2001 From: CornHusker89 Date: Tue, 1 Oct 2024 10:47:48 -0700 Subject: [PATCH 3/3] added prompt tokens to cost calculation --- ketchupbot-discord/ApiResponse.cs | 2 ++ ketchupbot-discord/GalaxyGPT.cs | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ketchupbot-discord/ApiResponse.cs b/ketchupbot-discord/ApiResponse.cs index 7f2cf02..37f611c 100644 --- a/ketchupbot-discord/ApiResponse.cs +++ b/ketchupbot-discord/ApiResponse.cs @@ -7,6 +7,8 @@ public class ApiResponse public required string Answer { get; init; } public string? Context { get; init; } + [JsonPropertyName("prompt_tokens")] public string? PromptTokens { get; init; } + [JsonPropertyName("context_tokens")] public string? ContextTokens { get; init; } [JsonPropertyName("question_tokens")] public string? QuestionTokens { get; init; } diff --git a/ketchupbot-discord/GalaxyGPT.cs b/ketchupbot-discord/GalaxyGPT.cs index 4d44d95..c92f25f 100644 --- a/ketchupbot-discord/GalaxyGPT.cs +++ b/ketchupbot-discord/GalaxyGPT.cs @@ -145,6 +145,8 @@ await message.ReplyAsync(""" if (verbose) { + if (int.TryParse(apiResponse.PromptTokens, out int promptTokens)) + answerMessage.AppendLine($"Prompt Tokens: {promptTokens}"); if (int.TryParse(apiResponse.ContextTokens, out int contextTokens)) answerMessage.AppendLine($"Context Tokens: {contextTokens}"); if (int.TryParse(apiResponse.QuestionTokens, out int questionTokens)) @@ -153,9 +155,9 @@ await message.ReplyAsync(""" answerMessage.AppendLine($"Response Tokens: {responseTokens}"); // NOTE: These numbers are hardcoded and not necessarily representative of the actual costs, as the model can change - if (questionTokens != 0 && responseTokens != 0) + if (promptTokens != 0 && contextTokens != 0 && questionTokens != 0 && responseTokens != 0) answerMessage.AppendLine( - $"Cost: {Math.Round(contextTokens * 0.000015 + questionTokens * 0.000015 + responseTokens * 0.00006, 7)} Cents"); + $"Cost: {Math.Round(promptTokens * 0.000015 + contextTokens * 0.000015 + questionTokens * 0.000015 + responseTokens * 0.00006, 7)} Cents"); if (apiResponse.Duration != null) answerMessage.AppendLine(