Closed vldvasi closed 11 months ago
š¤
It's great that you've identified the issue and provided a clear description of the bug. Your proposed solution to handle the case when response.raw is None seems like a step in the right direction. Encouraging you to go ahead and implement this fix in a pull request for LlamaIndex. Your contribution will be valuable in improving the framework for all users. Thank you for your willingness to contribute!
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a š if this is helpful and š if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
A possible fix that I've tested and working would be to handle the case when response.raw is None in get_llm_token_counts function:
# try getting attached token counts first
try:
messages_tokens = 0
response_tokens = 0
if response.raw is not None:
usage = response.raw.get("usage") # type: ignore
if usage is not None:
messages_tokens = usage.prompt_tokens
response_tokens = usage.completion_tokens
if messages_tokens == 0 or response_tokens == 0:
raise ValueError("Invalid token counts!")
return TokenCountingEvent(
event_id=event_id,
prompt=messages_str,
prompt_token_count=messages_tokens,
completion=response_str,
completion_token_count=response_tokens,
)
except (ValueError, KeyError):
# Invalid token counts, or no token counts attached
pass
Merged into main. Will be released v0.9.12 (or you can install from source and get it now)
Bug Description
When using LLamaIndex's QueryFusionRetriever and CondensePlusContextChatEngine with the Bedrock APIs (Claude-v2 and Titan-embed-text-v1) a NoneType exception is triggered in the function get_llm_token_counts() of token_counting.py.
Possibly handling the case when response.raw is None would fix the issue.
Version
0.9.8
Steps to Reproduce
The following snippet of code results in the mentioned error:
Relevant Logs/Tracbacks