Skip to content

Commit

Permalink
feat/add better custom errors (#315)
Browse files Browse the repository at this point in the history
* add better custom errors

* share same error handling code between async and non async partitioner code

* Fix async call

* Add error handling to openai embedder

* Add error handling to bedrock embedder

* Add error handling to octoai embedder

* Add error handling to togetherai embedder

* differentiate from rate limit and quote max in openai

* Update method to wrap error rather than raise to help with typing

* Add error handling to voyageai embedder

* fix unit test
  • Loading branch information
rbiseck3 authored Dec 20, 2024
1 parent 878ca74 commit 51dfbe1
Show file tree
Hide file tree
Showing 17 changed files with 1,097 additions and 29 deletions.
10 changes: 4 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
## 0.3.12-dev1

* **Bypass asyncio exception grouping to return more meaningful errors from OneDrive indexer**


## 0.3.12-dev0
## 0.3.12-dev2

### Fixes

Expand All @@ -12,6 +7,9 @@
### Enhancements

* **Kafka destination connector checks for existence of topic**
* **Create more reflective custom errors** Provide errors to indicate if the error was due to something user provided or due to a provider issue, applicable to all steps in the pipeline.
* **Bypass asyncio exception grouping to return more meaningful errors from OneDrive indexer**


## 0.3.11

Expand Down
28 changes: 28 additions & 0 deletions test/integration/embedders/test_bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
import os
from pathlib import Path

import pytest

from test.integration.embedders.utils import validate_embedding_output, validate_raw_embedder
from test.integration.utils import requires_env
from unstructured_ingest.embed.bedrock import BedrockEmbeddingConfig, BedrockEmbeddingEncoder
from unstructured_ingest.v2.errors import UserAuthError, UserError
from unstructured_ingest.v2.processes.embedder import Embedder, EmbedderConfig


Expand Down Expand Up @@ -47,3 +50,28 @@ def test_raw_bedrock_embedder(embedder_file: Path):
expected_dimensions=(1536,),
expected_is_unit_vector=False,
)


def test_raw_bedrock_embedder_invalid_credentials(embedder_file: Path):
embedder = BedrockEmbeddingEncoder(
config=BedrockEmbeddingConfig(
aws_access_key_id="no_key",
aws_secret_access_key="no_secret",
)
)
with pytest.raises(UserAuthError):
embedder.get_exemplary_embedding()


@requires_env("AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY")
def test_raw_bedrock_embedder_invalid_model(embedder_file: Path):
aws_credentials = get_aws_credentials()
embedder = BedrockEmbeddingEncoder(
config=BedrockEmbeddingConfig(
aws_access_key_id=aws_credentials["aws_access_key_id"],
aws_secret_access_key=aws_credentials["aws_secret_access_key"],
model_name="invalid_model",
)
)
with pytest.raises(UserError):
embedder.get_exemplary_embedding()
14 changes: 14 additions & 0 deletions test/integration/embedders/test_octoai.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
import os
from pathlib import Path

import pytest

from test.integration.embedders.utils import validate_embedding_output, validate_raw_embedder
from test.integration.utils import requires_env
from unstructured_ingest.embed.octoai import OctoAiEmbeddingConfig, OctoAIEmbeddingEncoder
from unstructured_ingest.v2.errors import UserAuthError
from unstructured_ingest.v2.processes.embedder import Embedder, EmbedderConfig

API_KEY = "OCTOAI_API_KEY"
Expand Down Expand Up @@ -39,3 +42,14 @@ def test_raw_octoai_embedder(embedder_file: Path):
validate_raw_embedder(
embedder=embedder, embedder_file=embedder_file, expected_dimensions=(1024,)
)


@pytest.mark.skip(reason="Unexpected connection error at the moment")
def test_raw_octoai_embedder_invalid_credentials():
embedder = OctoAIEmbeddingEncoder(
config=OctoAiEmbeddingConfig(
api_key="fake_api_key",
)
)
with pytest.raises(UserAuthError):
embedder.get_exemplary_embedding()
13 changes: 13 additions & 0 deletions test/integration/embedders/test_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
import os
from pathlib import Path

import pytest

from test.integration.embedders.utils import validate_embedding_output, validate_raw_embedder
from test.integration.utils import requires_env
from unstructured_ingest.embed.openai import OpenAIEmbeddingConfig, OpenAIEmbeddingEncoder
from unstructured_ingest.v2.errors import UserAuthError
from unstructured_ingest.v2.processes.embedder import Embedder, EmbedderConfig

API_KEY = "OPENAI_API_KEY"
Expand Down Expand Up @@ -39,3 +42,13 @@ def test_raw_openai_embedder(embedder_file: Path):
validate_raw_embedder(
embedder=embedder, embedder_file=embedder_file, expected_dimensions=(1536,)
)


def test_raw_openai_embedder_invalid_credentials():
embedder = OpenAIEmbeddingEncoder(
config=OpenAIEmbeddingConfig(
api_key="fake_api_key",
)
)
with pytest.raises(UserAuthError):
embedder.get_exemplary_embedding()
10 changes: 10 additions & 0 deletions test/integration/embedders/test_togetherai.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
import os
from pathlib import Path

import pytest

from test.integration.embedders.utils import validate_embedding_output, validate_raw_embedder
from test.integration.utils import requires_env
from unstructured_ingest.embed.togetherai import (
TogetherAIEmbeddingConfig,
TogetherAIEmbeddingEncoder,
)
from unstructured_ingest.v2.errors import UserAuthError
from unstructured_ingest.v2.processes.embedder import Embedder, EmbedderConfig

API_KEY = "TOGETHERAI_API_KEY"
Expand Down Expand Up @@ -41,3 +44,10 @@ def test_raw_togetherai_embedder(embedder_file: Path):
expected_dimensions=(768,),
expected_is_unit_vector=False,
)


def test_raw_togetherai_embedder_invalid_credentials():
embedder = TogetherAIEmbeddingEncoder(config=TogetherAIEmbeddingConfig(api_key="fake_api_key"))

with pytest.raises(UserAuthError):
embedder.get_exemplary_embedding()
Loading

0 comments on commit 51dfbe1

Please sign in to comment.