Spaces:
Sleeping
Sleeping
rename to datasets
Browse files- api/routes/search.py +11 -5
- api/routes/upload.py +18 -9
api/routes/search.py
CHANGED
|
@@ -16,11 +16,14 @@ router = APIRouter()
|
|
| 16 |
_chain = load_qa_chain(OpenAI(temperature=0), chain_type="stuff", verbose=True)
|
| 17 |
|
| 18 |
|
| 19 |
-
@router.get("/v1/
|
| 20 |
async def answer(name: str, query: str):
|
| 21 |
""" Answer a question from the doc
|
| 22 |
-
|
| 23 |
-
`
|
|
|
|
|
|
|
|
|
|
| 24 |
"""
|
| 25 |
_db = Store.get_instance().get_collection(name)
|
| 26 |
print(query)
|
|
@@ -30,8 +33,11 @@ async def answer(name: str, query: str):
|
|
| 30 |
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]})
|
| 31 |
|
| 32 |
|
| 33 |
-
@router.get("/v1/
|
| 34 |
async def list() -> list[dict]:
|
| 35 |
-
""" List all the
|
|
|
|
|
|
|
| 36 |
"""
|
|
|
|
| 37 |
return Store.get_instance().list_collections()
|
|
|
|
| 16 |
_chain = load_qa_chain(OpenAI(temperature=0), chain_type="stuff", verbose=True)
|
| 17 |
|
| 18 |
|
| 19 |
+
@router.get("/v1/datasets/{name}/answer")
|
| 20 |
async def answer(name: str, query: str):
|
| 21 |
""" Answer a question from the doc
|
| 22 |
+
Parameters:
|
| 23 |
+
- `name` of the doc.
|
| 24 |
+
- `query` to be answered.
|
| 25 |
+
Return:
|
| 26 |
+
a string answer to the query
|
| 27 |
"""
|
| 28 |
_db = Store.get_instance().get_collection(name)
|
| 29 |
print(query)
|
|
|
|
| 33 |
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]})
|
| 34 |
|
| 35 |
|
| 36 |
+
@router.get("/v1/datasets")
|
| 37 |
async def list() -> list[dict]:
|
| 38 |
+
""" List all the datasets avaialble to query.
|
| 39 |
+
:return:
|
| 40 |
+
list of datasets
|
| 41 |
"""
|
| 42 |
+
#TODO surface more metadata for individual datasets
|
| 43 |
return Store.get_instance().list_collections()
|
api/routes/upload.py
CHANGED
|
@@ -11,23 +11,32 @@ from fastapi import APIRouter, UploadFile, File, Body
|
|
| 11 |
|
| 12 |
router = APIRouter()
|
| 13 |
|
| 14 |
-
@router.put("/v1/
|
| 15 |
async def recreate_collection(name: Annotated[str, Body(embed=True)]):
|
| 16 |
-
"""
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
print(f"creating collection {name} in db")
|
| 20 |
return Store.get_instance().create_collection(name)
|
| 21 |
|
| 22 |
-
@router.post("/v1/
|
| 23 |
async def update(name: Annotated[str, Body()], file_name: Annotated[str, Body()], file: UploadFile = File(...)):
|
| 24 |
-
"""Update
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
| 29 |
"""
|
| 30 |
|
|
|
|
|
|
|
| 31 |
_db = Store.get_instance().get_collection(name)
|
| 32 |
if not _db:
|
| 33 |
return JSONResponse(status_code=404, content={})
|
|
|
|
| 11 |
|
| 12 |
router = APIRouter()
|
| 13 |
|
| 14 |
+
@router.put("/v1/datasets")
|
| 15 |
async def recreate_collection(name: Annotated[str, Body(embed=True)]):
|
| 16 |
+
""" Create a dataset with `name`.
|
| 17 |
+
**Delete and re-create if one exist.**
|
| 18 |
+
|
| 19 |
+
Parameters:
|
| 20 |
+
`name` of the doc to be created.
|
| 21 |
+
Returns:
|
| 22 |
+
None
|
| 23 |
"""
|
| 24 |
print(f"creating collection {name} in db")
|
| 25 |
return Store.get_instance().create_collection(name)
|
| 26 |
|
| 27 |
+
@router.post("/v1/datasets")
|
| 28 |
async def update(name: Annotated[str, Body()], file_name: Annotated[str, Body()], file: UploadFile = File(...)):
|
| 29 |
+
"""Update dataset `name` with information from the file.
|
| 30 |
+
Paramters:
|
| 31 |
+
`name` of the collection
|
| 32 |
+
`file` to upload.
|
| 33 |
+
`fileName` name of the file. This is used for metadata purposes only.
|
| 34 |
+
Returns:
|
| 35 |
+
name of the dataset once updated.
|
| 36 |
"""
|
| 37 |
|
| 38 |
+
#TODO return meaningful info
|
| 39 |
+
|
| 40 |
_db = Store.get_instance().get_collection(name)
|
| 41 |
if not _db:
|
| 42 |
return JSONResponse(status_code=404, content={})
|