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
aba63088
Commit
aba63088
authored
May 26, 2024
by
Jun Siang Cheah
Browse files
Merge remote-tracking branch 'upstream/dev' into feat/include-git-hash-everywhere
parents
4fdb26fd
7b81271b
Changes
132
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
415 additions
and
92 deletions
+415
-92
backend/apps/webui/main.py
backend/apps/webui/main.py
+6
-4
backend/apps/webui/models/auths.py
backend/apps/webui/models/auths.py
+2
-2
backend/apps/webui/models/chats.py
backend/apps/webui/models/chats.py
+39
-11
backend/apps/webui/models/documents.py
backend/apps/webui/models/documents.py
+1
-1
backend/apps/webui/models/memories.py
backend/apps/webui/models/memories.py
+2
-2
backend/apps/webui/models/models.py
backend/apps/webui/models/models.py
+179
-0
backend/apps/webui/models/prompts.py
backend/apps/webui/models/prompts.py
+1
-1
backend/apps/webui/models/tags.py
backend/apps/webui/models/tags.py
+1
-1
backend/apps/webui/models/users.py
backend/apps/webui/models/users.py
+2
-2
backend/apps/webui/routers/auths.py
backend/apps/webui/routers/auths.py
+2
-2
backend/apps/webui/routers/chats.py
backend/apps/webui/routers/chats.py
+52
-40
backend/apps/webui/routers/configs.py
backend/apps/webui/routers/configs.py
+1
-1
backend/apps/webui/routers/documents.py
backend/apps/webui/routers/documents.py
+1
-1
backend/apps/webui/routers/memories.py
backend/apps/webui/routers/memories.py
+1
-1
backend/apps/webui/routers/models.py
backend/apps/webui/routers/models.py
+108
-0
backend/apps/webui/routers/prompts.py
backend/apps/webui/routers/prompts.py
+1
-1
backend/apps/webui/routers/users.py
backend/apps/webui/routers/users.py
+3
-3
backend/apps/webui/routers/utils.py
backend/apps/webui/routers/utils.py
+1
-1
backend/config.py
backend/config.py
+10
-18
backend/constants.py
backend/constants.py
+2
-0
No files found.
backend/apps/web/main.py
→
backend/apps/web
ui
/main.py
View file @
aba63088
from
fastapi
import
FastAPI
,
Depends
from
fastapi.routing
import
APIRoute
from
fastapi.middleware.cors
import
CORSMiddleware
from
apps.web.routers
import
(
from
apps.web
ui
.routers
import
(
auths
,
users
,
chats
,
documents
,
model
file
s
,
models
,
prompts
,
configs
,
memories
,
...
...
@@ -40,6 +40,9 @@ app.state.config.DEFAULT_PROMPT_SUGGESTIONS = DEFAULT_PROMPT_SUGGESTIONS
app
.
state
.
config
.
DEFAULT_USER_ROLE
=
DEFAULT_USER_ROLE
app
.
state
.
config
.
USER_PERMISSIONS
=
USER_PERMISSIONS
app
.
state
.
config
.
WEBHOOK_URL
=
WEBHOOK_URL
app
.
state
.
MODELS
=
{}
app
.
state
.
AUTH_TRUSTED_EMAIL_HEADER
=
WEBUI_AUTH_TRUSTED_EMAIL_HEADER
...
...
@@ -56,11 +59,10 @@ app.include_router(users.router, prefix="/users", tags=["users"])
app
.
include_router
(
chats
.
router
,
prefix
=
"/chats"
,
tags
=
[
"chats"
])
app
.
include_router
(
documents
.
router
,
prefix
=
"/documents"
,
tags
=
[
"documents"
])
app
.
include_router
(
model
file
s
.
router
,
prefix
=
"/model
file
s"
,
tags
=
[
"model
file
s"
])
app
.
include_router
(
models
.
router
,
prefix
=
"/models"
,
tags
=
[
"models"
])
app
.
include_router
(
prompts
.
router
,
prefix
=
"/prompts"
,
tags
=
[
"prompts"
])
app
.
include_router
(
memories
.
router
,
prefix
=
"/memories"
,
tags
=
[
"memories"
])
app
.
include_router
(
configs
.
router
,
prefix
=
"/configs"
,
tags
=
[
"configs"
])
app
.
include_router
(
utils
.
router
,
prefix
=
"/utils"
,
tags
=
[
"utils"
])
...
...
backend/apps/web/models/auths.py
→
backend/apps/web
ui
/models/auths.py
View file @
aba63088
...
...
@@ -5,10 +5,10 @@ import uuid
import
logging
from
peewee
import
*
from
apps.web.models.users
import
UserModel
,
Users
from
apps.web
ui
.models.users
import
UserModel
,
Users
from
utils.utils
import
verify_password
from
apps.web.internal.db
import
DB
from
apps.web
ui
.internal.db
import
DB
from
config
import
SRC_LOG_LEVELS
...
...
backend/apps/web/models/chats.py
→
backend/apps/web
ui
/models/chats.py
View file @
aba63088
...
...
@@ -7,7 +7,7 @@ import json
import
uuid
import
time
from
apps.web.internal.db
import
DB
from
apps.web
ui
.internal.db
import
DB
####################
# Chat DB Schema
...
...
@@ -191,6 +191,20 @@ class ChatTable:
except
:
return
None
def
archive_all_chats_by_user_id
(
self
,
user_id
:
str
)
->
bool
:
try
:
chats
=
self
.
get_chats_by_user_id
(
user_id
)
for
chat
in
chats
:
query
=
Chat
.
update
(
archived
=
True
,
).
where
(
Chat
.
id
==
chat
.
id
)
query
.
execute
()
return
True
except
:
return
False
def
get_archived_chat_list_by_user_id
(
self
,
user_id
:
str
,
skip
:
int
=
0
,
limit
:
int
=
50
)
->
List
[
ChatModel
]:
...
...
@@ -205,17 +219,31 @@ class ChatTable:
]
def
get_chat_list_by_user_id
(
self
,
user_id
:
str
,
skip
:
int
=
0
,
limit
:
int
=
50
self
,
user_id
:
str
,
include_archived
:
bool
=
False
,
skip
:
int
=
0
,
limit
:
int
=
50
,
)
->
List
[
ChatModel
]:
return
[
ChatModel
(
**
model_to_dict
(
chat
))
for
chat
in
Chat
.
select
()
.
where
(
Chat
.
archived
==
False
)
.
where
(
Chat
.
user_id
==
user_id
)
.
order_by
(
Chat
.
updated_at
.
desc
())
# .limit(limit)
# .offset(skip)
]
if
include_archived
:
return
[
ChatModel
(
**
model_to_dict
(
chat
))
for
chat
in
Chat
.
select
()
.
where
(
Chat
.
user_id
==
user_id
)
.
order_by
(
Chat
.
updated_at
.
desc
())
# .limit(limit)
# .offset(skip)
]
else
:
return
[
ChatModel
(
**
model_to_dict
(
chat
))
for
chat
in
Chat
.
select
()
.
where
(
Chat
.
archived
==
False
)
.
where
(
Chat
.
user_id
==
user_id
)
.
order_by
(
Chat
.
updated_at
.
desc
())
# .limit(limit)
# .offset(skip)
]
def
get_chat_list_by_chat_ids
(
self
,
chat_ids
:
List
[
str
],
skip
:
int
=
0
,
limit
:
int
=
50
...
...
backend/apps/web/models/documents.py
→
backend/apps/web
ui
/models/documents.py
View file @
aba63088
...
...
@@ -8,7 +8,7 @@ import logging
from
utils.utils
import
decode_token
from
utils.misc
import
get_gravatar_url
from
apps.web.internal.db
import
DB
from
apps.web
ui
.internal.db
import
DB
import
json
...
...
backend/apps/web/models/memories.py
→
backend/apps/web
ui
/models/memories.py
View file @
aba63088
...
...
@@ -3,8 +3,8 @@ from peewee import *
from
playhouse.shortcuts
import
model_to_dict
from
typing
import
List
,
Union
,
Optional
from
apps.web.internal.db
import
DB
from
apps.web.models.chats
import
Chats
from
apps.web
ui
.internal.db
import
DB
from
apps.web
ui
.models.chats
import
Chats
import
time
import
uuid
...
...
backend/apps/webui/models/models.py
0 → 100644
View file @
aba63088
import
json
import
logging
from
typing
import
Optional
import
peewee
as
pw
from
peewee
import
*
from
playhouse.shortcuts
import
model_to_dict
from
pydantic
import
BaseModel
,
ConfigDict
from
apps.webui.internal.db
import
DB
,
JSONField
from
typing
import
List
,
Union
,
Optional
from
config
import
SRC_LOG_LEVELS
import
time
log
=
logging
.
getLogger
(
__name__
)
log
.
setLevel
(
SRC_LOG_LEVELS
[
"MODELS"
])
####################
# Models DB Schema
####################
# ModelParams is a model for the data stored in the params field of the Model table
class
ModelParams
(
BaseModel
):
model_config
=
ConfigDict
(
extra
=
"allow"
)
pass
# ModelMeta is a model for the data stored in the meta field of the Model table
class
ModelMeta
(
BaseModel
):
profile_image_url
:
Optional
[
str
]
=
"/favicon.png"
description
:
Optional
[
str
]
=
None
"""
User-facing description of the model.
"""
capabilities
:
Optional
[
dict
]
=
None
model_config
=
ConfigDict
(
extra
=
"allow"
)
pass
class
Model
(
pw
.
Model
):
id
=
pw
.
TextField
(
unique
=
True
)
"""
The model's id as used in the API. If set to an existing model, it will override the model.
"""
user_id
=
pw
.
TextField
()
base_model_id
=
pw
.
TextField
(
null
=
True
)
"""
An optional pointer to the actual model that should be used when proxying requests.
"""
name
=
pw
.
TextField
()
"""
The human-readable display name of the model.
"""
params
=
JSONField
()
"""
Holds a JSON encoded blob of parameters, see `ModelParams`.
"""
meta
=
JSONField
()
"""
Holds a JSON encoded blob of metadata, see `ModelMeta`.
"""
updated_at
=
BigIntegerField
()
created_at
=
BigIntegerField
()
class
Meta
:
database
=
DB
class
ModelModel
(
BaseModel
):
id
:
str
user_id
:
str
base_model_id
:
Optional
[
str
]
=
None
name
:
str
params
:
ModelParams
meta
:
ModelMeta
updated_at
:
int
# timestamp in epoch
created_at
:
int
# timestamp in epoch
####################
# Forms
####################
class
ModelResponse
(
BaseModel
):
id
:
str
name
:
str
meta
:
ModelMeta
updated_at
:
int
# timestamp in epoch
created_at
:
int
# timestamp in epoch
class
ModelForm
(
BaseModel
):
id
:
str
base_model_id
:
Optional
[
str
]
=
None
name
:
str
meta
:
ModelMeta
params
:
ModelParams
class
ModelsTable
:
def
__init__
(
self
,
db
:
pw
.
SqliteDatabase
|
pw
.
PostgresqlDatabase
,
):
self
.
db
=
db
self
.
db
.
create_tables
([
Model
])
def
insert_new_model
(
self
,
form_data
:
ModelForm
,
user_id
:
str
)
->
Optional
[
ModelModel
]:
model
=
ModelModel
(
**
{
**
form_data
.
model_dump
(),
"user_id"
:
user_id
,
"created_at"
:
int
(
time
.
time
()),
"updated_at"
:
int
(
time
.
time
()),
}
)
try
:
result
=
Model
.
create
(
**
model
.
model_dump
())
if
result
:
return
model
else
:
return
None
except
Exception
as
e
:
print
(
e
)
return
None
def
get_all_models
(
self
)
->
List
[
ModelModel
]:
return
[
ModelModel
(
**
model_to_dict
(
model
))
for
model
in
Model
.
select
()]
def
get_model_by_id
(
self
,
id
:
str
)
->
Optional
[
ModelModel
]:
try
:
model
=
Model
.
get
(
Model
.
id
==
id
)
return
ModelModel
(
**
model_to_dict
(
model
))
except
:
return
None
def
update_model_by_id
(
self
,
id
:
str
,
model
:
ModelForm
)
->
Optional
[
ModelModel
]:
try
:
# update only the fields that are present in the model
query
=
Model
.
update
(
**
model
.
model_dump
()).
where
(
Model
.
id
==
id
)
query
.
execute
()
model
=
Model
.
get
(
Model
.
id
==
id
)
return
ModelModel
(
**
model_to_dict
(
model
))
except
Exception
as
e
:
print
(
e
)
return
None
def
delete_model_by_id
(
self
,
id
:
str
)
->
bool
:
try
:
query
=
Model
.
delete
().
where
(
Model
.
id
==
id
)
query
.
execute
()
return
True
except
:
return
False
Models
=
ModelsTable
(
DB
)
backend/apps/web/models/prompts.py
→
backend/apps/web
ui
/models/prompts.py
View file @
aba63088
...
...
@@ -7,7 +7,7 @@ import time
from
utils.utils
import
decode_token
from
utils.misc
import
get_gravatar_url
from
apps.web.internal.db
import
DB
from
apps.web
ui
.internal.db
import
DB
import
json
...
...
backend/apps/web/models/tags.py
→
backend/apps/web
ui
/models/tags.py
View file @
aba63088
...
...
@@ -8,7 +8,7 @@ import uuid
import
time
import
logging
from
apps.web.internal.db
import
DB
from
apps.web
ui
.internal.db
import
DB
from
config
import
SRC_LOG_LEVELS
...
...
backend/apps/web/models/users.py
→
backend/apps/web
ui
/models/users.py
View file @
aba63088
...
...
@@ -5,8 +5,8 @@ from typing import List, Union, Optional
import
time
from
utils.misc
import
get_gravatar_url
from
apps.web.internal.db
import
DB
from
apps.web.models.chats
import
Chats
from
apps.web
ui
.internal.db
import
DB
from
apps.web
ui
.models.chats
import
Chats
####################
# User DB Schema
...
...
backend/apps/web/routers/auths.py
→
backend/apps/web
ui
/routers/auths.py
View file @
aba63088
...
...
@@ -10,7 +10,7 @@ import uuid
import
csv
from
apps.web.models.auths
import
(
from
apps.web
ui
.models.auths
import
(
SigninForm
,
SignupForm
,
AddUserForm
,
...
...
@@ -21,7 +21,7 @@ from apps.web.models.auths import (
Auths
,
ApiKey
,
)
from
apps.web.models.users
import
Users
from
apps.web
ui
.models.users
import
Users
from
utils.utils
import
(
get_password_hash
,
...
...
backend/apps/web/routers/chats.py
→
backend/apps/web
ui
/routers/chats.py
View file @
aba63088
...
...
@@ -7,8 +7,8 @@ from pydantic import BaseModel
import
json
import
logging
from
apps.web.models.users
import
Users
from
apps.web.models.chats
import
(
from
apps.web
ui
.models.users
import
Users
from
apps.web
ui
.models.chats
import
(
ChatModel
,
ChatResponse
,
ChatTitleForm
,
...
...
@@ -18,7 +18,7 @@ from apps.web.models.chats import (
)
from
apps.web.models.tags
import
(
from
apps.web
ui
.models.tags
import
(
TagModel
,
ChatIdTagModel
,
ChatIdTagForm
,
...
...
@@ -78,43 +78,25 @@ async def delete_all_user_chats(request: Request, user=Depends(get_current_user)
async
def
get_user_chat_list_by_user_id
(
user_id
:
str
,
user
=
Depends
(
get_admin_user
),
skip
:
int
=
0
,
limit
:
int
=
50
):
return
Chats
.
get_chat_list_by_user_id
(
user_id
,
skip
,
limit
)
############################
# GetArchivedChats
############################
@
router
.
get
(
"/archived"
,
response_model
=
List
[
ChatTitleIdResponse
])
async
def
get_archived_session_user_chat_list
(
user
=
Depends
(
get_current_user
),
skip
:
int
=
0
,
limit
:
int
=
50
):
return
Chats
.
get_archived_chat_list_by_user_id
(
user
.
id
,
skip
,
limit
)
return
Chats
.
get_chat_list_by_user_id
(
user_id
,
include_archived
=
True
,
skip
=
skip
,
limit
=
limit
)
############################
#
GetSharedChatById
#
CreateNewChat
############################
@
router
.
get
(
"/share/{share_id}"
,
response_model
=
Optional
[
ChatResponse
])
async
def
get_shared_chat_by_id
(
share_id
:
str
,
user
=
Depends
(
get_current_user
)):
if
user
.
role
==
"pending"
:
raise
HTTPException
(
status_code
=
status
.
HTTP_401_UNAUTHORIZED
,
detail
=
ERROR_MESSAGES
.
NOT_FOUND
)
if
user
.
role
==
"user"
:
chat
=
Chats
.
get_chat_by_share_id
(
share_id
)
elif
user
.
role
==
"admin"
:
chat
=
Chats
.
get_chat_by_id
(
share_id
)
if
chat
:
@
router
.
post
(
"/new"
,
response_model
=
Optional
[
ChatResponse
])
async
def
create_new_chat
(
form_data
:
ChatForm
,
user
=
Depends
(
get_current_user
)):
try
:
chat
=
Chats
.
insert_new_chat
(
user
.
id
,
form_data
)
return
ChatResponse
(
**
{
**
chat
.
model_dump
(),
"chat"
:
json
.
loads
(
chat
.
chat
)})
else
:
except
Exception
as
e
:
log
.
exception
(
e
)
raise
HTTPException
(
status_code
=
status
.
HTTP_40
1_UNAUTHORIZED
,
detail
=
ERROR_MESSAGES
.
NOT_FOUND
status_code
=
status
.
HTTP_40
0_BAD_REQUEST
,
detail
=
ERROR_MESSAGES
.
DEFAULT
()
)
...
...
@@ -150,19 +132,49 @@ async def get_all_user_chats_in_db(user=Depends(get_admin_user)):
############################
#
CreateNew
Chat
#
GetArchived
Chat
s
############################
@
router
.
post
(
"/new"
,
response_model
=
Optional
[
ChatResponse
])
async
def
create_new_chat
(
form_data
:
ChatForm
,
user
=
Depends
(
get_current_user
)):
try
:
chat
=
Chats
.
insert_new_chat
(
user
.
id
,
form_data
)
@
router
.
get
(
"/archived"
,
response_model
=
List
[
ChatTitleIdResponse
])
async
def
get_archived_session_user_chat_list
(
user
=
Depends
(
get_current_user
),
skip
:
int
=
0
,
limit
:
int
=
50
):
return
Chats
.
get_archived_chat_list_by_user_id
(
user
.
id
,
skip
,
limit
)
############################
# ArchiveAllChats
############################
@
router
.
post
(
"/archive/all"
,
response_model
=
List
[
ChatTitleIdResponse
])
async
def
archive_all_chats
(
user
=
Depends
(
get_current_user
)):
return
Chats
.
archive_all_chats_by_user_id
(
user
.
id
)
############################
# GetSharedChatById
############################
@
router
.
get
(
"/share/{share_id}"
,
response_model
=
Optional
[
ChatResponse
])
async
def
get_shared_chat_by_id
(
share_id
:
str
,
user
=
Depends
(
get_current_user
)):
if
user
.
role
==
"pending"
:
raise
HTTPException
(
status_code
=
status
.
HTTP_401_UNAUTHORIZED
,
detail
=
ERROR_MESSAGES
.
NOT_FOUND
)
if
user
.
role
==
"user"
:
chat
=
Chats
.
get_chat_by_share_id
(
share_id
)
elif
user
.
role
==
"admin"
:
chat
=
Chats
.
get_chat_by_id
(
share_id
)
if
chat
:
return
ChatResponse
(
**
{
**
chat
.
model_dump
(),
"chat"
:
json
.
loads
(
chat
.
chat
)})
except
Exception
as
e
:
log
.
exception
(
e
)
else
:
raise
HTTPException
(
status_code
=
status
.
HTTP_40
0_BAD_REQUEST
,
detail
=
ERROR_MESSAGES
.
DEFAULT
()
status_code
=
status
.
HTTP_40
1_UNAUTHORIZED
,
detail
=
ERROR_MESSAGES
.
NOT_FOUND
)
...
...
backend/apps/web/routers/configs.py
→
backend/apps/web
ui
/routers/configs.py
View file @
aba63088
...
...
@@ -8,7 +8,7 @@ from pydantic import BaseModel
import
time
import
uuid
from
apps.web.models.users
import
Users
from
apps.web
ui
.models.users
import
Users
from
utils.utils
import
(
get_password_hash
,
...
...
backend/apps/web/routers/documents.py
→
backend/apps/web
ui
/routers/documents.py
View file @
aba63088
...
...
@@ -6,7 +6,7 @@ from fastapi import APIRouter
from
pydantic
import
BaseModel
import
json
from
apps.web.models.documents
import
(
from
apps.web
ui
.models.documents
import
(
Documents
,
DocumentForm
,
DocumentUpdateForm
,
...
...
backend/apps/web/routers/memories.py
→
backend/apps/web
ui
/routers/memories.py
View file @
aba63088
...
...
@@ -7,7 +7,7 @@ from fastapi import APIRouter
from
pydantic
import
BaseModel
import
logging
from
apps.web.models.memories
import
Memories
,
MemoryModel
from
apps.web
ui
.models.memories
import
Memories
,
MemoryModel
from
utils.utils
import
get_verified_user
from
constants
import
ERROR_MESSAGES
...
...
backend/apps/webui/routers/models.py
0 → 100644
View file @
aba63088
from
fastapi
import
Depends
,
FastAPI
,
HTTPException
,
status
,
Request
from
datetime
import
datetime
,
timedelta
from
typing
import
List
,
Union
,
Optional
from
fastapi
import
APIRouter
from
pydantic
import
BaseModel
import
json
from
apps.webui.models.models
import
Models
,
ModelModel
,
ModelForm
,
ModelResponse
from
utils.utils
import
get_verified_user
,
get_admin_user
from
constants
import
ERROR_MESSAGES
router
=
APIRouter
()
###########################
# getModels
###########################
@
router
.
get
(
"/"
,
response_model
=
List
[
ModelResponse
])
async
def
get_models
(
user
=
Depends
(
get_verified_user
)):
return
Models
.
get_all_models
()
############################
# AddNewModel
############################
@
router
.
post
(
"/add"
,
response_model
=
Optional
[
ModelModel
])
async
def
add_new_model
(
request
:
Request
,
form_data
:
ModelForm
,
user
=
Depends
(
get_admin_user
)
):
if
form_data
.
id
in
request
.
app
.
state
.
MODELS
:
raise
HTTPException
(
status_code
=
status
.
HTTP_401_UNAUTHORIZED
,
detail
=
ERROR_MESSAGES
.
MODEL_ID_TAKEN
,
)
else
:
model
=
Models
.
insert_new_model
(
form_data
,
user
.
id
)
if
model
:
return
model
else
:
raise
HTTPException
(
status_code
=
status
.
HTTP_401_UNAUTHORIZED
,
detail
=
ERROR_MESSAGES
.
DEFAULT
(),
)
############################
# GetModelById
############################
@
router
.
get
(
"/"
,
response_model
=
Optional
[
ModelModel
])
async
def
get_model_by_id
(
id
:
str
,
user
=
Depends
(
get_verified_user
)):
model
=
Models
.
get_model_by_id
(
id
)
if
model
:
return
model
else
:
raise
HTTPException
(
status_code
=
status
.
HTTP_401_UNAUTHORIZED
,
detail
=
ERROR_MESSAGES
.
NOT_FOUND
,
)
############################
# UpdateModelById
############################
@
router
.
post
(
"/update"
,
response_model
=
Optional
[
ModelModel
])
async
def
update_model_by_id
(
request
:
Request
,
id
:
str
,
form_data
:
ModelForm
,
user
=
Depends
(
get_admin_user
)
):
model
=
Models
.
get_model_by_id
(
id
)
if
model
:
model
=
Models
.
update_model_by_id
(
id
,
form_data
)
return
model
else
:
if
form_data
.
id
in
request
.
app
.
state
.
MODELS
:
model
=
Models
.
insert_new_model
(
form_data
,
user
.
id
)
print
(
model
)
if
model
:
return
model
else
:
raise
HTTPException
(
status_code
=
status
.
HTTP_401_UNAUTHORIZED
,
detail
=
ERROR_MESSAGES
.
DEFAULT
(),
)
else
:
raise
HTTPException
(
status_code
=
status
.
HTTP_401_UNAUTHORIZED
,
detail
=
ERROR_MESSAGES
.
DEFAULT
(),
)
############################
# DeleteModelById
############################
@
router
.
delete
(
"/delete"
,
response_model
=
bool
)
async
def
delete_model_by_id
(
id
:
str
,
user
=
Depends
(
get_admin_user
)):
result
=
Models
.
delete_model_by_id
(
id
)
return
result
backend/apps/web/routers/prompts.py
→
backend/apps/web
ui
/routers/prompts.py
View file @
aba63088
...
...
@@ -6,7 +6,7 @@ from fastapi import APIRouter
from
pydantic
import
BaseModel
import
json
from
apps.web.models.prompts
import
Prompts
,
PromptForm
,
PromptModel
from
apps.web
ui
.models.prompts
import
Prompts
,
PromptForm
,
PromptModel
from
utils.utils
import
get_current_user
,
get_admin_user
from
constants
import
ERROR_MESSAGES
...
...
backend/apps/web/routers/users.py
→
backend/apps/web
ui
/routers/users.py
View file @
aba63088
...
...
@@ -9,9 +9,9 @@ import time
import
uuid
import
logging
from
apps.web.models.users
import
UserModel
,
UserUpdateForm
,
UserRoleUpdateForm
,
Users
from
apps.web.models.auths
import
Auths
from
apps.web.models.chats
import
Chats
from
apps.web
ui
.models.users
import
UserModel
,
UserUpdateForm
,
UserRoleUpdateForm
,
Users
from
apps.web
ui
.models.auths
import
Auths
from
apps.web
ui
.models.chats
import
Chats
from
utils.utils
import
get_verified_user
,
get_password_hash
,
get_admin_user
from
constants
import
ERROR_MESSAGES
...
...
backend/apps/web/routers/utils.py
→
backend/apps/web
ui
/routers/utils.py
View file @
aba63088
...
...
@@ -8,7 +8,7 @@ from pydantic import BaseModel
from
fpdf
import
FPDF
import
markdown
from
apps.web.internal.db
import
DB
from
apps.web
ui
.internal.db
import
DB
from
utils.utils
import
get_admin_user
from
utils.misc
import
calculate_sha256
,
get_gravatar_url
...
...
backend/config.py
View file @
aba63088
...
...
@@ -27,6 +27,8 @@ from constants import ERROR_MESSAGES
BACKEND_DIR
=
Path
(
__file__
).
parent
# the path containing this file
BASE_DIR
=
BACKEND_DIR
.
parent
# the path containing the backend/
print
(
BASE_DIR
)
try
:
from
dotenv
import
load_dotenv
,
find_dotenv
...
...
@@ -56,7 +58,6 @@ log_sources = [
"CONFIG"
,
"DB"
,
"IMAGES"
,
"LITELLM"
,
"MAIN"
,
"MODELS"
,
"OLLAMA"
,
...
...
@@ -122,7 +123,10 @@ def parse_section(section):
try
:
changelog_content
=
(
BASE_DIR
/
"CHANGELOG.md"
).
read_text
()
changelog_path
=
BASE_DIR
/
"CHANGELOG.md"
with
open
(
str
(
changelog_path
.
absolute
()),
"r"
,
encoding
=
"utf8"
)
as
file
:
changelog_content
=
file
.
read
()
except
:
changelog_content
=
(
pkgutil
.
get_data
(
"open_webui"
,
"CHANGELOG.md"
)
or
b
""
).
decode
()
...
...
@@ -374,10 +378,10 @@ def create_config_file(file_path):
LITELLM_CONFIG_PATH
=
f
"
{
DATA_DIR
}
/litellm/config.yaml"
if
not
os
.
path
.
exists
(
LITELLM_CONFIG_PATH
):
log
.
info
(
"Config file doesn't exist. Creating..."
)
create_config_file
(
LITELLM_CONFIG_PATH
)
log
.
info
(
"Config file created successfully."
)
#
if not os.path.exists(LITELLM_CONFIG_PATH):
#
log.info("Config file doesn't exist. Creating...")
#
create_config_file(LITELLM_CONFIG_PATH)
#
log.info("Config file created successfully.")
####################################
...
...
@@ -826,18 +830,6 @@ AUDIO_OPENAI_API_VOICE = PersistentConfig(
os
.
getenv
(
"AUDIO_OPENAI_API_VOICE"
,
"alloy"
),
)
####################################
# LiteLLM
####################################
ENABLE_LITELLM
=
os
.
environ
.
get
(
"ENABLE_LITELLM"
,
"True"
).
lower
()
==
"true"
LITELLM_PROXY_PORT
=
int
(
os
.
getenv
(
"LITELLM_PROXY_PORT"
,
"14365"
))
if
LITELLM_PROXY_PORT
<
0
or
LITELLM_PROXY_PORT
>
65535
:
raise
ValueError
(
"Invalid port number for LITELLM_PROXY_PORT"
)
LITELLM_PROXY_HOST
=
os
.
getenv
(
"LITELLM_PROXY_HOST"
,
"127.0.0.1"
)
####################################
# Database
...
...
backend/constants.py
View file @
aba63088
...
...
@@ -32,6 +32,8 @@ class ERROR_MESSAGES(str, Enum):
COMMAND_TAKEN
=
"Uh-oh! This command is already registered. Please choose another command string."
FILE_EXISTS
=
"Uh-oh! This file is already registered. Please choose another file."
MODEL_ID_TAKEN
=
"Uh-oh! This model id is already registered. Please choose another model id string."
NAME_TAG_TAKEN
=
"Uh-oh! This name tag is already registered. Please choose another name tag string."
INVALID_TOKEN
=
(
"Your session has expired or the token is invalid. Please sign in again."
...
...
Prev
1
2
3
4
5
6
7
Next
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