Added delete schema

This commit is contained in:
Saurab-Shrestha 2024-02-06 13:28:09 +05:45
parent 0a326c1e43
commit 2fe78b4b5f
8 changed files with 35 additions and 13 deletions

10
.env
View File

@ -16,8 +16,8 @@ ACCESS_TOKEN_EXPIRE_MINUTES=60
REFRESH_TOKEN_EXPIRE_MINUTES = 120 # 7 days REFRESH_TOKEN_EXPIRE_MINUTES = 120 # 7 days
SMTP_SERVER=smtp.gmail.com SMTP_SERVER=mail.gibl.com.np
SMTP_PORT=587 SMTP_PORT=25
SMTP_SENDER_EMAIL=shresthasaurab030@outlook.com SMTP_SENDER_EMAIL=noreply@gibl.com.np
SMTP_USERNAME=shresthasaurab030 SMTP_USERNAME=noreply@gibl.com.np
SMTP_PASSWORD=huurxwxeorxjorzw SMTP_PASSWORD=*G15y^N0reP!y

12
poetry.lock generated
View File

@ -941,6 +941,16 @@ idna = ["idna (>=2.1,<4.0)"]
trio = ["trio (>=0.14,<0.23)"] trio = ["trio (>=0.14,<0.23)"]
wmi = ["wmi (>=1.5.1,<2.0.0)"] wmi = ["wmi (>=1.5.1,<2.0.0)"]
[[package]]
name = "docx2txt"
version = "0.8"
description = "A pure python-based utility to extract text and images from docx files."
optional = false
python-versions = "*"
files = [
{file = "docx2txt-0.8.tar.gz", hash = "sha256:2c06d98d7cfe2d3947e5760a57d924e3ff07745b379c8737723922e7009236e5"},
]
[[package]] [[package]]
name = "ecdsa" name = "ecdsa"
version = "0.18.0" version = "0.18.0"
@ -6306,4 +6316,4 @@ chroma = ["chromadb"]
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = ">=3.11,<3.12" python-versions = ">=3.11,<3.12"
content-hash = "a81365f3feb2e4d69b3d6244c60330549234d13484a787ae8fe6de1b66a201b6" content-hash = "305eb6301c5ad6fae8ca068bf5c4e121c06a342043320f8f2154761df242d904"

View File

@ -4,8 +4,11 @@ import uvicorn
from private_gpt.main import app from private_gpt.main import app
from private_gpt.settings.settings import settings from private_gpt.settings.settings import settings
from fastapi.staticfiles import StaticFiles
# Set log_config=None to do not use the uvicorn logging configuration, and # Set log_config=None to do not use the uvicorn logging configuration, and
# use ours instead. For reference, see below: # use ours instead. For reference, see below:
# https://github.com/tiangolo/fastapi/discussions/7457#discussioncomment-5141108 # https://github.com/tiangolo/fastapi/discussions/7457#discussioncomment-5141108
app.mount("/static", StaticFiles(directory=r"C:\Users\Dbuser\QuickGPT\backend\privateGPT\private_gpt\static"), name="static")
uvicorn.run(app, host="0.0.0.0", port=settings().server.port, log_config=None) uvicorn.run(app, host="0.0.0.0", port=settings().server.port, log_config=None)

View File

@ -2,4 +2,4 @@ import os
from pathlib import Path from pathlib import Path
PROJECT_ROOT_PATH: Path = Path(__file__).parents[1] PROJECT_ROOT_PATH: Path = Path(__file__).parents[1]
UPLOAD_DIR = os.path.join(os.getcwd(), "uploads") UPLOAD_DIR = r"C:\Users\Dbuser\QuickGPT\backend\privateGPT\private_gpt\static"

View File

@ -2,7 +2,7 @@ import logging
from pathlib import Path from pathlib import Path
from typing import Literal from typing import Literal
from fastapi import APIRouter, Depends, HTTPException, Request, UploadFile, File, status, Security from fastapi import APIRouter, Depends, HTTPException, Request, UploadFile, File, status, Security, Body
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
@ -35,6 +35,8 @@ class IngestResponse(BaseModel):
model: Literal["private-gpt"] model: Literal["private-gpt"]
data: list[IngestedDoc] data: list[IngestedDoc]
class DeleteFilename(BaseModel):
filename: str
@ingest_router.post("/ingest", tags=["Ingestion"], deprecated=True) @ingest_router.post("/ingest", tags=["Ingestion"], deprecated=True)
def ingest(request: Request, file: UploadFile) -> IngestResponse: def ingest(request: Request, file: UploadFile) -> IngestResponse:
@ -121,10 +123,10 @@ def delete_ingested(request: Request, doc_id: str) -> None:
service.delete(doc_id) service.delete(doc_id)
@ingest_router.delete("/ingest/file/{filename}", tags=["Ingestion"]) @ingest_router.post("/ingest/file/delete", tags=["Ingestion"])
def delete_file( def delete_file(
request: Request, request: Request,
filename: str, delete_input: DeleteFilename,
current_user: models.User = Security( current_user: models.User = Security(
deps.get_current_user, deps.get_current_user,
)) -> dict: )) -> dict:
@ -133,6 +135,9 @@ def delete_file(
The `filename` can be obtained from the `GET /ingest/list` endpoint. The `filename` can be obtained from the `GET /ingest/list` endpoint.
The document will be effectively deleted from your storage context. The document will be effectively deleted from your storage context.
""" """
filename = delete_input.filename
print(filename)
service = request.state.injector.get(IngestService) service = request.state.injector.get(IngestService)
try: try:
doc_ids = service.get_doc_ids_by_filename(filename) doc_ids = service.get_doc_ids_by_filename(filename)

View File

@ -20,7 +20,7 @@ class Source(BaseModel):
file_name = doc_metadata.get("file_name", "-") if doc_metadata else "-" file_name = doc_metadata.get("file_name", "-") if doc_metadata else "-"
page_label = doc_metadata.get("page_label", "-") if doc_metadata else "-" page_label = doc_metadata.get("page_label", "-") if doc_metadata else "-"
page_link = str(Path(f"{UPLOAD_DIR}/{file_name}#page={page_label}")) page_link = str(f"http://10.1.101.125:88/static/{file_name}#page={page_label}")
source = Source(file=file_name, page=page_label, text=chunk.text, page_link=page_link) source = Source(file=file_name, page=page_label, text=chunk.text, page_link=page_link)
curated_sources.add(source) curated_sources.add(source)

View File

@ -22,8 +22,11 @@ def send_registration_email(fullname: str, email: str, random_password: str) ->
msg["From"] = settings.SMTP_SENDER_EMAIL msg["From"] = settings.SMTP_SENDER_EMAIL
msg["To"] = email msg["To"] = email
print(settings.SMTP_SERVER)
print(settings.SMTP_PORT)
with smtplib.SMTP(settings.SMTP_SERVER, settings.SMTP_PORT) as server: with smtplib.SMTP(settings.SMTP_SERVER, settings.SMTP_PORT) as server:
server.starttls() # server.starttls()
server.login(settings.SMTP_USERNAME, settings.SMTP_PASSWORD) # server.login(settings.SMTP_USERNAME, settings.SMTP_PASSWORD)
server.sendmail(settings.SMTP_SENDER_EMAIL, email, msg.as_string()) server.sendmail(settings.SMTP_SENDER_EMAIL, email, msg.as_string())

View File

@ -23,6 +23,7 @@ bcrypt = "^4.1.2"
python-jose = "^3.3.0" python-jose = "^3.3.0"
psycopg2-binary = "^2.9.9" psycopg2-binary = "^2.9.9"
passlib = "^1.7.4" passlib = "^1.7.4"
docx2txt = "^0.8"
[tool.poetry.group.dev.dependencies] [tool.poetry.group.dev.dependencies]
black = "^22" black = "^22"