Added api for document listing

This commit is contained in:
Saurab-Shrestha 2024-02-19 17:28:29 +05:45
parent c8b39c898c
commit c45f5b993d
2 changed files with 29 additions and 2 deletions

View File

@ -15,7 +15,7 @@ from private_gpt.server.ingest.ingest_router import common_ingest_logic, IngestR
from private_gpt.constants import OCR_UPLOAD from private_gpt.constants import OCR_UPLOAD
pdf_router = APIRouter(prefix="/pdf", tags=["ocr"]) pdf_router = APIRouter(prefix="/v1", tags=["ocr"])
@pdf_router.post("/pdf_ocr") @pdf_router.post("/pdf_ocr")

View File

@ -1,7 +1,7 @@
import os import os
import logging import logging
from pathlib import Path from pathlib import Path
from typing import Literal, Optional from typing import Literal, Optional, List
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from fastapi import APIRouter, Depends, HTTPException, Request, UploadFile, File, status, Security, Body from fastapi import APIRouter, Depends, HTTPException, Request, UploadFile, File, status, Security, Body
@ -275,3 +275,30 @@ async def common_ingest_logic(
status_code=500, status_code=500,
detail="Internal Server Error: Unable to ingest file.", detail="Internal Server Error: Unable to ingest file.",
) )
from private_gpt.users.schemas import Document
@ingest_router.get("/ingest/list_files", response_model=List[schemas.Document], tags=["Ingestion"])
def list_files(
request: Request,
db: Session = Depends(deps.get_db),
skip: int = 0,
limit: int = 100,
current_user: models.User = Security(
deps.get_current_user,
scopes=[Role.ADMIN["name"], Role.SUPER_ADMIN["name"]],
)
):
try:
docs = crud.documents.get_multi(db, skip=skip, limit=limit)
return docs
except Exception as e:
logger.error(f"There was an error uploading the file(s): {str(e)}")
print("ERROR: ", e)
raise HTTPException(
status_code=500,
detail="Internal Server Error: Unable to ingest file.",
)