fix
This commit is contained in:
parent
3d721e3db8
commit
ce3d7df6eb
1 changed files with 6 additions and 4 deletions
|
|
@ -12,6 +12,7 @@ from typing import Optional, List
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import shutil
|
import shutil
|
||||||
|
import aiofiles
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
|
|
@ -134,7 +135,6 @@ def create_app(args):
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@app.on_event("startup")
|
@app.on_event("startup")
|
||||||
async def startup_event():
|
async def startup_event():
|
||||||
"""Index all files in input directory during startup"""
|
"""Index all files in input directory during startup"""
|
||||||
|
|
@ -142,9 +142,11 @@ def create_app(args):
|
||||||
new_files = doc_manager.scan_directory()
|
new_files = doc_manager.scan_directory()
|
||||||
for file_path in new_files:
|
for file_path in new_files:
|
||||||
try:
|
try:
|
||||||
with open(file_path, 'r', encoding='utf-8') as f:
|
# Use async file reading
|
||||||
content = f.read()
|
async with aiofiles.open(file_path, 'r', encoding='utf-8') as f:
|
||||||
rag.insert(content)
|
content = await f.read()
|
||||||
|
# Use the async version of insert directly
|
||||||
|
await rag.ainsert(content)
|
||||||
doc_manager.mark_as_indexed(file_path)
|
doc_manager.mark_as_indexed(file_path)
|
||||||
logging.info(f"Indexed file: {file_path}")
|
logging.info(f"Indexed file: {file_path}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue