forked from open-webui/open-webui
refac: file upload
This commit is contained in:
parent
ffd0a5a2a0
commit
d6a1bf1406
2 changed files with 11 additions and 7 deletions
|
@ -24,7 +24,7 @@ from typing import Optional
|
|||
|
||||
import uuid
|
||||
|
||||
|
||||
from utils.misc import calculate_sha256
|
||||
from utils.utils import get_current_user
|
||||
from config import UPLOAD_DIR, EMBED_MODEL, CHROMA_CLIENT, CHUNK_SIZE, CHUNK_OVERLAP
|
||||
from constants import ERROR_MESSAGES
|
||||
|
@ -123,12 +123,11 @@ def store_web(form_data: StoreWebForm, user=Depends(get_current_user)):
|
|||
|
||||
@app.post("/doc")
|
||||
def store_doc(
|
||||
collection_name: str = Form(...),
|
||||
collection_name: Optional[str] = Form(None),
|
||||
file: UploadFile = File(...),
|
||||
user=Depends(get_current_user),
|
||||
):
|
||||
# "https://www.gutenberg.org/files/1727/1727-h/1727-h.htm"
|
||||
file.filename = f"{collection_name}-{file.filename}"
|
||||
|
||||
if file.content_type not in ["application/pdf", "text/plain"]:
|
||||
raise HTTPException(
|
||||
|
@ -144,6 +143,11 @@ def store_doc(
|
|||
f.write(contents)
|
||||
f.close()
|
||||
|
||||
f = open(file_path, "rb")
|
||||
if collection_name == None:
|
||||
collection_name = calculate_sha256(f)[:63]
|
||||
f.close()
|
||||
|
||||
if file.content_type == "application/pdf":
|
||||
loader = PyPDFLoader(file_path)
|
||||
elif file.content_type == "text/plain":
|
||||
|
|
|
@ -124,8 +124,8 @@
|
|||
reader.readAsDataURL(file);
|
||||
} else if (['application/pdf', 'text/plain'].includes(file['type'])) {
|
||||
console.log(file);
|
||||
const hash = (await calculateSHA256(file)).substring(0, 63);
|
||||
const res = await uploadDocToVectorDB(localStorage.token, hash, file);
|
||||
// const hash = (await calculateSHA256(file)).substring(0, 63);
|
||||
const res = await uploadDocToVectorDB(localStorage.token, '', file);
|
||||
|
||||
if (res) {
|
||||
files = [
|
||||
|
@ -243,8 +243,8 @@
|
|||
reader.readAsDataURL(file);
|
||||
} else if (['application/pdf', 'text/plain'].includes(file['type'])) {
|
||||
console.log(file);
|
||||
const hash = (await calculateSHA256(file)).substring(0, 63);
|
||||
const res = await uploadDocToVectorDB(localStorage.token, hash, file);
|
||||
// const hash = (await calculateSHA256(file)).substring(0, 63);
|
||||
const res = await uploadDocToVectorDB(localStorage.token, '', file);
|
||||
|
||||
if (res) {
|
||||
files = [
|
||||
|
|
Loading…
Reference in a new issue