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
83986620
Commit
83986620
authored
Jun 18, 2024
by
Timothy J. Baek
Browse files
refac
parent
9e7b7a89
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
66 additions
and
11 deletions
+66
-11
backend/apps/rag/main.py
backend/apps/rag/main.py
+3
-0
backend/apps/webui/models/files.py
backend/apps/webui/models/files.py
+9
-0
backend/apps/webui/routers/files.py
backend/apps/webui/routers/files.py
+18
-0
src/lib/apis/files/index.ts
src/lib/apis/files/index.ts
+0
-1
src/lib/apis/rag/index.ts
src/lib/apis/rag/index.ts
+1
-0
src/lib/components/chat/MessageInput.svelte
src/lib/components/chat/MessageInput.svelte
+2
-3
src/lib/utils/characters/index.ts
src/lib/utils/characters/index.ts
+31
-7
src/routes/(app)/workspace/models/create/+page.svelte
src/routes/(app)/workspace/models/create/+page.svelte
+2
-0
No files found.
backend/apps/rag/main.py
View file @
83986620
...
@@ -1136,6 +1136,7 @@ def store_doc(
...
@@ -1136,6 +1136,7 @@ def store_doc(
class
ProcessDocForm
(
BaseModel
):
class
ProcessDocForm
(
BaseModel
):
file_id
:
str
file_id
:
str
collection_name
:
Optional
[
str
]
=
None
@
app
.
post
(
"/process/doc"
)
@
app
.
post
(
"/process/doc"
)
...
@@ -1148,6 +1149,8 @@ def process_doc(
...
@@ -1148,6 +1149,8 @@ def process_doc(
file_path
=
file
.
meta
.
get
(
"path"
,
f
"
{
UPLOAD_DIR
}
/
{
file
.
filename
}
"
)
file_path
=
file
.
meta
.
get
(
"path"
,
f
"
{
UPLOAD_DIR
}
/
{
file
.
filename
}
"
)
f
=
open
(
file_path
,
"rb"
)
f
=
open
(
file_path
,
"rb"
)
collection_name
=
form_data
.
collection_name
if
collection_name
==
None
:
if
collection_name
==
None
:
collection_name
=
calculate_sha256
(
f
)[:
63
]
collection_name
=
calculate_sha256
(
f
)[:
63
]
f
.
close
()
f
.
close
()
...
...
backend/apps/webui/models/files.py
View file @
83986620
...
@@ -99,5 +99,14 @@ class FilesTable:
...
@@ -99,5 +99,14 @@ class FilesTable:
except
:
except
:
return
False
return
False
def
delete_all_files
(
self
)
->
bool
:
try
:
query
=
File
.
delete
()
query
.
execute
()
# Remove the rows, return number of rows removed.
return
True
except
:
return
False
Files
=
FilesTable
(
DB
)
Files
=
FilesTable
(
DB
)
backend/apps/webui/routers/files.py
View file @
83986620
...
@@ -53,6 +53,7 @@ def upload_file(
...
@@ -53,6 +53,7 @@ def upload_file(
# replace filename with uuid
# replace filename with uuid
id
=
str
(
uuid
.
uuid4
())
id
=
str
(
uuid
.
uuid4
())
filename
=
f
"
{
id
}
_
{
filename
}
"
file_path
=
f
"
{
UPLOAD_DIR
}
/
{
filename
}
"
file_path
=
f
"
{
UPLOAD_DIR
}
/
{
filename
}
"
contents
=
file
.
file
.
read
()
contents
=
file
.
file
.
read
()
...
@@ -143,3 +144,20 @@ async def delete_file_by_id(id: str, user=Depends(get_verified_user)):
...
@@ -143,3 +144,20 @@ async def delete_file_by_id(id: str, user=Depends(get_verified_user)):
status_code
=
status
.
HTTP_401_UNAUTHORIZED
,
status_code
=
status
.
HTTP_401_UNAUTHORIZED
,
detail
=
ERROR_MESSAGES
.
NOT_FOUND
,
detail
=
ERROR_MESSAGES
.
NOT_FOUND
,
)
)
############################
# Delete All Files
############################
@
router
.
delete
(
"/all"
)
async
def
delete_all_files
(
user
=
Depends
(
get_admin_user
)):
result
=
Files
.
delete_all_files
()
if
result
:
return
{
"message"
:
"All files deleted successfully"
}
else
:
raise
HTTPException
(
status_code
=
status
.
HTTP_400_BAD_REQUEST
,
detail
=
ERROR_MESSAGES
.
DEFAULT
(
"Error deleting files"
),
)
src/lib/apis/files/index.ts
View file @
83986620
...
@@ -9,7 +9,6 @@ export const uploadFile = async (token: string, file: File) => {
...
@@ -9,7 +9,6 @@ export const uploadFile = async (token: string, file: File) => {
method
:
'
POST
'
,
method
:
'
POST
'
,
headers
:
{
headers
:
{
Accept
:
'
application/json
'
,
Accept
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
authorization
:
`Bearer
${
token
}
`
authorization
:
`Bearer
${
token
}
`
},
},
body
:
data
body
:
data
...
...
src/lib/apis/rag/index.ts
View file @
83986620
...
@@ -171,6 +171,7 @@ export const processDocToVectorDB = async (token: string, file_id: string) => {
...
@@ -171,6 +171,7 @@ export const processDocToVectorDB = async (token: string, file_id: string) => {
method
:
'
POST
'
,
method
:
'
POST
'
,
headers
:
{
headers
:
{
Accept
:
'
application/json
'
,
Accept
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
authorization
:
`Bearer
${
token
}
`
authorization
:
`Bearer
${
token
}
`
},
},
body
:
JSON
.
stringify
({
body
:
JSON
.
stringify
({
...
...
src/lib/components/chat/MessageInput.svelte
View file @
83986620
...
@@ -147,7 +147,6 @@
...
@@ -147,7 +147,6 @@
if (res) {
if (res) {
fileItem.status = 'processed';
fileItem.status = 'processed';
fileItem.collection_name = res.collection_name;
files = files;
files = files;
}
}
} catch (e) {
} catch (e) {
...
@@ -523,12 +522,12 @@
...
@@ -523,12 +522,12 @@
</Tooltip>
</Tooltip>
{/if}
{/if}
</div>
</div>
{:else if
file.type === 'doc'
}
{:else if
['doc', 'file'].includes(file.type)
}
<div
<div
class="h-16 w-[15rem] flex items-center space-x-3 px-2.5 dark:bg-gray-600 rounded-xl border border-gray-200 dark:border-none"
class="h-16 w-[15rem] flex items-center space-x-3 px-2.5 dark:bg-gray-600 rounded-xl border border-gray-200 dark:border-none"
>
>
<div class="p-2.5 bg-red-400 text-white rounded-lg">
<div class="p-2.5 bg-red-400 text-white rounded-lg">
{#if file.
upload_status
}
{#if file.
status === 'processed'
}
<svg
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
viewBox="0 0 24 24"
...
...
src/lib/utils/characters/index.ts
View file @
83986620
...
@@ -117,15 +117,39 @@ const decodeTextChunk = (data) => {
...
@@ -117,15 +117,39 @@ const decodeTextChunk = (data) => {
const
extractCharacter
=
(
json
)
=>
{
const
extractCharacter
=
(
json
)
=>
{
function
getTrimmedValue
(
json
,
keys
)
{
function
getTrimmedValue
(
json
,
keys
)
{
return
keys
.
map
((
key
)
=>
json
[
key
]).
find
((
value
)
=>
value
&&
value
.
trim
());
return
keys
.
map
((
key
)
=>
{
const
keyParts
=
key
.
split
(
'
.
'
);
let
value
=
json
;
for
(
const
part
of
keyParts
)
{
if
(
value
&&
value
[
part
]
!=
null
)
{
value
=
value
[
part
];
}
else
{
value
=
null
;
break
;
}
}
return
value
&&
value
.
trim
();
})
.
find
((
value
)
=>
value
);
}
}
const
name
=
getTrimmedValue
(
json
,
[
'
char_name
'
,
'
name
'
]);
const
name
=
getTrimmedValue
(
json
,
[
'
char_name
'
,
'
name
'
,
'
data.name
'
]);
const
summary
=
getTrimmedValue
(
json
,
[
'
personality
'
,
'
title
'
]);
const
summary
=
getTrimmedValue
(
json
,
[
'
personality
'
,
'
title
'
,
'
data.description
'
]);
const
personality
=
getTrimmedValue
(
json
,
[
'
char_persona
'
,
'
description
'
]);
const
personality
=
getTrimmedValue
(
json
,
[
'
char_persona
'
,
'
description
'
,
'
data.personality
'
]);
const
scenario
=
getTrimmedValue
(
json
,
[
'
world_scenario
'
,
'
scenario
'
]);
const
scenario
=
getTrimmedValue
(
json
,
[
'
world_scenario
'
,
'
scenario
'
,
'
data.scenario
'
]);
const
greeting
=
getTrimmedValue
(
json
,
[
'
char_greeting
'
,
'
greeting
'
,
'
first_mes
'
]);
const
greeting
=
getTrimmedValue
(
json
,
[
const
examples
=
getTrimmedValue
(
json
,
[
'
example_dialogue
'
,
'
mes_example
'
,
'
definition
'
]);
'
char_greeting
'
,
'
greeting
'
,
'
first_mes
'
,
'
data.first_mes
'
]);
const
examples
=
getTrimmedValue
(
json
,
[
'
example_dialogue
'
,
'
mes_example
'
,
'
definition
'
,
'
data.mes_example
'
]);
return
{
name
,
summary
,
personality
,
scenario
,
greeting
,
examples
};
return
{
name
,
summary
,
personality
,
scenario
,
greeting
,
examples
};
};
};
...
...
src/routes/(app)/workspace/models/create/+page.svelte
View file @
83986620
...
@@ -226,6 +226,8 @@
...
@@ -226,6 +226,8 @@
return null;
return null;
});
});
console.log(character);
if (character && character.character) {
if (character && character.character) {
character = character.character;
character = character.character;
console.log(character);
console.log(character);
...
...
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