-
Notifications
You must be signed in to change notification settings - Fork 413
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
feat(gemini): trace google gemini Integration #10503
Conversation
|
BenchmarksBenchmark execution time: 2024-09-11 20:02:53 Comparing candidate commit eecda47 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 353 metrics, 47 unstable metrics. |
Datadog ReportBranch report: ✅ 0 Failed, 9717 Passed, 355 Skipped, 2h 9m 47.19s Total duration (1m 35.08s time saved) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some nits and clarifying questions
Adds support for tracing Google's Gemini Python SDK `generate_content` and `generate_content_async` methods (also indirectly traces `send_message()`). This PR also moves `_get_attr()` convenience helper from the anthropic integration to the shared `ddtrace.llmobs._utils.py` module. ### Features: - Traces `generate_content/generate_content_async()` and indirectly `send_message/send_message_async()` which uses `generate_content` under the hood - Handles streamed responses - Captures input/outputs (truncation included, function call/response messages included), token usage, input configuration options, and model name. ### Testing: The Gemini Python SDK does not use requests/httpx to submit requests but instead via GRPC. The vcrpy testing framework does not capture this so I wrote a mock client to store/return mock responses instead of sending actual requests to Google. This testing framework was inspired by the [Gemini Python SDK's testing strategy](https://github.com/google-gemini/generative-ai-python/blob/9407dcde5666ba58831227d3acf8bd0e3f3b4f81/tests/test_generative_models.py#L41). ### Next steps (future PRs) - Wrap `send_message()` not to trace, but to attach a hash/session_id for all subsequent send_message calls - Integrate with LLMObs ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) (cherry picked from commit c0fd013)
Adds support for tracing Google's Gemini Python SDK
generate_content
andgenerate_content_async
methods (also indirectly tracessend_message()
).This PR also moves
_get_attr()
convenience helper from the anthropic integration to the sharedddtrace.llmobs._utils.py
module.Features:
generate_content/generate_content_async()
and indirectlysend_message/send_message_async()
which usesgenerate_content
under the hoodTesting:
The Gemini Python SDK does not use requests/httpx to submit requests but instead via GRPC. The vcrpy testing framework does not capture this so I wrote a mock client to store/return mock responses instead of sending actual requests to Google. This testing framework was inspired by the Gemini Python SDK's testing strategy.
Next steps (future PRs)
send_message()
not to trace, but to attach a hash/session_id for all subsequent send_message callsChecklist
Reviewer Checklist