fix installing on python3.8

This commit is contained in:
Ishaan Jaff 2024-07-16 16:56:15 -07:00 • committed by Krrish Dholakia
parent 3659aa26a9
commit 505b4f86d3

View file

@ -1575,8 +1575,8 @@ def openai_token_counter(
model="gpt-3.5-turbo-0613",
text: Optional[str] = None,
is_tool_call: Optional[bool] = False,
tools: Optional[List[ChatCompletionToolParam]] = None,
tool_choice: Optional[ChatCompletionNamedToolChoiceParam] = None,
tools: List[ChatCompletionToolParam] | None = None,
tool_choice: ChatCompletionNamedToolChoiceParam | None = None,
count_response_tokens: Optional[
bool
] = False, # Flag passed from litellm.stream_chunk_builder, to indicate counting tokens for LLM Response. We need this because for LLM input we add +3 tokens per message - based on OpenAI's token counter
@ -1621,6 +1621,7 @@ def openai_token_counter(
num_tokens += tokens_per_message
if message.get("role", None) == "system":
includes_system_message = True
includes_system_message = True
for key, value in message.items():
if isinstance(value, str):
num_tokens += len(encoding.encode(value, disallowed_special=()))
@ -1872,6 +1873,7 @@ def _format_type(props, indent):
return "any"
def token_counter(
model="",
custom_tokenizer: Optional[dict] = None,
@ -1960,6 +1962,7 @@ def token_counter(
count_response_tokens=count_response_tokens,
tools=tools,
tool_choice=tool_choice,
tool_choice=tool_choice,
)
else:
print_verbose(
@ -1973,6 +1976,7 @@ def token_counter(
count_response_tokens=count_response_tokens,
tools=tools,
tool_choice=tool_choice,
tool_choice=tool_choice,
)
else:
num_tokens = len(encoding.encode(text, disallowed_special=())) # type: ignore