(
name: Annotated[str, typer.Option(help="Name of dataset to load.")],
input_dir: Annotated[Optional[str], typer.Option(help="Path to directory containing dataset.")] = None,
input_files: Annotated[List[str], typer.Option(help="List of paths to files containing dataset.")] = [],
recursive: Annotated[bool, typer.Option(help="Recursively search for files in directory.")] = False,
extensions: Annotated[str, typer.Option(help="Comma separated list of file extensions to load")] = default_extensions,
user_id: Annotated[Optional[uuid.UUID], typer.Option(help="User ID to associate with dataset.")] = None, # TODO: remove
description: Annotated[Optional[str], typer.Option(help="Description of the source.")] = None,
)
| 25 | |
| 26 | @app.command("directory") |
| 27 | def load_directory( |
| 28 | name: Annotated[str, typer.Option(help="Name of dataset to load.")], |
| 29 | input_dir: Annotated[Optional[str], typer.Option(help="Path to directory containing dataset.")] = None, |
| 30 | input_files: Annotated[List[str], typer.Option(help="List of paths to files containing dataset.")] = [], |
| 31 | recursive: Annotated[bool, typer.Option(help="Recursively search for files in directory.")] = False, |
| 32 | extensions: Annotated[str, typer.Option(help="Comma separated list of file extensions to load")] = default_extensions, |
| 33 | user_id: Annotated[Optional[uuid.UUID], typer.Option(help="User ID to associate with dataset.")] = None, # TODO: remove |
| 34 | description: Annotated[Optional[str], typer.Option(help="Description of the source.")] = None, |
| 35 | ): |
| 36 | client = create_client() |
| 37 | |
| 38 | # create connector |
| 39 | connector = DirectoryConnector(input_files=input_files, input_directory=input_dir, recursive=recursive, extensions=extensions) |
| 40 | |
| 41 | # choose form list of embedding configs |
| 42 | embedding_configs = client.list_embedding_configs() |
| 43 | embedding_options = [embedding_config.embedding_model for embedding_config in embedding_configs] |
| 44 | |
| 45 | embedding_choices = [ |
| 46 | questionary.Choice(title=embedding_config.pretty_print(), value=embedding_config) for embedding_config in embedding_configs |
| 47 | ] |
| 48 | |
| 49 | # select model |
| 50 | if len(embedding_options) == 0: |
| 51 | raise ValueError("No embedding models found. Please enable a provider.") |
| 52 | elif len(embedding_options) == 1: |
| 53 | embedding_model_name = embedding_options[0] |
| 54 | else: |
| 55 | embedding_model_name = questionary.select("Select embedding model:", choices=embedding_choices).ask().embedding_model |
| 56 | embedding_config = [ |
| 57 | embedding_config for embedding_config in embedding_configs if embedding_config.embedding_model == embedding_model_name |
| 58 | ][0] |
| 59 | |
| 60 | # create source |
| 61 | source = client.create_source(name=name, embedding_config=embedding_config) |
| 62 | |
| 63 | # load data |
| 64 | try: |
| 65 | client.load_data(connector, source_name=name) |
| 66 | except Exception as e: |
| 67 | typer.secho(f"Failed to load data from provided information.\n{e}", fg=typer.colors.RED) |
| 68 | client.delete_source(source.id) |
nothing calls this directly
no test coverage detected