gpt-tokenizer icon indicating copy to clipboard operation
gpt-tokenizer copied to clipboard

Support function calls?

Open seoker opened this issue 2 years ago • 3 comments
trafficstars

As you may know, function calls are now supported by OpenAI, and the function call tokens will be taken into account. With some googling, I found the calculation here.

It will be great if the library could also calculate the required tokens when using with function calls. 🙏🏼

seoker avatar Jun 29 '23 10:06 seoker

One related issue is the type signature of ChatMessage. Depending on whether there is functional calling, the ChatMessage may have either the content field or the function_call field, but not both. The current typing in gpt-tokenizer/src/GptEncoding.ts will need an update.

chuanqisun avatar Jul 24 '23 17:07 chuanqisun

I saw that https://github.com/hmarr/openai-chat-tokens already does it - would it be fine to import that package here to provide that functionality?

NatoBoram avatar Mar 05 '24 21:03 NatoBoram

PRs welcome! I would prefer not to pull in an external dependency, and it looks like the code isn't too complex.

niieani avatar Jul 18 '24 00:07 niieani