diff --git a/lib/chatbot-api/functions/api-handler/routes/documents.py b/lib/chatbot-api/functions/api-handler/routes/documents.py index d74244809..2f29b55ac 100644 --- a/lib/chatbot-api/functions/api-handler/routes/documents.py +++ b/lib/chatbot-api/functions/api-handler/routes/documents.py @@ -65,10 +65,12 @@ class GetDocumentRequest(BaseModel): workspaceId: str documentId: str + class DeleteDocumentRequest(BaseModel): workspaceId: str documentId: str + class GetRssPostsRequest(BaseModel): workspaceId: str documentId: str @@ -135,14 +137,18 @@ def get_documents(input: dict): "lastDocumentId": result["last_document_id"], } + @router.resolver(field_name="deleteDocument") @tracer.capture_method def delete_document(input: dict): request = DeleteDocumentRequest(**input) - result = genai_core.documents.delete_document(request.workspaceId, request.documentId) - + result = genai_core.documents.delete_document( + request.workspaceId, request.documentId + ) + return result + @router.resolver(field_name="getDocument") @tracer.capture_method def get_document_details(input: dict): @@ -307,13 +313,7 @@ def update_rss_feed(input: dict): def _convert_document(document: dict): - if "crawler_properties" in document: - document["crawler_properties"] = { - "followLinks": document["crawler_properties"]["follow_links"], - "limit": document["crawler_properties"]["limit"], - "contentTypes": document["crawler_properties"]["content_types"], - } - return { + converted_document = { "id": document["document_id"], "workspaceId": document["workspace_id"], "type": document["document_type"], @@ -329,11 +329,14 @@ def _convert_document(document: dict): "updatedAt": document.get("updated_at", None), "rssFeedId": document.get("rss_feed_id", None), "rssLastCheckedAt": document.get("rss_last_checked", None), - "crawlerProperties": { + } + if "crawler_properties" in document: + converted_document["crawlerProperties"] = { "followLinks": document.get("crawler_properties").get("follow_links", None), "limit": document.get("crawler_properties").get("limit", None), - "contentTypes": document.get("crawler_properties").get("content_types", None), + "contentTypes": document.get("crawler_properties").get( + "content_types", None + ), } - if document.get("crawler_properties", None) != None - else None, - } + + return converted_document