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
83ff1d77
"...git@developer.sourcefind.cn:chenpangpang/open-webui.git" did not exist on "79d0932a3ab12ccacf7e4c82c3fc658544364008"
Commit
83ff1d77
authored
Nov 19, 2023
by
Timothy J. Baek
Browse files
feat: set first user to admin by default
parent
07d2c987
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
28 additions
and
25 deletions
+28
-25
backend/apps/ollama/main.py
backend/apps/ollama/main.py
+2
-2
backend/apps/web/main.py
backend/apps/web/main.py
+2
-2
backend/apps/web/models/users.py
backend/apps/web/models/users.py
+3
-0
backend/apps/web/routers/auths.py
backend/apps/web/routers/auths.py
+2
-1
backend/config.py
backend/config.py
+13
-17
backend/utils/utils.py
backend/utils/utils.py
+1
-1
compose.yaml
compose.yaml
+2
-1
src/lib/constants.ts
src/lib/constants.ts
+3
-1
No files found.
backend/apps/ollama/main.py
View file @
83ff1d77
...
...
@@ -9,7 +9,7 @@ import json
from
apps.web.models.users
import
Users
from
constants
import
ERROR_MESSAGES
from
utils.utils
import
extract_token_from_auth_header
from
config
import
OLLAMA_API_BASE_URL
,
OLLAMA_
WEBUI_AUTH
from
config
import
OLLAMA_API_BASE_URL
,
WEBUI_AUTH
app
=
Flask
(
__name__
)
CORS
(
...
...
@@ -32,7 +32,7 @@ def proxy(path):
headers
=
dict
(
request
.
headers
)
# Basic RBAC support
if
OLLAMA_
WEBUI_AUTH
:
if
WEBUI_AUTH
:
if
"Authorization"
in
headers
:
token
=
extract_token_from_auth_header
(
headers
[
"Authorization"
])
user
=
Users
.
get_user_by_token
(
token
)
...
...
backend/apps/web/main.py
View file @
83ff1d77
...
...
@@ -2,7 +2,7 @@ from fastapi import FastAPI, Request, Depends, HTTPException
from
fastapi.middleware.cors
import
CORSMiddleware
from
apps.web.routers
import
auths
,
users
from
config
import
OLLAMA_
WEBUI_VERSION
,
OLLAMA_
WEBUI_AUTH
from
config
import
WEBUI_VERSION
,
WEBUI_AUTH
app
=
FastAPI
()
...
...
@@ -23,4 +23,4 @@ app.include_router(users.router, prefix="/users", tags=["users"])
@
app
.
get
(
"/"
)
async
def
get_status
():
return
{
"status"
:
True
,
"version"
:
OLLAMA_
WEBUI_VERSION
,
"auth"
:
OLLAMA_
WEBUI_AUTH
}
return
{
"status"
:
True
,
"version"
:
WEBUI_VERSION
,
"auth"
:
WEBUI_AUTH
}
backend/apps/web/models/users.py
View file @
83ff1d77
...
...
@@ -81,6 +81,9 @@ class UsersTable:
)
]
def
get_num_users
(
self
)
->
Optional
[
int
]:
return
self
.
table
.
count_documents
({})
def
update_user_by_id
(
self
,
id
:
str
,
updated
:
dict
)
->
Optional
[
UserModel
]:
user
=
self
.
table
.
find_one_and_update
(
{
"id"
:
id
},
{
"$set"
:
updated
},
return_document
=
ReturnDocument
.
AFTER
...
...
backend/apps/web/routers/auths.py
View file @
83ff1d77
...
...
@@ -86,8 +86,9 @@ async def signin(form_data: SigninForm):
async
def
signup
(
form_data
:
SignupForm
):
if
not
Users
.
get_user_by_email
(
form_data
.
email
.
lower
()):
try
:
role
=
"admin"
if
Users
.
get_num_users
()
==
0
else
"pending"
hashed
=
get_password_hash
(
form_data
.
password
)
user
=
Auths
.
insert_new_auth
(
form_data
.
email
,
hashed
,
form_data
.
name
)
user
=
Auths
.
insert_new_auth
(
form_data
.
email
,
hashed
,
form_data
.
name
,
role
)
if
user
:
token
=
create_token
(
data
=
{
"email"
:
user
.
email
})
...
...
backend/config.py
View file @
83ff1d77
...
...
@@ -26,40 +26,36 @@ if ENV == "prod":
OLLAMA_API_BASE_URL
=
"http://host.docker.internal:11434/api"
####################################
#
OLLAMA_
WEBUI_VERSION
# WEBUI_VERSION
####################################
OLLAMA_
WEBUI_VERSION
=
os
.
environ
.
get
(
"
OLLAMA_
WEBUI_VERSION"
,
"v1.0.0-alpha.9"
)
WEBUI_VERSION
=
os
.
environ
.
get
(
"WEBUI_VERSION"
,
"v1.0.0-alpha.9"
)
####################################
#
OLLAMA_
WEBUI_AUTH
# WEBUI_AUTH
####################################
OLLAMA_WEBUI_AUTH
=
(
True
if
os
.
environ
.
get
(
"OLLAMA_WEBUI_AUTH"
,
"TRUE"
)
==
"TRUE"
else
False
)
WEBUI_AUTH
=
True
if
os
.
environ
.
get
(
"WEBUI_AUTH"
,
"TRUE"
)
==
"TRUE"
else
False
if
OLLAMA_
WEBUI_AUTH
:
if
WEBUI_AUTH
:
####################################
#
OLLAMA_
WEBUI_DB
# WEBUI_DB
####################################
OLLAMA_
WEBUI_DB_URL
=
os
.
environ
.
get
(
"
OLLAMA_
WEBUI_DB_URL"
,
"mongodb://root:root@localhost:27017/"
WEBUI_DB_URL
=
os
.
environ
.
get
(
"WEBUI_DB_URL"
,
"mongodb://root:root@localhost:27017/"
)
DB_CLIENT
=
MongoClient
(
f
"
{
OLLAMA_
WEBUI_DB_URL
}
?authSource=admin"
)
DB_CLIENT
=
MongoClient
(
f
"
{
WEBUI_DB_URL
}
?authSource=admin"
)
DB
=
DB_CLIENT
[
"ollama-webui"
]
####################################
#
OLLAMA_
WEBUI_JWT_SECRET_KEY
# WEBUI_JWT_SECRET_KEY
####################################
OLLAMA_WEBUI_JWT_SECRET_KEY
=
os
.
environ
.
get
(
"OLLAMA_WEBUI_JWT_SECRET_KEY"
,
"t0p-s3cr3t"
)
WEBUI_JWT_SECRET_KEY
=
os
.
environ
.
get
(
"WEBUI_JWT_SECRET_KEY"
,
"t0p-s3cr3t"
)
if
ENV
==
"prod"
:
if
OLLAMA_
WEBUI_JWT_SECRET_KEY
==
""
:
OLLAMA_
WEBUI_JWT_SECRET_KEY
=
str
(
b64encode
(
token_bytes
(
32
)).
decode
())
if
WEBUI_JWT_SECRET_KEY
==
""
:
WEBUI_JWT_SECRET_KEY
=
str
(
b64encode
(
token_bytes
(
32
)).
decode
())
backend/utils/utils.py
View file @
83ff1d77
...
...
@@ -9,7 +9,7 @@ import jwt
import
config
JWT_SECRET_KEY
=
config
.
OLLAMA_
WEBUI_JWT_SECRET_KEY
JWT_SECRET_KEY
=
config
.
WEBUI_JWT_SECRET_KEY
ALGORITHM
=
"HS256"
##############
...
...
compose.yaml
View file @
83ff1d77
...
...
@@ -46,7 +46,8 @@ services:
-
3000:8080
environment
:
-
"
OLLAMA_API_BASE_URL=http://ollama:11434/api"
-
"
OLLAMA_WEBUI_DB_URL=mongodb://root:example@ollama-webui-db:27017/"
-
"
WEBUI_DB_URL=mongodb://root:example@ollama-webui-db:27017/"
-
"
WEBUI_AUTH=TRUE"
extra_hosts
:
-
host.docker.internal:host-gateway
restart
:
unless-stopped
...
...
src/lib/constants.ts
View file @
83ff1d77
...
...
@@ -3,8 +3,10 @@ import { PUBLIC_API_BASE_URL } from '$env/static/public';
export
const
OLLAMA_API_BASE_URL
=
PUBLIC_API_BASE_URL
===
''
?
browser
?
dev
?
`http://
${
location
.
hostname
}
:8080/ollama/api`
:
browser
?
`http://
${
location
.
hostname
}
:11434/api`
:
`http://localhost:11434/api`
:
PUBLIC_API_BASE_URL
;
...
...
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