janar commited on
Commit
edf2758
1 Parent(s): 1412a81

rename to datasets

Browse files
Files changed (2) hide show
  1. api/routes/search.py +11 -5
  2. 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/docs/{name}/answer")
20
  async def answer(name: str, query: str):
21
  """ Answer a question from the doc
22
- `name` of the doc.
23
- `query` to be answered.
 
 
 
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/docs")
34
  async def list() -> list[dict]:
35
- """ List all the docs.
 
 
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/docs")
15
  async def recreate_collection(name: Annotated[str, Body(embed=True)]):
16
- """ `name` of the doc to be created.
17
- If one exits, delete and recreate.
 
 
 
 
 
18
  """
19
  print(f"creating collection {name} in db")
20
  return Store.get_instance().create_collection(name)
21
 
22
- @router.post("/v1/docs")
23
  async def update(name: Annotated[str, Body()], file_name: Annotated[str, Body()], file: UploadFile = File(...)):
24
- """Update an existing document with information from the file.
25
- If one doesn't exist with name, it creates a new document to update.
26
- `name` of the collection
27
- `file` to upload.
28
- `fileName` name of the file. This is used for metadata purposes only.
 
 
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={})