Skip to content
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

[BUG] Failure in TokenCollector.collect_openai_tokens_for_parent_span method #3892

Open
vladfeigin opened this issue Dec 21, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@vladfeigin
Copy link

Describe the bug
I'm using promptflow for trace collecting. When running the application it fails in collect_openai_tokens_for_parent_span method method with the error: "TypeError: unsupported operand type(s) for +: 'int' and 'dict'\n'}}], 'debugInfo': {'type': 'ScriptExecutionError', 'message': "Execution failure in 'rag_flow': (TypeError) unsupported operand type(s) for +: 'int' and 'dict'""

How To Reproduce the bug
from promptflow.tracing import start_trace

start_trace()
... code ...

Then from command line run: pf flow serve --source ./ --port 8080 --host localhost
at some point the failure happens

Running Information(please complete the following information):

{
"promptflow": "1.16.2",
"promptflow-azure": "1.16.1",
"promptflow-core": "1.16.2",
"promptflow-devkit": "1.16.2",
"promptflow-tracing": "1.16.2"
}

OS:
ProductName: macOS
ProductVersion: 15.2
BuildVersion: 24C101

Python 3.11.11

Additional context
Issue explanation: The root cause is in this code :
merged_tokens = {
# When token count is None for some reason, we should default to 0.
key: (self._span_id_to_tokens[parent_span_id].get(key, 0) or 0) + (tokens.get(key, 0) or 0)
for key in set(self._span_id_to_tokens[parent_span_id]) | set(tokens)
}

this is because can be that "tokens" dictionary is not flat dictionary but could contain another dictionaries.
For example: {'completion_tokens': 112, 'prompt_tokens': 587, 'total_tokens': 699, 'completion_tokens_details': {'audio_tokens': 0, 'reasoning_tokens': 0, 'accepted_prediction_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}} . In this case tokens dictionary contains "completion_tokens_details and prompt_tokens_details which are dictionaries. However the code attempting 0 + dictionary, and this crash the code.

@vladfeigin vladfeigin added the bug Something isn't working label Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant