Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
d6a1bf14
Commit
d6a1bf14
authored
Jan 07, 2024
by
Timothy J. Baek
Browse files
refac: file upload
parent
ffd0a5a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
7 deletions
+11
-7
backend/apps/rag/main.py
backend/apps/rag/main.py
+7
-3
src/lib/components/chat/MessageInput.svelte
src/lib/components/chat/MessageInput.svelte
+4
-4
No files found.
backend/apps/rag/main.py
View file @
d6a1bf14
...
@@ -24,7 +24,7 @@ from typing import Optional
...
@@ -24,7 +24,7 @@ from typing import Optional
import
uuid
import
uuid
from
utils.misc
import
calculate_sha256
from
utils.utils
import
get_current_user
from
utils.utils
import
get_current_user
from
config
import
UPLOAD_DIR
,
EMBED_MODEL
,
CHROMA_CLIENT
,
CHUNK_SIZE
,
CHUNK_OVERLAP
from
config
import
UPLOAD_DIR
,
EMBED_MODEL
,
CHROMA_CLIENT
,
CHUNK_SIZE
,
CHUNK_OVERLAP
from
constants
import
ERROR_MESSAGES
from
constants
import
ERROR_MESSAGES
...
@@ -123,12 +123,11 @@ def store_web(form_data: StoreWebForm, user=Depends(get_current_user)):
...
@@ -123,12 +123,11 @@ def store_web(form_data: StoreWebForm, user=Depends(get_current_user)):
@
app
.
post
(
"/doc"
)
@
app
.
post
(
"/doc"
)
def
store_doc
(
def
store_doc
(
collection_name
:
str
=
Form
(
...
),
collection_name
:
Optional
[
str
]
=
Form
(
None
),
file
:
UploadFile
=
File
(...),
file
:
UploadFile
=
File
(...),
user
=
Depends
(
get_current_user
),
user
=
Depends
(
get_current_user
),
):
):
# "https://www.gutenberg.org/files/1727/1727-h/1727-h.htm"
# "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"
]:
if
file
.
content_type
not
in
[
"application/pdf"
,
"text/plain"
]:
raise
HTTPException
(
raise
HTTPException
(
...
@@ -144,6 +143,11 @@ def store_doc(
...
@@ -144,6 +143,11 @@ def store_doc(
f
.
write
(
contents
)
f
.
write
(
contents
)
f
.
close
()
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"
:
if
file
.
content_type
==
"application/pdf"
:
loader
=
PyPDFLoader
(
file_path
)
loader
=
PyPDFLoader
(
file_path
)
elif
file
.
content_type
==
"text/plain"
:
elif
file
.
content_type
==
"text/plain"
:
...
...
src/lib/components/chat/MessageInput.svelte
View file @
d6a1bf14
...
@@ -124,8 +124,8 @@
...
@@ -124,8 +124,8 @@
reader.readAsDataURL(file);
reader.readAsDataURL(file);
} else if (['application/pdf', 'text/plain'].includes(file['type'])) {
} else if (['application/pdf', 'text/plain'].includes(file['type'])) {
console.log(file);
console.log(file);
const hash = (await calculateSHA256(file)).substring(0, 63);
//
const hash = (await calculateSHA256(file)).substring(0, 63);
const res = await uploadDocToVectorDB(localStorage.token,
hash
, file);
const res = await uploadDocToVectorDB(localStorage.token,
''
, file);
if (res) {
if (res) {
files = [
files = [
...
@@ -243,8 +243,8 @@
...
@@ -243,8 +243,8 @@
reader.readAsDataURL(file);
reader.readAsDataURL(file);
} else if (['application/pdf', 'text/plain'].includes(file['type'])) {
} else if (['application/pdf', 'text/plain'].includes(file['type'])) {
console.log(file);
console.log(file);
const hash = (await calculateSHA256(file)).substring(0, 63);
//
const hash = (await calculateSHA256(file)).substring(0, 63);
const res = await uploadDocToVectorDB(localStorage.token,
hash
, file);
const res = await uploadDocToVectorDB(localStorage.token,
''
, file);
if (res) {
if (res) {
files = [
files = [
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment