promptflow
promptflow copied to clipboard
don't add empty openai token count values in tracing
Description
Using OpenAI's API outside of Azure, I was sometimes receiving a usage dict that looked like:
{'completion_tokens': 296, 'prompt_tokens': 1768, 'total_tokens': 2064, 'completion_tokens_details': None}
The empty key was getting added to the trace and throwing an error later when adding values
This keeps it out with a very minimal change.
All Promptflow Contribution checklist:
- X The pull request does not introduce [breaking changes].
- [ ] CHANGELOG is updated for new features, bug fixes or other significant changes.
- X I have read the contribution guidelines.
- N/A I confirm that all new dependencies are compatible with the MIT license.
General Guidelines and Best Practices
- X Title of the pull request is clear and informative.
- X 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.
Testing Guidelines
- [ ] Pull request includes test coverage for the included changes.
Looking at OpenAI's API, this is going to require a more extensive fix, because completion_tokens_details is a dict, not an int, when it does come through. I don't have capacity to fix this, so feel free to close this PR.
"completion_tokens_details": {
"reasoning_tokens": 0
}