Feat/improve exception raising for better debugging (#1512)
<!-- .github/pull_request_template.md --> ## Description When raising exceptions, in some places we lose the stack trace, or in some cases when we raise custom exceptions - we also lose any metadata from original exception that could help pinpoint the issue. This PR updates exception throwing to use [`raise ... from`](https://docs.python.org/3/reference/simple_stmts.html#raise), which: 1. preserves stack trace 2. when we throw custom exception, indicates that our exception was caused by XYZ exception _this is a scoped down version for upcoming release, rest of the changes are in #1518_ <!-- Please provide a clear, human-generated description of the changes in this PR. DO NOT use AI-generated descriptions. We want to understand your thought process and reasoning. --> ## Type of Change <!-- Please check the relevant option --> - [ ] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Code refactoring - [ ] Performance improvement - [ ] Other (please specify): ## Screenshots/Videos (if applicable) <!-- Add screenshots or videos to help explain your changes --> ## Pre-submission Checklist <!-- Please check all boxes that apply before submitting your PR --> - [ ] **I have tested my changes thoroughly before submitting this PR** - [ ] **This PR contains minimal changes necessary to address the issue/feature** - [ ] My code follows the project's coding standards and style guidelines - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have added necessary documentation (if applicable) - [ ] All new and existing tests pass - [ ] I have searched existing PRs to ensure this change hasn't been submitted already - [ ] I have linked any relevant issues in the description - [ ] My commits have clear and descriptive messages ## DCO Affirmation I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin.
This commit is contained in:
commit
4b14bd7566
3 changed files with 9 additions and 5 deletions
4
.github/workflows/test_s3_file_storage.yml
vendored
4
.github/workflows/test_s3_file_storage.yml
vendored
|
|
@ -6,6 +6,10 @@ on:
|
|||
permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
RUNTIME__LOG_LEVEL: ERROR
|
||||
ENV: 'dev'
|
||||
|
||||
jobs:
|
||||
test-gemini:
|
||||
name: Run S3 File Storage Test
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ class GenericAPIAdapter(LLMInterface):
|
|||
if not (self.fallback_model and self.fallback_api_key and self.fallback_endpoint):
|
||||
raise ContentPolicyFilterError(
|
||||
f"The provided input contains content that is not aligned with our content policy: {text_input}"
|
||||
)
|
||||
) from error
|
||||
|
||||
try:
|
||||
return await self.aclient.chat.completions.create(
|
||||
|
|
@ -151,4 +151,4 @@ class GenericAPIAdapter(LLMInterface):
|
|||
else:
|
||||
raise ContentPolicyFilterError(
|
||||
f"The provided input contains content that is not aligned with our content policy: {text_input}"
|
||||
)
|
||||
) from error
|
||||
|
|
|
|||
|
|
@ -146,11 +146,11 @@ class OpenAIAdapter(LLMInterface):
|
|||
ContentFilterFinishReasonError,
|
||||
ContentPolicyViolationError,
|
||||
InstructorRetryException,
|
||||
):
|
||||
) as e:
|
||||
if not (self.fallback_model and self.fallback_api_key):
|
||||
raise ContentPolicyFilterError(
|
||||
f"The provided input contains content that is not aligned with our content policy: {text_input}"
|
||||
)
|
||||
) from e
|
||||
|
||||
try:
|
||||
return await self.aclient.chat.completions.create(
|
||||
|
|
@ -183,7 +183,7 @@ class OpenAIAdapter(LLMInterface):
|
|||
else:
|
||||
raise ContentPolicyFilterError(
|
||||
f"The provided input contains content that is not aligned with our content policy: {text_input}"
|
||||
)
|
||||
) from error
|
||||
|
||||
@observe
|
||||
@sleep_and_retry_sync()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue