Skip to content

Commit 54d7bf8

Browse files
authored
Merge branch 'dev' into improve-swedish-translation
2 parents df12382 + 3be5e31 commit 54d7bf8

File tree

123 files changed

+2751
-1236
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+2751
-1236
lines changed

backend/open_webui/config.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def filter(self, record: logging.LogRecord) -> bool:
4444

4545
# Function to run the alembic migrations
4646
def run_migrations():
47-
print("Running migrations")
47+
log.info("Running migrations")
4848
try:
4949
from alembic import command
5050
from alembic.config import Config
@@ -57,7 +57,7 @@ def run_migrations():
5757

5858
command.upgrade(alembic_cfg, "head")
5959
except Exception as e:
60-
print(f"Error: {e}")
60+
log.exception(f"Error running migrations: {e}")
6161

6262

6363
run_migrations()
@@ -678,6 +678,10 @@ def oidc_oauth_register(client):
678678
S3_BUCKET_NAME = os.environ.get("S3_BUCKET_NAME", None)
679679
S3_KEY_PREFIX = os.environ.get("S3_KEY_PREFIX", None)
680680
S3_ENDPOINT_URL = os.environ.get("S3_ENDPOINT_URL", None)
681+
S3_USE_ACCELERATE_ENDPOINT = (
682+
os.environ.get("S3_USE_ACCELERATE_ENDPOINT", "False").lower() == "true"
683+
)
684+
S3_ADDRESSING_STYLE = os.environ.get("S3_ADDRESSING_STYLE", None)
681685

682686
GCS_BUCKET_NAME = os.environ.get("GCS_BUCKET_NAME", None)
683687
GOOGLE_APPLICATION_CREDENTIALS_JSON = os.environ.get(
@@ -1094,7 +1098,7 @@ class BannerModel(BaseModel):
10941098
banners = json.loads(os.environ.get("WEBUI_BANNERS", "[]"))
10951099
banners = [BannerModel(**banner) for banner in banners]
10961100
except Exception as e:
1097-
print(f"Error loading WEBUI_BANNERS: {e}")
1101+
log.exception(f"Error loading WEBUI_BANNERS: {e}")
10981102
banners = []
10991103

11001104
WEBUI_BANNERS = PersistentConfig("WEBUI_BANNERS", "ui.banners", banners)
@@ -1566,6 +1570,18 @@ class BannerModel(BaseModel):
15661570
os.environ.get("GOOGLE_DRIVE_API_KEY", ""),
15671571
)
15681572

1573+
ENABLE_ONEDRIVE_INTEGRATION = PersistentConfig(
1574+
"ENABLE_ONEDRIVE_INTEGRATION",
1575+
"onedrive.enable",
1576+
os.getenv("ENABLE_ONEDRIVE_INTEGRATION", "False").lower() == "true",
1577+
)
1578+
1579+
ONEDRIVE_CLIENT_ID = PersistentConfig(
1580+
"ONEDRIVE_CLIENT_ID",
1581+
"onedrive.client_id",
1582+
os.environ.get("ONEDRIVE_CLIENT_ID", ""),
1583+
)
1584+
15691585
# RAG Content Extraction
15701586
CONTENT_EXTRACTION_ENGINE = PersistentConfig(
15711587
"CONTENT_EXTRACTION_ENGINE",
@@ -1579,6 +1595,18 @@ class BannerModel(BaseModel):
15791595
os.getenv("TIKA_SERVER_URL", "http://tika:9998"), # Default for sidecar deployment
15801596
)
15811597

1598+
DOCUMENT_INTELLIGENCE_ENDPOINT = PersistentConfig(
1599+
"DOCUMENT_INTELLIGENCE_ENDPOINT",
1600+
"rag.document_intelligence_endpoint",
1601+
os.getenv("DOCUMENT_INTELLIGENCE_ENDPOINT", ""),
1602+
)
1603+
1604+
DOCUMENT_INTELLIGENCE_KEY = PersistentConfig(
1605+
"DOCUMENT_INTELLIGENCE_KEY",
1606+
"rag.document_intelligence_key",
1607+
os.getenv("DOCUMENT_INTELLIGENCE_KEY", ""),
1608+
)
1609+
15821610
RAG_TOP_K = PersistentConfig(
15831611
"RAG_TOP_K", "rag.top_k", int(os.environ.get("RAG_TOP_K", "3"))
15841612
)

