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

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'
Copy link

Hi, thank you for your interest in helping to improve the prompt flow experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment.

@github-actions github-actions bot added the no-recent-activity There has been no recent activity on this issue/pull request label Jan 22, 2025
Copy link

Hi, thank you for your contribution. Since there has not been recent engagement, we are going to close this out. Feel free to reopen if you'd like to continue working on these changes. Please be sure to remove the no-recent-activity label; otherwise, this is likely to be closed again with the next cleanup pass.

@github-actions github-actions bot closed this Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external no-recent-activity There has been no recent activity on this issue/pull request promptflow-tracing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant