Skip to content

Commit

Permalink
input uuid by default
Browse files Browse the repository at this point in the history
  • Loading branch information
javier-cohere authored and javier-cohere committed Sep 13, 2024
1 parent 3f6b737 commit 44efd06
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions compass_sdk/compass.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,26 +280,21 @@ 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]:
"""
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)
Expand All @@ -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,

Check failure on line 321 in compass_sdk/compass.py

View workflow job for this annotation

GitHub Actions / typecheck (3.11, .)

No parameter named "content_type" (reportCallIssue)
content_length_bytes=len(doc.filebytes),
)
result = self._send_request(
Expand Down

0 comments on commit 44efd06

Please sign in to comment.