backend/open_webui/functions.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
import inspect
44
import json
5+
import asyncio
56

67
from pydantic import BaseModel
78
from typing import AsyncGenerator, Generator, Iterator
@@ -76,11 +77,13 @@ async def get_function_models(request):
7677
if hasattr(function_module, "pipes"):
7778
sub_pipes = []
7879

79-
# Check if pipes is a function or a list
80-
80+
# Handle pipes being a list, sync function, or async function
8181
try:
8282
if callable(function_module.pipes):
83-
sub_pipes = function_module.pipes()
83+
if asyncio.iscoroutinefunction(function_module.pipes):
84+
sub_pipes = await function_module.pipes()
85+
else:
86+
sub_pipes = function_module.pipes()
8487
else:
8588
sub_pipes = function_module.pipes
8689
except Exception as e:

backend/open_webui/main.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
OLLAMA_API_CONFIGS,
9696
# OpenAI
9797
ENABLE_OPENAI_API,
98+
ONEDRIVE_CLIENT_ID,
9899
OPENAI_API_BASE_URLS,
99100
OPENAI_API_KEYS,
100101
OPENAI_API_CONFIGS,
@@ -180,6 +181,8 @@
180181
CHUNK_SIZE,
181182
CONTENT_EXTRACTION_ENGINE,
182183
TIKA_SERVER_URL,
184+
DOCUMENT_INTELLIGENCE_ENDPOINT,
185+
DOCUMENT_INTELLIGENCE_KEY,
183186
RAG_TOP_K,
184187
RAG_TEXT_SPLITTER,
185188
TIKTOKEN_ENCODING_NAME,
@@ -215,11 +218,13 @@
215218
GOOGLE_PSE_ENGINE_ID,
216219
GOOGLE_DRIVE_CLIENT_ID,
217220
GOOGLE_DRIVE_API_KEY,
221+
ONEDRIVE_CLIENT_ID,
218222
ENABLE_RAG_HYBRID_SEARCH,
219223
ENABLE_RAG_LOCAL_WEB_FETCH,
220224
ENABLE_RAG_WEB_LOADER_SSL_VERIFICATION,
221225
ENABLE_RAG_WEB_SEARCH,
222226
ENABLE_GOOGLE_DRIVE_INTEGRATION,
227+
ENABLE_ONEDRIVE_INTEGRATION,
223228
UPLOAD_DIR,
224229
# WebUI
225230
WEBUI_AUTH,
@@ -533,6 +538,8 @@ async def lifespan(app: FastAPI):
533538

534539
app.state.config.CONTENT_EXTRACTION_ENGINE = CONTENT_EXTRACTION_ENGINE
535540
app.state.config.TIKA_SERVER_URL = TIKA_SERVER_URL
541+
app.state.config.DOCUMENT_INTELLIGENCE_ENDPOINT = DOCUMENT_INTELLIGENCE_ENDPOINT
542+
app.state.config.DOCUMENT_INTELLIGENCE_KEY = DOCUMENT_INTELLIGENCE_KEY
536543

537544
app.state.config.TEXT_SPLITTER = RAG_TEXT_SPLITTER
538545
app.state.config.TIKTOKEN_ENCODING_NAME = TIKTOKEN_ENCODING_NAME
@@ -564,6 +571,7 @@ async def lifespan(app: FastAPI):
564571
app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST = RAG_WEB_SEARCH_DOMAIN_FILTER_LIST
565572

566573
app.state.config.ENABLE_GOOGLE_DRIVE_INTEGRATION = ENABLE_GOOGLE_DRIVE_INTEGRATION
574+
app.state.config.ENABLE_ONEDRIVE_INTEGRATION = ENABLE_ONEDRIVE_INTEGRATION
567575
app.state.config.SEARXNG_QUERY_URL = SEARXNG_QUERY_URL
568576
app.state.config.GOOGLE_PSE_API_KEY = GOOGLE_PSE_API_KEY
569577
app.state.config.GOOGLE_PSE_ENGINE_ID = GOOGLE_PSE_ENGINE_ID
@@ -911,7 +919,7 @@ def get_filtered_models(models, user):
911919

912920
return filtered_models
913921

914-
models = await get_all_models(request)
922+
models = await get_all_models(request, user=user)
915923

916924
# Filter out filter pipelines
917925
models = [
@@ -951,7 +959,7 @@ async def chat_completion(
951959
user=Depends(get_verified_user),
952960
):
953961
if not request.app.state.MODELS:
954-
await get_all_models(request)
962+
await get_all_models(request, user=user)
955963

956964
model_item = form_data.pop("model_item", {})
957965
tasks = form_data.pop("background_tasks", None)
@@ -1146,6 +1154,7 @@ async def get_app_config(request: Request):
11461154
"enable_admin_export": ENABLE_ADMIN_EXPORT,
11471155
"enable_admin_chat_access": ENABLE_ADMIN_CHAT_ACCESS,
11481156
"enable_google_drive_integration": app.state.config.ENABLE_GOOGLE_DRIVE_INTEGRATION,
1157+
"enable_onedrive_integration": app.state.config.ENABLE_ONEDRIVE_INTEGRATION,
11491158
}
11501159
if user is not None
11511160
else {}
@@ -1177,6 +1186,7 @@ async def get_app_config(request: Request):
11771186
"client_id": GOOGLE_DRIVE_CLIENT_ID.value,
11781187
"api_key": GOOGLE_DRIVE_API_KEY.value,
11791188
},
1189+
"onedrive": {"client_id": ONEDRIVE_CLIENT_ID.value},
11801190
}
11811191
if user is not None
11821192
else {}

backend/open_webui/models/chats.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import logging
12
import json
23
import time
34
import uuid
45
from typing import Optional
56

67
from open_webui.internal.db import Base, get_db
78
from open_webui.models.tags import TagModel, Tag, Tags
8-
9+
from open_webui.env import SRC_LOG_LEVELS
910

1011
from pydantic import BaseModel, ConfigDict
1112
from sqlalchemy import BigInteger, Boolean, Column, String, Text, JSON
@@ -16,6 +17,8 @@
1617
# Chat DB Schema
1718
####################
1819

20+
log = logging.getLogger(__name__)
21+
log.setLevel(SRC_LOG_LEVELS["MODELS"])
1922

2023
class Chat(Base):
2124
__tablename__ = "chat"
@@ -670,7 +673,7 @@ def get_chats_by_user_id_and_search_text(
670673
# Perform pagination at the SQL level
671674
all_chats = query.offset(skip).limit(limit).all()
672675

673-
print(len(all_chats))
676+
log.info(f"The number of chats: {len(all_chats)}")
674677

675678
# Validate and return chats
676679
return [ChatModel.model_validate(chat) for chat in all_chats]
@@ -731,7 +734,7 @@ def get_chat_list_by_user_id_and_tag_name(
731734
query = db.query(Chat).filter_by(user_id=user_id)
732735
tag_id = tag_name.replace(" ", "_").lower()
733736

734-
print(db.bind.dialect.name)
737+
log.info(f"DB dialect name: {db.bind.dialect.name}")
735738
if db.bind.dialect.name == "sqlite":
736739
# SQLite JSON1 querying for tags within the meta JSON field
737740
query = query.filter(
@@ -752,7 +755,7 @@ def get_chat_list_by_user_id_and_tag_name(
752755
)
753756

754757
all_chats = query.all()
755-
print("all_chats", all_chats)
758+
log.debug(f"all_chats: {all_chats}")
756759
return [ChatModel.model_validate(chat) for chat in all_chats]
757760

758761
def add_chat_tag_by_id_and_user_id_and_tag_name(
@@ -810,7 +813,7 @@ def count_chats_by_tag_name_and_user_id(self, tag_name: str, user_id: str) -> in
810813
count = query.count()
811814

812815
# Debugging output for inspection
813-
print(f"Count of chats for tag '{tag_name}':", count)
816+
log.info(f"Count of chats for tag '{tag_name}': {count}")
814817

815818
return count
816819

backend/open_webui/models/feedbacks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def insert_new_feedback(
118118
else:
119119
return None
120120
except Exception as e:
121-
print(e)
121+
log.exception(f"Error creating a new feedback: {e}")
122122
return None
123123

124124
def get_feedback_by_id(self, id: str) -> Optional[FeedbackModel]:

backend/open_webui/models/files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def insert_new_file(self, user_id: str, form_data: FileForm) -> Optional[FileMod
119119
else:
120120
return None
121121
except Exception as e:
122-
print(f"Error creating tool: {e}")
122+
log.exception(f"Error inserting a new file: {e}")
123123
return None
124124

125125
def get_file_by_id(self, id: str) -> Optional[FileModel]:

backend/open_webui/models/folders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def insert_new_folder(
8282
else:
8383
return None
8484
except Exception as e:
85-
print(e)
85+
log.exception(f"Error inserting a new folder: {e}")
8686
return None
8787

8888
def get_folder_by_id_and_user_id(

backend/open_webui/models/functions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def insert_new_function(
105105
else:
106106
return None
107107
except Exception as e:
108-
print(f"Error creating tool: {e}")
108+
log.exception(f"Error creating a new function: {e}")
109109
return None
110110

111111
def get_function_by_id(self, id: str) -> Optional[FunctionModel]:
@@ -170,7 +170,7 @@ def get_function_valves_by_id(self, id: str) -> Optional[dict]:
170170
function = db.get(Function, id)
171171
return function.valves if function.valves else {}
172172
except Exception as e:
173-
print(f"An error occurred: {e}")
173+
log.exception(f"Error getting function valves by id {id}: {e}")
174174
return None
175175

176176
def update_function_valves_by_id(
@@ -202,7 +202,7 @@ def get_user_valves_by_id_and_user_id(
202202

203203
return user_settings["functions"]["valves"].get(id, {})
204204
except Exception as e:
205-
print(f"An error occurred: {e}")
205+
log.exception(f"Error getting user values by id {id} and user id {user_id}: {e}")
206206
return None
207207

208208
def update_user_valves_by_id_and_user_id(
@@ -225,7 +225,7 @@ def update_user_valves_by_id_and_user_id(
225225

226226
return user_settings["functions"]["valves"][id]
227227
except Exception as e:
228-
print(f"An error occurred: {e}")
228+
log.exception(f"Error updating user valves by id {id} and user_id {user_id}: {e}")
229229
return None
230230

231231
def update_function_by_id(self, id: str, updated: dict) -> Optional[FunctionModel]:

backend/open_webui/models/models.py

100644100755
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def insert_new_model(
166166
else:
167167
return None
168168
except Exception as e:
169-
print(e)
169+
log.exception(f"Failed to insert a new model: {e}")
170170
return None
171171

172172
def get_all_models(self) -> list[ModelModel]:
@@ -246,8 +246,7 @@ def update_model_by_id(self, id: str, model: ModelForm) -> Optional[ModelModel]:
246246
db.refresh(model)
247247
return ModelModel.model_validate(model)
248248
except Exception as e:
249-
print(e)
250-
249+
log.exception(f"Failed to update the model by id {id}: {e}")
251250
return None
252251

253252
def delete_model_by_id(self, id: str) -> bool:

backend/open_webui/models/tags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def insert_new_tag(self, name: str, user_id: str) -> Optional[TagModel]:
6161
else:
6262
return None
6363
except Exception as e:
64-
print(e)
64+
log.exception(f"Error inserting a new tag: {e}")
6565
return None
6666

6767
def get_tag_by_name_and_user_id(

0 commit comments

Comments
 (0)