File size: 1,444 Bytes
ca2fff7
 
 
 
 
 
 
 
 
 
 
 
 
edf2758
ca2fff7
edf2758
 
 
 
 
 
 
ca2fff7
 
 
 
edf2758
ca2fff7
edf2758
 
 
 
 
 
 
ca2fff7
 
edf2758
 
ca2fff7
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#This is to init the vector store

from typing import Annotated

from db.vector_store import Store
from document_parsing import generate_documents

from fastapi import APIRouter, Body
from fastapi.responses import JSONResponse
from fastapi import APIRouter, UploadFile, File, Body

router = APIRouter()

@router.put("/v1/datasets")
async def recreate_collection(name: Annotated[str, Body(embed=True)]):
    """ Create a dataset with `name`. 
        **Delete and re-create if one exist.**

    Parameters:
        `name` of the doc to be created.
    Returns:
        None
    """
    print(f"creating collection {name} in db")
    return Store.get_instance().create_collection(name)

@router.post("/v1/datasets")
async def update(name: Annotated[str, Body()], file_name: Annotated[str, Body()], file: UploadFile = File(...)):
    """Update dataset `name` with information from the file.
    Paramters:
        `name` of the collection
        `file` to upload.
        `fileName` name of the file. This is used for metadata purposes only.
    Returns:
        name of the dataset once updated.
    """
    
    #TODO return meaningful info

    _db = Store.get_instance().get_collection(name)
    if not _db:
        return JSONResponse(status_code=404, content={})

    async for doc in generate_documents(file, file_name):
        print(doc)
        _db.add_documents([doc])
    return JSONResponse(status_code=200, content={"name": name})