Skip to content

Conversation

@hassiebp
Copy link
Contributor

@hassiebp hassiebp commented Feb 3, 2025

Important

Fixes mutation issue in _parse_usage by copying the usage dictionary in openai.py.

  • Behavior:
    • Modify _parse_usage in openai.py to copy the usage dictionary to prevent mutation of the original object.
    • Ensure compatibility with both dictionary and object-based usage inputs.
  • Tests:
    • Update assertions in test_openai.py to check for substring presence in model names.

This description was created by Ellipsis for 979ce0b. It will automatically update as commits are pushed.


Greptile Summary

Disclaimer: Experimental PR review

This PR modifies the OpenAI usage object handling in langfuse-python to prevent unintended mutations of the original usage data during token detail processing.

  • Modified _parse_usage in langfuse/openai.py to create a copy of the usage dictionary before processing
  • Ensures data integrity by preventing modifications to the original OpenAI usage object
  • Maintains compatibility with both dictionary and object-based usage inputs

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@hassiebp hassiebp merged commit d951399 into main Feb 3, 2025
10 checks passed
@hassiebp hassiebp deleted the fix-openai-tokens-details-mutation branch February 3, 2025 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants