Merge branch 'refs/heads/main' into custom-openid-claims

# Conflicts:
#	backend/main.py
This commit is contained in:
Sergey Mihaylin
2024-07-01 10:08:38 +03:00
17 changed files with 1014 additions and 277 deletions

View File

@@ -153,7 +153,7 @@ async def cleanup_response(
await session.close()
async def post_streaming_url(url: str, payload: str):
async def post_streaming_url(url: str, payload: str, stream: bool = True):
r = None
try:
session = aiohttp.ClientSession(
@@ -162,12 +162,20 @@ async def post_streaming_url(url: str, payload: str):
r = await session.post(url, data=payload)
r.raise_for_status()
return StreamingResponse(
r.content,
status_code=r.status,
headers=dict(r.headers),
background=BackgroundTask(cleanup_response, response=r, session=session),
)
if stream:
return StreamingResponse(
r.content,
status_code=r.status,
headers=dict(r.headers),
background=BackgroundTask(
cleanup_response, response=r, session=session
),
)
else:
res = await r.json()
await cleanup_response(r, session)
return res
except Exception as e:
error_detail = "Open WebUI: Server Connection Error"
if r is not None:
@@ -963,7 +971,11 @@ async def generate_openai_chat_completion(
url = app.state.config.OLLAMA_BASE_URLS[url_idx]
log.info(f"url: {url}")
return await post_streaming_url(f"{url}/v1/chat/completions", json.dumps(payload))
return await post_streaming_url(
f"{url}/v1/chat/completions",
json.dumps(payload),
stream=payload.get("stream", False),
)
@app.get("/v1/models")

View File

@@ -686,6 +686,13 @@ ENABLE_SIGNUP = PersistentConfig(
else os.environ.get("ENABLE_SIGNUP", "True").lower() == "true"
),
)
DEFAULT_LOCALE = PersistentConfig(
"DEFAULT_LOCALE",
"ui.default_locale",
os.environ.get("DEFAULT_LOCALE", ""),
)
DEFAULT_MODELS = PersistentConfig(
"DEFAULT_MODELS", "ui.default_models", os.environ.get("DEFAULT_MODELS", None)
)

View File

@@ -101,6 +101,7 @@ from config import (
UPLOAD_DIR,
CACHE_DIR,
STATIC_DIR,
DEFAULT_LOCALE,
ENABLE_OPENAI_API,
ENABLE_OLLAMA_API,
ENABLE_MODEL_FILTER,
@@ -617,6 +618,8 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
return StreamingResponse(
self.ollama_stream_wrapper(response.body_iterator, data_items),
)
return response
else:
return response
@@ -1720,18 +1723,11 @@ async def update_pipeline_valves(
@app.get("/api/config")
async def get_app_config():
# Checking and Handling the Absence of 'ui' in CONFIG_DATA
default_locale = "en-US"
if "ui" in CONFIG_DATA:
default_locale = CONFIG_DATA["ui"].get("default_locale", "en-US")
# The Rest of the Function Now Uses the Variables Defined Above
return {
"status": True,
"name": WEBUI_NAME,
"version": VERSION,
"default_locale": default_locale,
"default_locale": str(DEFAULT_LOCALE),
"default_models": webui_app.state.config.DEFAULT_MODELS,
"default_prompt_suggestions": webui_app.state.config.DEFAULT_PROMPT_SUGGESTIONS,
"features": {
@@ -1924,8 +1920,7 @@ async def oauth_callback(provider: str, request: Request, response: Response):
if existing_user:
raise HTTPException(400, detail=ERROR_MESSAGES.EMAIL_TAKEN)
picture_claim = webui_app.state.config.OAUTH_PICTURE_CLAIM
picture_url = user_data.get(picture_claim, "")
picture_url = user_data.get("picture", "")
if picture_url:
# Download the profile image into a base64 string
try:
@@ -1946,6 +1941,11 @@ async def oauth_callback(provider: str, request: Request, response: Response):
if not picture_url:
picture_url = "/user.png"
username_claim = webui_app.state.config.OAUTH_USERNAME_CLAIM
role = (
"admin"
if Users.get_num_users() == 0
else webui_app.state.config.DEFAULT_USER_ROLE
)
user = Auths.insert_new_auth(
email=email,
password=get_password_hash(
@@ -1953,7 +1953,7 @@ async def oauth_callback(provider: str, request: Request, response: Response):
), # Random password, not used
name=user_data.get(username_claim, "User"),
profile_image_url=picture_url,
role=webui_app.state.config.DEFAULT_USER_ROLE,
role=role,
oauth_sub=provider_sub,
)
@@ -1980,7 +1980,7 @@ async def oauth_callback(provider: str, request: Request, response: Response):
# Set the cookie token
response.set_cookie(
key="token",
value=token,
value=jwt_token,
httponly=True, # Ensures the cookie is not accessible via JavaScript
)

View File

@@ -6,7 +6,7 @@ python-multipart==0.0.9
Flask==3.0.3
Flask-Cors==4.0.1
python-socketio==5.11.2
python-socketio==5.11.3
python-jose==3.3.0
passlib[bcrypt]==1.7.4
@@ -32,10 +32,10 @@ google-generativeai==0.5.4
langchain==0.2.0
langchain-community==0.2.0
langchain-chroma==0.1.1
langchain-chroma==0.1.2
fake-useragent==1.5.1
chromadb==0.5.0
chromadb==0.5.3
sentence-transformers==2.7.0
pypdf==4.2.0
docx2txt==0.8
@@ -58,7 +58,7 @@ rank-bm25==0.2.2
faster-whisper==1.0.2
PyJWT[crypto]==2.8.0
authlib==1.3.0
authlib==1.3.1
black==24.4.2
langfuse==2.33.0
@@ -67,4 +67,4 @@ pytube==15.0.0
extract_msg
pydub
duckduckgo-search~=6.1.5
duckduckgo-search~=6.1.7