From f5d57e6973fa52b494bb084a99253da5dae8dad8 Mon Sep 17 00:00:00 2001 From: Stephen von Takach Date: Fri, 3 Nov 2023 11:48:39 +1100 Subject: [PATCH] feat(chat.cr): add helper for tracking token usage --- src/openai/api/chat.cr | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/openai/api/chat.cr b/src/openai/api/chat.cr index b01df0e..2de687d 100644 --- a/src/openai/api/chat.cr +++ b/src/openai/api/chat.cr @@ -107,7 +107,10 @@ module OpenAI # The name and arguments of a function that should be called, as generated by the model. getter function_call : ChatFunctionCall? - def initialize(@role, @content = nil, @name = nil, @function_call = nil) + @[JSON::Field(ignore: true)] + property tokens : Int32 = 0 + + def initialize(@role, @content = nil, @name = nil, @function_call = nil, @tokens = 0) end end