Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug in token usage merging logic for promptflow-tracing SDK (#3793)
# Description The token calculation logic in promptflow-tracing merges two dictionaries related to token usage. i.e. Given these two dictionaries: ```json { "completion_tokens": 146, "prompt_tokens": 166, "total_tokens": 312 } ``` ```json { "completion_tokens": 10, "prompt_tokens": 10, "total_tokens": 20 } ``` The merged result will be: ```json { "completion_tokens": 156, "prompt_tokens": 176, "total_tokens": 332 } ``` However, for some customized models, there might be more additional fields populated in the dictionaries, like: ```json { "completion_tokens": 146, "prompt_tokens": 166, "total_tokens": 312, "completion_tokens_details": null } ``` Which causes the merging logic crash: ![image](https://github.com/user-attachments/assets/c1777ebf-db00-4c3c-a449-7a72274ffc0c) This PR is to fix the issue. It converts `null`s to `0`s to avoid Python from raising errors. # 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](https://github.com/microsoft/promptflow/blob/main/CONTRIBUTING.md).** - [x] **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](../CONTRIBUTING.md#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](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md). ### Testing Guidelines - [ ] Pull request includes test coverage for the included changes. --------- Co-authored-by: Hanchi Wang <[email protected]> Co-authored-by: Hanchi Wang <[email protected]>
- Loading branch information