feat(cohere): upgrade integration from ai to gen_ai#5532
feat(cohere): upgrade integration from ai to gen_ai#5532
Conversation
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Documentation 📚
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 31 passed | Total: 31 | Pass Rate: 100% | Execution Time: 14.02s 📊 Comparison with Base Branch
All tests are passing successfully. ❌ Patch coverage is 6.83%. Project has 14581 uncovered lines. Files with missing lines (5)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 26.40% 27.31% +0.91%
==========================================
Files 189 192 +3
Lines 19902 20058 +156
Branches 6464 6534 +70
==========================================
+ Hits 5255 5477 +222
- Misses 14647 14581 -66
- Partials 457 488 +31Generated by Codecov Action |
| GEN_AI_ALLOWED_MESSAGE_ROLES.SYSTEM: ["system"], | ||
| GEN_AI_ALLOWED_MESSAGE_ROLES.USER: ["user", "human"], | ||
| GEN_AI_ALLOWED_MESSAGE_ROLES.ASSISTANT: ["assistant", "ai"], | ||
| GEN_AI_ALLOWED_MESSAGE_ROLES.ASSISTANT: ["assistant", "ai", "chatbot"], |
There was a problem hiding this comment.
This is needed because cohere sometimes uses the role chatbot in their message structure
| with sentry_sdk.start_span( | ||
| op=OP.GEN_AI_EMBEDDINGS, | ||
| name=f"embeddings {model}".strip(), | ||
| origin=CohereIntegration.origin, |
There was a problem hiding this comment.
set_input_span_data call not wrapped in capture_internal_exceptions()
In _wrap_embed, the call to set_input_span_data on line 101 is not wrapped in capture_internal_exceptions(), unlike the equivalent calls in v1.py (line 131-135) and v2.py (line 188-195). If set_input_span_data raises an exception due to unexpected data types or internal errors, it will propagate to the user's code, potentially causing their embed request to fail despite the underlying Cohere API call succeeding.
Verification
Read v1.py (lines 131-135) and v2.py (lines 188-195) which both wrap set_input_span_data in capture_internal_exceptions(). Read set_input_span_data in span_config.py to verify it can raise exceptions. The init.py _wrap_embed function does not wrap line 101 in capture_internal_exceptions().
Suggested fix: Wrap the set_input_span_data call in capture_internal_exceptions() to prevent instrumentation errors from affecting user code.
| origin=CohereIntegration.origin, | |
| with capture_internal_exceptions(): | |
| set_input_span_data(span, kwargs, integration, COHERE_EMBED_CONFIG) |
Identified by Warden code-review · HPV-RQ8
This PR encompasses multiple changes to accomplish this
Closes TET-2023