fix(utils.py): don't modify openai_token_counter

This commit is contained in:
Krrish Dholakia 2025-04-02 08:09:56 -07:00
parent 294de31803
commit b12a9892b7
2 changed files with 3 additions and 2 deletions

View file

@ -1674,7 +1674,7 @@ def openai_token_counter( # noqa: PLR0915
if tools:
num_tokens += len(encoding.encode(_format_function_definitions(tools)))
num_tokens += FUNCTION_DEFINITION_TOKEN_COUNT # Additional tokens for function definition of tools
num_tokens += 9 # Additional tokens for function definition of tools
# If there's a system message and tools are present, subtract four tokens
if tools and includes_system_message:
num_tokens -= 4
@ -1684,7 +1684,7 @@ def openai_token_counter( # noqa: PLR0915
if tool_choice == "none":
num_tokens += 1
elif isinstance(tool_choice, dict):
num_tokens += TOOL_CHOICE_OBJECT_TOKEN_COUNT
num_tokens += 7
num_tokens += len(encoding.encode(tool_choice["function"]["name"]))
return num_tokens