|
| 1 | +from dataclasses import dataclass |
| 2 | + |
| 3 | +import click |
| 4 | + |
| 5 | +from unstructured.ingest.v2.cli.base import DestCmd |
| 6 | +from unstructured.ingest.v2.cli.interfaces import CliConfig |
| 7 | +from unstructured.ingest.v2.cli.utils import DelimitedString |
| 8 | +from unstructured.ingest.v2.processes.connectors.weaviate import CONNECTOR_TYPE |
| 9 | + |
| 10 | + |
| 11 | +@dataclass |
| 12 | +class WeaviateCliConnectionConfig(CliConfig): |
| 13 | + @staticmethod |
| 14 | + def get_cli_options() -> list[click.Option]: |
| 15 | + options = [ |
| 16 | + click.Option( |
| 17 | + ["--host-url"], |
| 18 | + required=True, |
| 19 | + help="Weaviate instance url", |
| 20 | + ), |
| 21 | + click.Option( |
| 22 | + ["--class-name"], |
| 23 | + default=None, |
| 24 | + type=str, |
| 25 | + help="Name of the class to push the records into, e.g: Pdf-elements", |
| 26 | + ), |
| 27 | + click.Option( |
| 28 | + ["--access-token"], default=None, type=str, help="Used to create the bearer token." |
| 29 | + ), |
| 30 | + click.Option( |
| 31 | + ["--refresh-token"], |
| 32 | + default=None, |
| 33 | + type=str, |
| 34 | + help="Will tie this value to the bearer token. If not provided, " |
| 35 | + "the authentication will expire once the lifetime of the access token is up.", |
| 36 | + ), |
| 37 | + click.Option( |
| 38 | + ["--api-key"], |
| 39 | + default=None, |
| 40 | + type=str, |
| 41 | + ), |
| 42 | + click.Option( |
| 43 | + ["--client-secret"], |
| 44 | + default=None, |
| 45 | + type=str, |
| 46 | + ), |
| 47 | + click.Option( |
| 48 | + ["--scope"], |
| 49 | + default=None, |
| 50 | + type=DelimitedString(), |
| 51 | + ), |
| 52 | + click.Option( |
| 53 | + ["--username"], |
| 54 | + default=None, |
| 55 | + type=str, |
| 56 | + ), |
| 57 | + click.Option( |
| 58 | + ["--password"], |
| 59 | + default=None, |
| 60 | + type=str, |
| 61 | + ), |
| 62 | + click.Option( |
| 63 | + ["--anonymous"], |
| 64 | + is_flag=True, |
| 65 | + default=False, |
| 66 | + type=bool, |
| 67 | + help="if set, all auth values will be ignored", |
| 68 | + ), |
| 69 | + ] |
| 70 | + return options |
| 71 | + |
| 72 | + |
| 73 | +@dataclass |
| 74 | +class WeaviateCliUploaderConfig(CliConfig): |
| 75 | + @staticmethod |
| 76 | + def get_cli_options() -> list[click.Option]: |
| 77 | + options = [ |
| 78 | + click.Option( |
| 79 | + ["--batch-size"], |
| 80 | + default=100, |
| 81 | + type=int, |
| 82 | + help="Number of records per batch", |
| 83 | + ) |
| 84 | + ] |
| 85 | + return options |
| 86 | + |
| 87 | + |
| 88 | +@dataclass |
| 89 | +class WeaviateCliUploadStagerConfig(CliConfig): |
| 90 | + @staticmethod |
| 91 | + def get_cli_options() -> list[click.Option]: |
| 92 | + return [] |
| 93 | + |
| 94 | + |
| 95 | +weaviate_dest_cmd = DestCmd( |
| 96 | + cmd_name=CONNECTOR_TYPE, |
| 97 | + connection_config=WeaviateCliConnectionConfig, |
| 98 | + uploader_config=WeaviateCliUploaderConfig, |
| 99 | + upload_stager_config=WeaviateCliUploadStagerConfig, |
| 100 | +) |
0 commit comments