fix
This commit is contained in:
parent
e783d92eca
commit
0084ae6bc0
@ -65,24 +65,6 @@ def _get_service() -> ITextProcessor:
|
||||
return get_processor_service()
|
||||
|
||||
|
||||
def _to_domain_strategy(request_strategy) -> ChunkingStrategy:
|
||||
"""
|
||||
Convert API request strategy to domain model.
|
||||
|
||||
Args:
|
||||
request_strategy: API request strategy schema
|
||||
|
||||
Returns:
|
||||
ChunkingStrategy: Domain strategy model
|
||||
"""
|
||||
return ChunkingStrategy(
|
||||
strategy_name=request_strategy.strategy_name,
|
||||
chunk_size=request_strategy.chunk_size,
|
||||
overlap_size=request_strategy.overlap_size,
|
||||
respect_boundaries=request_strategy.respect_boundaries,
|
||||
)
|
||||
|
||||
|
||||
def _to_document_response(document) -> DocumentResponse:
|
||||
"""
|
||||
Convert domain document to API response.
|
||||
@ -221,14 +203,14 @@ async def process_file(
|
||||
# Pull service from bootstrap
|
||||
service: ITextProcessor = _get_service()
|
||||
|
||||
# Create temporary file with appropriate suffix
|
||||
suffix = Path(file.filename).suffix if file.filename else ".tmp"
|
||||
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=suffix)
|
||||
temp_file_path = Path(temp_file.name)
|
||||
# Create temporary directory and file with original filename
|
||||
temp_dir = tempfile.mkdtemp()
|
||||
original_filename = file.filename if file.filename else "uploaded_file.tmp"
|
||||
temp_file_path = Path(temp_dir) / original_filename
|
||||
|
||||
# Copy uploaded file to temporary location
|
||||
logger.info(f"Processing uploaded file: {file.filename}")
|
||||
with temp_file:
|
||||
with open(temp_file_path, 'wb') as temp_file:
|
||||
shutil.copyfileobj(file.file, temp_file)
|
||||
|
||||
# Create chunking strategy
|
||||
@ -261,13 +243,14 @@ async def process_file(
|
||||
detail=f"Internal server error: {str(e)}",
|
||||
)
|
||||
finally:
|
||||
# Clean up temporary file
|
||||
# Clean up temporary file and directory
|
||||
if temp_file_path and temp_file_path.exists():
|
||||
try:
|
||||
temp_file_path.unlink()
|
||||
logger.debug(f"Cleaned up temporary file: {temp_file_path}")
|
||||
temp_dir = temp_file_path.parent
|
||||
shutil.rmtree(temp_dir)
|
||||
logger.debug(f"Cleaned up temporary directory: {temp_dir}")
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to delete temporary file {temp_file_path}: {str(e)}")
|
||||
logger.warning(f"Failed to delete temporary directory: {str(e)}")
|
||||
|
||||
|
||||
@router.get(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user