RAG-retrieval / utils /handle_file.py
yasirme's picture
Update utils/handle_file.py
17117b0 verified
from utils.file_reader import file_reader
from rag.RAG import rag
class HandleFiles:
def __init__(self):
pass
def handle_files(self,files,allowed_chars):
try:
result = {
"files": {},
"total_chars": 0
}
content,status_code = file_reader.calc_chars(files,allowed_chars)
if(status_code!=200):
return content,status_code
for text_dict in content['clean_contents']:
embedding, status_code = rag.generate_embedding(text_dict['content'])
if(status_code!=200):
return embedding,status_code
result['files'][str(text_dict['id'])] = {
"name": text_dict['name'],
"type": text_dict['type'],
"total_chars": text_dict['total_chars'],
"embeddings": embedding['embeddings'],
"chunks": embedding['chunks']
}
result['total_chars'] = content['total_chars']
return result
except Exception as e:
return {"error": f"an error occured: {e}"}, 500
file_handler = HandleFiles()