microsoft / promptflow

Build high-quality LLM apps - from prototyping, testing to production deployment and monitoring.
https://microsoft.github.io/promptflow/
MIT License
9.53k stars 872 forks source link

Fix bug in token usage merging logic for promptflow-tracing SDK #3793

Closed zzn2 closed 1 month ago

zzn2 commented 1 month ago

Description

The token calculation logic in promptflow-tracing merges two dictionaries related to token usage. i.e. Given these two dictionaries:

{ "completion_tokens": 146, "prompt_tokens": 166, "total_tokens": 312 }
{ "completion_tokens": 10, "prompt_tokens": 10, "total_tokens": 20 }

The merged result will be:

{ "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:

{ "completion_tokens": 146, "prompt_tokens": 166, "total_tokens": 312, "completion_tokens_details": null }

Which causes the merging logic crash:

image

This PR is to fix the issue. It converts nulls to 0s to avoid Python from raising errors.

All Promptflow Contribution checklist:

General Guidelines and Best Practices

Testing Guidelines

github-actions[bot] commented 1 month ago

promptflow-tracing test result

 12 files  ±0   12 suites  ±0   16s :stopwatch: -1s  62 tests ±0   62 :white_check_mark: ±0  0 :zzz: ±0  0 :x: ±0  744 runs  ±0  744 :white_check_mark: ±0  0 :zzz: ±0  0 :x: ±0 

Results for commit c8ef3b27. ± Comparison against base commit 11ac34bd.

:recycle: This comment has been updated with latest results.

github-actions[bot] commented 1 month ago

promptflow SDK CLI Azure E2E Test Result u/zhizhu/20240929-fix-tracing-bug

  4 files    4 suites   4m 18s :stopwatch: 244 tests 204 :white_check_mark:  40 :zzz: 0 :x: 976 runs  816 :white_check_mark: 160 :zzz: 0 :x:

Results for commit c8ef3b27.

:recycle: This comment has been updated with latest results.

github-actions[bot] commented 1 month ago

promptflow-core test result

0 tests  ±0   0 :white_check_mark: ±0   0s :stopwatch: ±0s 0 suites ±0   0 :zzz: ±0  0 files   ±0   0 :x: ±0 

Results for commit c8ef3b27. ± Comparison against base commit 11ac34bd.

:recycle: This comment has been updated with latest results.

github-actions[bot] commented 1 month ago

SDK CLI Global Config Test Result u/zhizhu/20240929-fix-tracing-bug

6 tests   6 :white_check_mark:  1m 23s :stopwatch: 1 suites  0 :zzz: 1 files    0 :x:

Results for commit c8ef3b27.

:recycle: This comment has been updated with latest results.

github-actions[bot] commented 1 month ago

Executor Unit Test Result u/zhizhu/20240929-fix-tracing-bug

798 tests   798 :white_check_mark:  3m 43s :stopwatch:   1 suites    0 :zzz:   1 files      0 :x:

Results for commit c8ef3b27.

:recycle: This comment has been updated with latest results.

github-actions[bot] commented 1 month ago

Executor E2E Test Result u/zhizhu/20240929-fix-tracing-bug

246 tests   239 :white_check_mark:  5m 15s :stopwatch:   1 suites    6 :zzz:   1 files      1 :x:

For more details on these failures, see this check.

Results for commit c8ef3b27.

:recycle: This comment has been updated with latest results.

github-actions[bot] commented 1 month ago

SDK CLI Test Result u/zhizhu/20240929-fix-tracing-bug

    4 files      4 suites   1h 5m 37s :stopwatch:   790 tests   767 :white_check_mark: 23 :zzz: 0 :x: 3 160 runs  3 068 :white_check_mark: 92 :zzz: 0 :x:

Results for commit c8ef3b27.

:recycle: This comment has been updated with latest results.