promptflow: [BUG] Running Prompt flow locally produces errors
Describe the bug
Running a flow using pf test seems to work but exceptions are reported locally.
How To Reproduce the bug
Run pf test on a flow locally. The flow executes successfully but exceptions are generated when collecting token metrics for openai.
Expected behavior A clean run without exceptions
Screenshots
WARNING:opentelemetry.attributes:Invalid type NoneType 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 NoneType 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 NoneType for attribute ‘computed.cumulative_token_count.completion’ value. Expected one of [‘bool’, ‘str’, ‘bytes’, ‘int’, ‘float’] or a sequence of those types
Running Information(please complete the following information): { “promptflow”: “1.15.0”, “promptflow-azure”: “1.15.0”, “promptflow-core”: “1.15.0”, “promptflow-devkit”: “1.15.0”, “promptflow-tracing”: “1.15.0” }
Executable ‘c:\git\azure-ai-prompt-flow.venv\Scripts\python.exe’ Python (Windows) 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] Additional context Seems like the exception is in here
def collect_openai_tokens_for_parent_span(self, span):
tokens = self.try_get_openai_tokens(span.get_span_context().span_id)
if tokens:
if not hasattr(span, "parent") or span.parent is None:
return
parent_span_id = span.parent.span_id
with self._lock:
if parent_span_id in self._span_id_to_tokens:
merged_tokens = {
key: self._span_id_to_tokens[parent_span_id].get(key, 0) + tokens.get(key, 0)
for key in set(self._span_id_to_tokens[parent_span_id]) | set(tokens)
}
self._span_id_to_tokens[parent_span_id] = merged_tokens
else:
self._span_id_to_tokens[parent_span_id] = tokens
On the line key: self._span_id_to_tokens[parent_span_id].get(key, 0) + tokens.get(key, 0) . Not all steps in my flow are LLM steps. I wonder if this could be causing the issue where we have some steps in the flow that don’t have any tokens.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 11
- Comments: 30 (2 by maintainers)
Rolling back the version of openai also works,
openai<=1.44.1resolves the error. Looks like promptflow-tracing could be incompatible with 1.45.0 https://pypi.org/project/openai/#historyWe encountered the problem as well. Adding the following lines to the promptflow YAML worked:
Some keys in the tokens have values that are not int, causing the issue.
As a temporary solution, tracing can be disabled by setting PF_DISABLE_TRACING=true.
Rolling back OpenAI did not work for me, Pydantic is so dynamic that I still get
completion_tokens_details={'reasoning_tokens': 0}. In summary:promflow.tracing, which does not support that.Also having this issue, with similar errors:
This happens when running a version of the
chat-math-variantexample, edited so thatextract_text.pycalls the OpenAI ChatCompletions endpoint. One of my coworkers is also seeing this error, seemingly from an LLM tool call.We see something similar, however in our case it is an error and failing the execution:
@asos-oliverfrost thank you for finding that! Rolling back worked for me. It looks like this is the specific line that is breaking the behavior in prompt flow, because the new field completion_token_details is optional: https://github.com/openai/openai-python/compare/v1.44.1...v1.45.0#diff-d85f41ac9f419751206af46c34ef5c8c74258660be492aa703dcbebcfc96a41bR25
Nice it worked for me as well, after upgrading the promptflow package
Also still having this issue. I don’t want to give up tracing as it’s extremely useful for my development. I’m using prompt flow via the yaml-based declarative approach. I have tried openai==1.44.0, promptflow-tracing==1.16.1
EDIT: Upgrading all promptflow packages to the Jan 6th release, promptflow 1.17.0, fixed the issue for me. The fix is in the release notes. https://pypi.org/project/promptflow/1.17.0/
As @JanWerder suggested this did the trick for me
This is fixed with promptflow-tracing 1.16.1
I’m able to run locally, but I get TypeError: unsupported operand type(s) for +: ‘int’ and ‘NoneType’ after deploying using Azure AI Studio
This worked for me