Skip to content

Commit

Permalink
Moved conversion settings object creation to cli
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Brandão <[email protected]>
  • Loading branch information
HolyMichael committed Sep 28, 2023
1 parent f403a3f commit c790cf4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
16 changes: 15 additions & 1 deletion deepsearch/cps/cli/data_indices_typer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from deepsearch.cps.client.components.elastic import ElasticProjectDataCollectionSource
from deepsearch.cps.data_indices import utils
from deepsearch.documents.core.common_routines import ERROR_MSG
from deepsearch.documents.core.models import ConversionSettings

app = typer.Typer(no_args_is_help=True)

Expand Down Expand Up @@ -159,13 +160,26 @@ def upload_files(
raise typer.Abort()

coords = ElasticProjectDataCollectionSource(proj_key=proj_key, index_key=index_key)

if type(conv_settings) == str:
try:
final_conv_settings = ConversionSettings.parse_obj(
json.loads(conv_settings)
)
except ValueError as e:
raise ValueError(
"Could not parse a ConversionSettings object from --conv-settings string"
)
else:
final_conv_settings = None

utils.upload_files(
api=api,
coords=coords,
url=urls,
local_file=local_file,
s3_coordinates=cos_coordinates,
conv_settings=conv_settings,
conv_settings=final_conv_settings,
)

typer.echo("Tasks have been queued successfully")
Expand Down
14 changes: 2 additions & 12 deletions deepsearch/cps/data_indices/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,11 @@ def upload_files(
url: Optional[Union[str, List[str]]] = None,
local_file: Optional[Union[str, Path]] = None,
s3_coordinates: Optional[S3Coordinates] = None,
conv_settings: Optional[Union[ConversionSettings, str]] = None,
conv_settings: Optional[ConversionSettings] = None,
):
"""
Orchestrate document conversion and upload to an index in a project
"""
final_conv_settings: Optional[ConversionSettings] = None
if type(conv_settings) == str:
try:
final_conv_settings = ConversionSettings.parse_obj(
json.loads(conv_settings)
)
except ValueError as e:
raise ValueError("Could not parse dict from --conv-settings string")
else:
final_conv_settings = conv_settings # type: ignore # Type checking unnecessarily complicated, string is already taken care of

# check required inputs are present
if url is None and local_file is None and s3_coordinates is None:
Expand All @@ -60,7 +50,7 @@ def upload_files(
api=api,
coords=coords,
local_file=Path(local_file),
conv_settings=final_conv_settings,
conv_settings=conv_settings,
)
elif url is None and local_file is None and s3_coordinates is not None:
return process_external_cos(
Expand Down

0 comments on commit c790cf4

Please sign in to comment.