feat: Updated the extension for SurfSense v0.0.6

This commit is contained in:
DESKTOP-RTLN3BA\$punk 2025-03-26 20:02:53 -07:00
parent 24fd873ca7
commit 8cd1264d3f
4 changed files with 74 additions and 22 deletions

View file

@ -35,16 +35,14 @@ async def create_documents(
if request.document_type == DocumentType.EXTENSION:
for individual_document in request.content:
fastapi_background_tasks.add_task(
add_extension_received_document,
session,
process_extension_document_with_new_session,
individual_document,
request.search_space_id
)
elif request.document_type == DocumentType.CRAWLED_URL:
for url in request.content:
fastapi_background_tasks.add_task(
add_crawled_url_document,
session,
process_crawled_url_with_new_session,
url,
request.search_space_id
)
@ -97,11 +95,10 @@ async def create_documents(
# Process in background to avoid uvloop conflicts
fastapi_background_tasks.add_task(
process_file_in_background,
process_file_in_background_with_new_session,
temp_path,
file.filename,
search_space_id,
session
search_space_id
)
except Exception as e:
raise HTTPException(
@ -120,6 +117,45 @@ async def create_documents(
detail=f"Failed to upload files: {str(e)}"
)
async def process_extension_document_with_new_session(
individual_document,
search_space_id: int
):
"""Create a new session and process extension document."""
from app.db import async_session_maker
async with async_session_maker() as session:
try:
await add_extension_received_document(session, individual_document, search_space_id)
except Exception as e:
import logging
logging.error(f"Error processing extension document: {str(e)}")
async def process_crawled_url_with_new_session(
url: str,
search_space_id: int
):
"""Create a new session and process crawled URL."""
from app.db import async_session_maker
async with async_session_maker() as session:
try:
await add_crawled_url_document(session, url, search_space_id)
except Exception as e:
import logging
logging.error(f"Error processing crawled URL: {str(e)}")
async def process_file_in_background_with_new_session(
file_path: str,
filename: str,
search_space_id: int
):
"""Create a new session and process file."""
from app.db import async_session_maker
async with async_session_maker() as session:
await process_file_in_background(file_path, filename, search_space_id, session)
async def process_file_in_background(
file_path: str,
filename: str,