new branch

This commit is contained in:
ACBBZ
2024-05-10 07:21:21 +00:00
committed by superobk
parent 48a01d6f0c
commit 2bcb9d990f
6 changed files with 246 additions and 37 deletions

View File

@ -59,8 +59,11 @@ class ChromaUpsert(Blackbox):
else:
collection_id = "123"
print("file: ",file)
print("file name: ",file.filename)
if file is not None:
file_type = file.split(".")[-1]
file_type = file.filename.split(".")[-1]
print("file_type: ",file_type)
if file_type == "pdf":
loader = PyPDFLoader(file)
elif file_type == "txt":
@ -102,16 +105,12 @@ class ChromaUpsert(Blackbox):
async def fast_api_handler(self, request: Request) -> Response:
try:
data = await request.json()
except:
return JSONResponse(content={"error": "json parse error"}, status_code=status.HTTP_400_BAD_REQUEST)
user_collection_id = data.get("collection_id")
user_file = data.get("file")
user_string = data.get("string")
user_context = data.get("context")
user_setting = data.get("setting")
user_collection_id = (await request.form()).get("collection_id")
user_file = (await request.form()).get("file")
user_string = (await request.form()).get("string")
user_context = (await request.form()).get("context")
user_setting = (await request.form()).get("setting")
if user_collection_id is None and user_setting["collections"] == []:
return JSONResponse(content={"error": "The first creation requires a collection id"}, status_code=status.HTTP_400_BAD_REQUEST)
@ -119,6 +118,17 @@ class ChromaUpsert(Blackbox):
if user_file is None and user_string is None:
return JSONResponse(content={"error": "file or string is required"}, status_code=status.HTTP_400_BAD_REQUEST)
# data = await user_file.read()
# with open(f'./{data.filename}', 'wb') as f:
# f.write(content)
loader = PyPDFLoader(f'./{user_file.filename}')
documents = loader.load()
text_splitter = RecursiveCharacterTextSplitter(chunk_size=512, chunk_overlap=0)
docs = text_splitter.split_documents(documents)
print("docs: ",docs)
return JSONResponse(
content={"response": self.processing(user_collection_id, user_file, user_string, user_context, user_setting)},
status_code=status.HTTP_200_OK)