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

checking if the value of the metric is an int #3911

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

orasik
Copy link

@orasik orasik commented Jan 8, 2025

Description

When using the OpenAI connection in a Python code, I was getting the warning

Failed to calculate metrics due to exception: unsupported operand type(s) for +: 'int' and 'dict'.

This is due to Azure OpenAI returning the following object in "usage"

    "usage": {
      "completion_tokens": 38,
      "prompt_tokens": 1456,
      "total_tokens": 1494,
      "completion_tokens_details": {
        "accepted_prediction_tokens": 0,
        "audio_tokens": 0,
        "reasoning_tokens": 0,
        "rejected_prediction_tokens": 0
      }

The code is adding the value of each key in usage without checking the value type, which is causing it to add a dictionary completion_tokens_details instead of avoiding it.

I just added a check to ensure it only adds int values.

This error is affecting grouping calls in Application Insights in Azure, and we are unable to see the flow of the request.

Issue: 3910

All Promptflow Contribution checklist:

  • The pull request does not introduce [breaking changes].
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.
  • I confirm that all new dependencies are compatible with the MIT license.
  • [] Create an issue and link to the pull request to get dedicated review from promptflow team. Learn more: suggested workflow.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

…iled to calculate metrics due to exception: unsupported operand type(s) for +: 'int' and 'dict'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant