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
6350d86b
Commit
6350d86b
authored
Dec 25, 2023
by
Timothy J. Baek
Browse files
fix: chat model schema
parent
8d5c3ee5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
19 deletions
+23
-19
backend/apps/web/models/auths.py
backend/apps/web/models/auths.py
+15
-13
backend/apps/web/models/chats.py
backend/apps/web/models/chats.py
+8
-6
No files found.
backend/apps/web/models/auths.py
View file @
6350d86b
...
...
@@ -98,21 +98,23 @@ class AuthsTable:
def
authenticate_user
(
self
,
email
:
str
,
password
:
str
)
->
Optional
[
UserModel
]:
print
(
"authenticate_user"
,
email
)
auth
=
Auth
.
get
(
Auth
.
email
==
email
,
Auth
.
active
==
True
)
print
(
auth
.
email
)
if
auth
:
print
(
password
,
str
(
auth
.
password
))
print
(
verify_password
(
password
,
str
(
auth
.
password
)))
if
verify_password
(
password
,
auth
.
password
):
user
=
Users
.
get_user_by_id
(
auth
.
id
)
print
(
user
)
return
user
try
:
auth
=
Auth
.
get
(
Auth
.
email
==
email
,
Auth
.
active
==
True
)
print
(
auth
.
email
)
if
auth
:
print
(
password
,
str
(
auth
.
password
))
print
(
verify_password
(
password
,
str
(
auth
.
password
)))
if
verify_password
(
password
,
auth
.
password
):
user
=
Users
.
get_user_by_id
(
auth
.
id
)
print
(
user
)
return
user
else
:
return
None
else
:
return
None
e
lse
:
e
xcept
:
return
None
...
...
backend/apps/web/models/chats.py
View file @
6350d86b
...
...
@@ -18,7 +18,7 @@ from apps.web.internal.db import DB
class
Chat
(
Model
):
id
=
CharField
(
unique
=
True
)
user_id
:
CharField
()
user_id
=
CharField
()
title
=
CharField
()
chat
=
TextField
()
# Save Chat JSON as Text
timestamp
=
DateField
()
...
...
@@ -31,7 +31,7 @@ class ChatModel(BaseModel):
id
:
str
user_id
:
str
title
:
str
chat
:
dict
chat
:
str
timestamp
:
int
# timestamp in epoch
...
...
@@ -64,8 +64,10 @@ class ChatTable:
**
{
"id"
:
id
,
"user_id"
:
user_id
,
"title"
:
form_data
.
chat
[
"title"
],
"chat"
:
json
.
dump
(
form_data
.
chat
),
"title"
:
form_data
.
chat
[
"title"
]
if
"title"
in
form_data
.
chat
else
"New Chat"
,
"chat"
:
json
.
dumps
(
form_data
.
chat
),
"timestamp"
:
int
(
time
.
time
()),
}
)
...
...
@@ -75,7 +77,7 @@ class ChatTable:
def
update_chat_by_id
(
self
,
id
:
str
,
chat
:
dict
)
->
Optional
[
ChatModel
]:
try
:
query
=
Chat
.
update
(
chat
=
json
.
dump
(
chat
)).
where
(
Chat
.
id
==
id
)
query
=
Chat
.
update
(
chat
=
json
.
dump
s
(
chat
)).
where
(
Chat
.
id
==
id
)
query
.
execute
()
chat
=
Chat
.
get
(
Chat
.
id
==
id
)
...
...
@@ -88,7 +90,7 @@ class ChatTable:
)
->
List
[
ChatModel
]:
return
[
ChatModel
(
**
model_to_dict
(
chat
))
for
chat
in
Chat
.
select
(
Chat
.
id
,
Chat
.
title
)
for
chat
in
Chat
.
select
()
.
where
(
Chat
.
user_id
==
user_id
)
.
limit
(
limit
)
.
offset
(
skip
)
...
...
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