promptflow: [BUG] Getting unsupported operand type(s) for +: 'dict' and 'dict' when running chat-with-wikipedia flow

Describe the bug When running chat-with-wikipedia flow, I’m encountering the following error:

...
  File "/usr/local/lib/python3.9/site-packages/promptflow/tracing/_trace.py", line 145, in <dictcomp>
    key: (self._span_id_to_tokens[parent_span_id].get(key, 0) or 0) + (tokens.get(key, 0) or 0)
TypeError: unsupported operand type(s) for +: 'dict' and 'dict'

How To Reproduce the bug Steps to reproduce the behavior, how frequent can you experience the bug:

  1. I used Open in GitHub Codespaces option to use the pre-built environment
  2. Run the examples/flows/chat/chat-with-wikipedia flow, using Run it with standard mode option
  3. The command I see in the terminal is: /usr/local/bin/python3 -m promptflow._cli._pf.entry flow test --flow /workspaces/promptflow/examples/flows/chat/chat-with-wikipedia --user-agent "prompt-flow-extension/1.20.2 (linux; x64) VSCode/1.94.2"
  4. The following error comes every single time this flow is run
2024-10-25 14:55:25 +0000   17101 execution.flow     INFO     Executing node augmented_chat. node run id: edeaf1be-c107-4555-851f-38d5706e7a30_augmented_chat_0
WARNING:opentelemetry.attributes:Invalid type dict for attribute '__computed__.cumulative_token_count.completion' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types
WARNING:opentelemetry.attributes:Invalid type dict for attribute '__computed__.cumulative_token_count.prompt' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types
WARNING:opentelemetry.attributes:Invalid type dict for attribute 'llm.usage.completion_tokens_details' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types
WARNING:opentelemetry.attributes:Invalid type dict for attribute 'llm.usage.prompt_tokens_details' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types
WARNING:opentelemetry.attributes:Invalid type dict for attribute '__computed__.cumulative_token_count.completion' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types
WARNING:opentelemetry.attributes:Invalid type dict for attribute '__computed__.cumulative_token_count.prompt' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types
2024-10-25 14:55:26 +0000   17101 execution          ERROR    Node augmented_chat in line 0 failed. Exception: Execution failure in 'augmented_chat': (TypeError) unsupported operand type(s) for +: 'dict' and 'dict'.
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/promptflow/_core/flow_execution_context.py", line 182, in _invoke_tool_inner
    return f(**kwargs)
  File "/usr/local/lib/python3.9/site-packages/promptflow/executor/flow_executor.py", line 1344, in wrapper
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/promptflow/tracing/_trace.py", line 562, in wrapped
    token_collector.collect_openai_tokens_for_parent_span(span)
  File "/usr/local/lib/python3.9/site-packages/promptflow/tracing/_trace.py", line 143, in collect_openai_tokens_for_parent_span
    merged_tokens = {
  File "/usr/local/lib/python3.9/site-packages/promptflow/tracing/_trace.py", line 145, in <dictcomp>
    key: (self._span_id_to_tokens[parent_span_id].get(key, 0) or 0) + (tokens.get(key, 0) or 0)
TypeError: unsupported operand type(s) for +: 'dict' and 'dict'

Expected behavior I am expecting the flow to run without any errors

Screenshots I’m attaching two screenshots to show the error Image Image

Running Information(please complete the following information):

  • Promptflow Package Version using pf -v: [e.g. 0.0.102309906]
{
 "promptflow": "1.16.1",
 "promptflow-azure": "1.16.1",
 "promptflow-core": "1.16.1",
 "promptflow-devkit": "1.16.1",
 "promptflow-tracing": "1.16.1"
}

Executable '/usr/local/bin/python3.9'
Python (Linux) 3.9.20 (main, Oct 19 2024, 01:00:05) 
[GCC 10.2.1 20210110]
  • Operating System: Linux (GitHub Codespaces) - Debian GNU/Linux 11 (bullseye)
  • Python Version using python --version: Python 3.9.20

Additional context This is my first time using GitHub Codespaces as well as Prompt flow, so if there’s some additional initialization/config that I had to run, please let me know

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 18

Commits related to this issue

Most upvoted comments

https://microsoft.github.io/promptflow/reference/changelog/promptflow-tracing.html shows that this issue was fixed in Image

Where is this release available? Looks like it is not yet published.

{ “promptflow”: “1.16.2”, “promptflow-azure”: “1.16.2”, “promptflow-core”: “1.16.2”, “promptflow-devkit”: “1.16.2”, “promptflow-tracing”: “1.16.2” }

Python 3.10.15

Error: in key: (self._span_id_to_tokens[parent_span_id].get(key, 0) or 0) + (tokens.get(key, 0) or 0) TypeError: unsupported operand type(s) for +: ‘int’ and ‘dict’

in flow.dag.yaml at the end try

environment_variables:
  PF_DISABLE_TRACING: true
environment:
  python_requirements_txt: requirements.txt

the workaround of disabled tracing work for me. but is there a work around to still use trace? as I am using trace for my evaluation workflow.

I also tried setting the tracing to none thinking it won’t go to _trace.py but that didn’t make any difference. But when I set the PF_DISABLE_TRACING environment variable to true (in the same terminal) and re-ran the flow command, I didn’t get this error as the tracing code didn’t run in that case.