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

[Executor] Update openai tokens to trace #1918

Merged
merged 8 commits into from
Feb 2, 2024

Conversation

lumoslnt
Copy link
Contributor

@lumoslnt lumoslnt commented Feb 1, 2024

Description

This pull request primarily introduces changes to the src/promptflow/promptflow/_core/tracer.py file. The main focus of the changes is to enhance the tracing mechanism by adding a TokenCollector class for collecting OpenAI tokens associated with spans, and integrating it into the existing tracing flow. The changes also include a minor import modification for the OpenTelemetry library.

Main Changes:

  • src/promptflow/promptflow/_core/tracer.py: Introduced a new class TokenCollector to collect OpenAI tokens associated with spans. The class provides methods to collect tokens, merge tokens for parent spans, and retrieve tokens for a given span id.
  • src/promptflow/promptflow/_core/tracer.py: The enrich_span_with_output function now also sets token attributes to the span if any tokens are associated with the span id.
  • src/promptflow/promptflow/_core/tracer.py: The wrapped function (both synchronous and asynchronous versions) now collects OpenAI tokens if the trace type is LLM, and collects tokens for the parent span before returning the output.

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.
  • 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.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

@lumoslnt lumoslnt requested a review from a team as a code owner February 1, 2024 11:14
@github-actions github-actions bot added promptflow executor The changes related to the execution of the flow labels Feb 1, 2024
Copy link

github-actions bot commented Feb 1, 2024

SDK CLI Global Config Test Result devs/linatang/update_openai_tokens_to_trace

2 tests   2 ✅  49s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit b6f9c5d.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Feb 1, 2024

Executor Unit Test Result devs/linatang/update_openai_tokens_to_trace

705 tests   705 ✅  44s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit b6f9c5d.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Feb 1, 2024

promptflow SDK CLI Azure E2E Test Result devs/linatang/update_openai_tokens_to_trace

  4 files    4 suites   3m 21s ⏱️
129 tests 110 ✅ 19 💤 0 ❌
516 runs  440 ✅ 76 💤 0 ❌

Results for commit b6f9c5d.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Feb 1, 2024

Executor E2E Test Result devs/linatang/update_openai_tokens_to_trace

187 tests   185 ✅  3m 48s ⏱️
  1 suites    2 💤
  1 files      0 ❌

Results for commit b6f9c5d.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Feb 1, 2024

SDK CLI Test Result devs/linatang/update_openai_tokens_to_trace

   12 files     12 suites   39m 3s ⏱️
  419 tests   411 ✅  8 💤 0 ❌
1 676 runs  1 644 ✅ 32 💤 0 ❌

Results for commit b6f9c5d.

♻️ This comment has been updated with latest results.

@zhengfeiwang zhengfeiwang merged commit d0a2829 into main Feb 2, 2024
42 checks passed
@zhengfeiwang zhengfeiwang deleted the devs/linatang/update_openai_tokens_to_trace branch February 2, 2024 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
executor The changes related to the execution of the flow promptflow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants