newrelic / newrelic-python-agent

New Relic Python Agent
https://docs.newrelic.com/docs/agents/python-agent
Apache License 2.0
176 stars 99 forks source link

Add LLM token count callback. #1094

Closed umaannamalai closed 6 months ago

umaannamalai commented 6 months ago

This PR adds a new, public callback set_llm_token_count_callback. This callback calls a user function to calculate total LLM token counts for a chat completion or embedding and stores in on the corresponding LLM events.

github-actions[bot] commented 6 months ago

🦙 MegaLinter status: ❌ ERROR

Descriptor Linter Files Fixed Errors Elapsed time
✅ PYTHON bandit 5 0 6.88s
✅ PYTHON black 23 2 0 4.52s
❌ PYTHON flake8 23 1 2.15s
✅ PYTHON isort 23 17 0 0.43s
❌ PYTHON pylint 23 52 11.65s

See detailed report in MegaLinter reports _Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff_

_MegaLinter is graciously provided by OX Security_

codecov-commenter commented 6 months ago

Codecov Report

Attention: Patch coverage is 88.23529% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 81.87%. Comparing base (b950070) to head (4305fe7). Report is 7 commits behind head on develop-ai-limited-preview-3.

Files Patch % Lines
newrelic/api/ml_model.py 79.31% 4 Missing and 2 partials :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop-ai-limited-preview-3 #1094 +/- ## ============================================================= Coverage 81.86% 81.87% ============================================================= Files 192 192 Lines 21253 21248 -5 Branches 3711 3709 -2 ============================================================= - Hits 17398 17396 -2 + Misses 2783 2778 -5 - Partials 1072 1074 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.