Skip to content

Commit

Permalink
PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsbatista committed Feb 20, 2024
1 parent 2428de5 commit f2994c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(
"""

self.api_url = api_url
self.api_key = api_key.resolve_value() if api_key else None
self.api_key = api_key
self.document_creation_mode = document_creation_mode
self.unstructured_kwargs = unstructured_kwargs or {}
self.separator = separator
Expand All @@ -67,7 +67,7 @@ def __init__(
is_hosted_api = api_url == UNSTRUCTURED_HOSTED_API_URL

# we check whether api_key is None or an empty string
if is_hosted_api and not api_key:
if is_hosted_api and not self.api_key:
msg = (
"To use the hosted version of Unstructured, you need to set the environment variable "
"UNSTRUCTURED_API_KEY (recommended) or explicitly pass the parameter api_key."
Expand Down Expand Up @@ -194,7 +194,10 @@ def _partition_file_into_elements(self, filepath: Path) -> List[Element]:
elements = []
try:
elements = partition_via_api(
filename=str(filepath), api_url=self.api_url, api_key=self.api_key, **self.unstructured_kwargs
filename=str(filepath),
api_url=self.api_url,
api_key=self.api_key.resolve_value() if self.api_key else None,
**self.unstructured_kwargs,
)
except Exception as e:
logger.warning(f"Unstructured could not process file {filepath}. Error: {e}")
Expand Down
4 changes: 2 additions & 2 deletions integrations/unstructured/tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class TestUnstructuredFileConverter:
@pytest.mark.usefixtures("set_env_variables")
def test_init_default(self):
converter = UnstructuredFileConverter()
assert converter.api_url == "https://api.unstructured.io/general/v0/general"
Expand All @@ -17,6 +16,7 @@ def test_init_default(self):
assert converter.unstructured_kwargs == {}
assert converter.progress_bar

@pytest.mark.usefixtures("set_env_variables")
def test_init_with_parameters(self):
converter = UnstructuredFileConverter(
api_url="http://custom-url:8000/general",
Expand All @@ -41,7 +41,7 @@ def test_to_dict(self):
"type": "haystack_integrations.components.converters.unstructured.converter.UnstructuredFileConverter",
"init_parameters": {
"api_url": "https://api.unstructured.io/general/v0/general",
"api_key": {"env_vars": ["UNSTRUCTURED_API_KEY"], "strict": True, "type": "env_var"},
"api_key": {"env_vars": ["UNSTRUCTURED_API_KEY"], "strict": False, "type": "env_var"},
"document_creation_mode": "one-doc-per-file",
"separator": "\n\n",
"unstructured_kwargs": {},
Expand Down

0 comments on commit f2994c5

Please sign in to comment.