From 44efd06c72823cb02b61f5a8505e18ab9537e5f5 Mon Sep 17 00:00:00 2001 From: javier-cohere Date: Fri, 13 Sep 2024 09:33:42 +0200 Subject: [PATCH] input uuid by default --- compass_sdk/compass.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/compass_sdk/compass.py b/compass_sdk/compass.py index e153c1e..2163121 100644 --- a/compass_sdk/compass.py +++ b/compass_sdk/compass.py @@ -280,7 +280,8 @@ def parse_and_insert_doc( *, index_name: str, filename: str, - file_uuid: Optional[str] = None, + content_type: str, + file_uuid: Optional[uuid.UUID] = None, max_retries: int = DEFAULT_MAX_RETRIES, sleep_retry_seconds: int = DEFAULT_SLEEP_RETRY_SECONDS, ) -> Optional[str]: @@ -288,18 +289,12 @@ def parse_and_insert_doc( Parse and insert a document into an index in Compass :param index_name: the name of the index :param filename: the filename of the document + :param content_type: the content type of the document :param file_uuid: the id of the document (optional) :param max_retries: the maximum number of times to retry a request if it fails :param sleep_retry_seconds: the number of seconds to wait before retrying an API request :return: an error message if the request failed, otherwise None """ - def is_valid_uuid(fileid: Optional[str]) -> bool: - try: - uuid.UUID(fileid) - return True - except ValueError: - return False - def generate_uuid(b64_string: str) -> uuid.UUID: namespace = uuid.UUID(UUID_NAMESPACE) return uuid.uuid5(namespace, b64_string) @@ -318,15 +313,12 @@ def generate_uuid(b64_string: str) -> uuid.UUID: # Open the file and read the bytes. Get some metadata and send it to Compass b64 = base64.b64encode(doc.filebytes).decode("utf-8") - if file_uuid and not is_valid_uuid(file_uuid): - err = f"Invalid UUID: {file_uuid}. Namespace: {UUID_NAMESPACE}" - logger.error(err) - return err file_uuid = file_uuid or generate_uuid(b64) put_doc_input = ParseableDocument( id=file_uuid, filename=filename, bytes=b64, + content_type=content_type, content_length_bytes=len(doc.filebytes), ) result = self._send_request(