-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
openai[patch]: Bugfix: try catch around JSON stringify/parse when counting OpenAI function calling tokens #4799
openai[patch]: Bugfix: try catch around JSON stringify/parse when counting OpenAI function calling tokens #4799
Conversation
…function call arguments tokens
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
f4a5cb9
to
834d326
Compare
); | ||
); | ||
} catch (error) { | ||
console.error("Error parsing function arguments", error, JSON.stringify(openAIMessage.additional_kwargs.function_call)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your call how you want to approach this kind of logging. I've had this as a patch-package patch for a while. Logging this is useful bc then I can easily see when arguments is invalid JSON
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this seems reasonable, thank you!
…bugfix/try-catch-arg-token-counting
Thank you for this! |
If OpenAI doesn't return valid JSON in arguments (which is rare, but happens) the OpenAI invocation just throws because token counting fails. Counting the tokens without removing newlines/spaces (which I assume is needed bc it was already there, but I don't know for sure), should be a good enough approximation of token count