Spaces:
Sleeping
Sleeping
file name & llm verbose for debugging
Browse files- api/routes/search.py +5 -5
api/routes/search.py
CHANGED
@@ -14,10 +14,10 @@ from langchain.llms import OpenAI
|
|
14 |
from db import vector_store
|
15 |
|
16 |
router = APIRouter()
|
17 |
-
_chain = load_qa_chain(OpenAI(temperature=0), chain_type="stuff")
|
18 |
|
19 |
@router.post("/v1/docs")
|
20 |
-
async def create_or_update(name: Annotated[str, Body()],
|
21 |
"""create or update a collection
|
22 |
`name` of the collection
|
23 |
`file` to upload.
|
@@ -27,7 +27,7 @@ async def create_or_update(name: Annotated[str, Body()], fileName: Annotated[str
|
|
27 |
_db = vector_store.get_instance(name)
|
28 |
if not _db:
|
29 |
return JSONResponse(status_code=404, content={})
|
30 |
-
async for doc in generate_documents(file,
|
31 |
print(doc)
|
32 |
_db.add_documents([doc])
|
33 |
#todo return something sensible
|
@@ -46,11 +46,11 @@ async def answer(name: str, query: str):
|
|
46 |
answer = _chain.run(input_documents=[tup[0] for tup in docs], question=query)
|
47 |
return JSONResponse(status_code=200, content={"answer": answer, "file_score": [[f"{d[0].metadata['file']} : {d[0].metadata['page']}", d[1]] for d in docs]})
|
48 |
|
49 |
-
async def generate_documents(file: UploadFile,
|
50 |
num=0
|
51 |
async for txt in convert_documents(file):
|
52 |
num += 1
|
53 |
-
document = Document(page_content=txt,metadata={"file":
|
54 |
yield document
|
55 |
|
56 |
async def convert_documents(file: UploadFile):
|
|
|
14 |
from db import vector_store
|
15 |
|
16 |
router = APIRouter()
|
17 |
+
_chain = load_qa_chain(OpenAI(temperature=0), chain_type="stuff", verbose=True)
|
18 |
|
19 |
@router.post("/v1/docs")
|
20 |
+
async def create_or_update(name: Annotated[str, Body()], file_name: Annotated[str, Body()], file: UploadFile = File(...)):
|
21 |
"""create or update a collection
|
22 |
`name` of the collection
|
23 |
`file` to upload.
|
|
|
27 |
_db = vector_store.get_instance(name)
|
28 |
if not _db:
|
29 |
return JSONResponse(status_code=404, content={})
|
30 |
+
async for doc in generate_documents(file, file_name):
|
31 |
print(doc)
|
32 |
_db.add_documents([doc])
|
33 |
#todo return something sensible
|
|
|
46 |
answer = _chain.run(input_documents=[tup[0] for tup in docs], question=query)
|
47 |
return JSONResponse(status_code=200, content={"answer": answer, "file_score": [[f"{d[0].metadata['file']} : {d[0].metadata['page']}", d[1]] for d in docs]})
|
48 |
|
49 |
+
async def generate_documents(file: UploadFile, file_name: str):
|
50 |
num=0
|
51 |
async for txt in convert_documents(file):
|
52 |
num += 1
|
53 |
+
document = Document(page_content=txt,metadata={"file": file_name, "page": num})
|
54 |
yield document
|
55 |
|
56 |
async def convert_documents(file: UploadFile):
|