Skip to content

Commit 329626a

Browse files
authored
fix: properly handle Together API 5xx errors (#577)
Together AI 500 errors are returned as 400 user errors. This PR correctly raises a ProviderError instead of a UserError when a 500 is returned from together ai
1 parent a1cac17 commit 329626a

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.2.4
2+
3+
**Fix**: properly handle Together API 5xx errors as ProviderError instead of UserError
4+
15
## 1.2.3
26

37
* **Feature**: allow environment credentials for S3

unstructured_ingest/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.2.3" # pragma: no cover
1+
__version__ = "1.2.4" # pragma: no cover

unstructured_ingest/embed/togetherai.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
BaseEmbeddingEncoder,
99
EmbeddingConfig,
1010
)
11+
from unstructured_ingest.errors_v2 import (
12+
ProviderError,
13+
UserAuthError,
14+
UserError,
15+
is_internal_error,
16+
)
1117
from unstructured_ingest.errors_v2 import (
1218
RateLimitError as CustomRateLimitError,
1319
)
14-
from unstructured_ingest.errors_v2 import UserAuthError, UserError, is_internal_error
1520
from unstructured_ingest.logger import logger
1621
from unstructured_ingest.utils.dep_check import requires_dependencies
1722

@@ -34,14 +39,22 @@ def wrap_error(self, e: Exception) -> Exception:
3439
from together.error import AuthenticationError, RateLimitError, TogetherException
3540

3641
if not isinstance(e, TogetherException):
37-
logger.error(f"unhandled exception from openai: {e}", exc_info=True)
42+
logger.error(f"unhandled exception from together: {e}", exc_info=True)
3843
return e
3944
message = e.args[0]
4045
if isinstance(e, AuthenticationError):
4146
return UserAuthError(message)
4247
if isinstance(e, RateLimitError):
4348
return CustomRateLimitError(message)
44-
return UserError(message)
49+
50+
status_code = getattr(e, 'status_code', None)
51+
if status_code is not None:
52+
if 400 <= status_code < 500:
53+
return UserError(message)
54+
if status_code >= 500:
55+
return ProviderError(message)
56+
logger.error(f"unhandled exception from together: {e}", exc_info=True)
57+
return e
4558

4659
def run_precheck(self) -> None:
4760
client = self.get_client()

0 commit comments

Comments
 (0)