From 0ce358451638ae0b4bc979ad10a8db6d698533bc Mon Sep 17 00:00:00 2001 From: Phil Szalay Date: Mon, 17 Feb 2025 18:32:05 +0100 Subject: [PATCH] Move openai.py to beyond_the_loop module --- .../routers/openai.py | 0 backend/open_webui/main.py | 24 ++----------------- backend/open_webui/routers/pipelines.py | 6 +---- backend/open_webui/utils/chat.py | 13 +++------- backend/open_webui/utils/models.py | 4 ++-- 5 files changed, 8 insertions(+), 39 deletions(-) rename backend/{open_webui => beyond_the_loop}/routers/openai.py (100%) diff --git a/backend/open_webui/routers/openai.py b/backend/beyond_the_loop/routers/openai.py similarity index 100% rename from backend/open_webui/routers/openai.py rename to backend/beyond_the_loop/routers/openai.py diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 07202bc27..038d2f70d 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -1,36 +1,25 @@ import asyncio -import inspect import json import logging import mimetypes import os -import shutil import sys import time -import random from contextlib import asynccontextmanager from urllib.parse import urlencode, parse_qs, urlparse from pydantic import BaseModel from sqlalchemy import text -from typing import Optional -from aiocache import cached import aiohttp -import requests - from fastapi import ( Depends, FastAPI, - File, - Form, HTTPException, Request, - UploadFile, status, applications, - BackgroundTasks, ) from fastapi.openapi.docs import get_swagger_ui_html @@ -42,8 +31,7 @@ from fastapi.staticfiles import StaticFiles from starlette.exceptions import HTTPException as StarletteHTTPException from starlette.middleware.base import BaseHTTPMiddleware from starlette.middleware.sessions import SessionMiddleware -from starlette.responses import Response, StreamingResponse - +from starlette.responses import Response from open_webui.socket.main import ( app as socket_app, @@ -53,7 +41,6 @@ from open_webui.routers import ( audio, images, ollama, - openai, retrieval, pipelines, tasks, @@ -73,6 +60,7 @@ from open_webui.routers import ( users, utils, ) +from beyond_the_loop.routers import openai from open_webui.routers.retrieval import ( get_embedding_function, @@ -130,17 +118,12 @@ from open_webui.config import ( AUDIO_TTS_AZURE_SPEECH_REGION, AUDIO_TTS_AZURE_SPEECH_OUTPUT_FORMAT, WHISPER_MODEL, - WHISPER_MODEL_AUTO_UPDATE, - WHISPER_MODEL_DIR, # Retrieval RAG_TEMPLATE, - DEFAULT_RAG_TEMPLATE, RAG_EMBEDDING_MODEL, RAG_EMBEDDING_MODEL_AUTO_UPDATE, - RAG_EMBEDDING_MODEL_TRUST_REMOTE_CODE, RAG_RERANKING_MODEL, RAG_RERANKING_MODEL_AUTO_UPDATE, - RAG_RERANKING_MODEL_TRUST_REMOTE_CODE, RAG_EMBEDDING_ENGINE, RAG_EMBEDDING_BATCH_SIZE, RAG_RELEVANCE_THRESHOLD, @@ -185,11 +168,9 @@ from open_webui.config import ( GOOGLE_DRIVE_CLIENT_ID, GOOGLE_DRIVE_API_KEY, ENABLE_RAG_HYBRID_SEARCH, - ENABLE_RAG_LOCAL_WEB_FETCH, ENABLE_RAG_WEB_LOADER_SSL_VERIFICATION, ENABLE_RAG_WEB_SEARCH, ENABLE_GOOGLE_DRIVE_INTEGRATION, - UPLOAD_DIR, # WebUI WEBUI_AUTH, WEBUI_NAME, @@ -211,7 +192,6 @@ from open_webui.config import ( DEFAULT_USER_ROLE, DEFAULT_PROMPT_SUGGESTIONS, DEFAULT_MODELS, - DEFAULT_ARENA_MODEL, MODEL_ORDER_LIST, EVALUATION_ARENA_MODELS, # WebUI (OAuth) diff --git a/backend/open_webui/routers/pipelines.py b/backend/open_webui/routers/pipelines.py index 062663671..69db4673f 100644 --- a/backend/open_webui/routers/pipelines.py +++ b/backend/open_webui/routers/pipelines.py @@ -1,6 +1,5 @@ from fastapi import ( Depends, - FastAPI, File, Form, HTTPException, @@ -14,15 +13,12 @@ import logging import shutil import requests from pydantic import BaseModel -from starlette.responses import FileResponse from typing import Optional from open_webui.env import SRC_LOG_LEVELS from open_webui.config import CACHE_DIR -from open_webui.constants import ERROR_MESSAGES - -from open_webui.routers.openai import get_all_models_responses +from beyond_the_loop.routers.openai import get_all_models_responses from open_webui.utils.auth import get_admin_user diff --git a/backend/open_webui/utils/chat.py b/backend/open_webui/utils/chat.py index 26ad6c1e7..2e48a109e 100644 --- a/backend/open_webui/utils/chat.py +++ b/backend/open_webui/utils/chat.py @@ -1,18 +1,13 @@ -import time import logging import sys -from aiocache import cached -from typing import Any, Optional +from typing import Any import random import json import inspect from fastapi import Request -from starlette.responses import Response, StreamingResponse - - -from beyond_the_loop.models.users import UserModel +from starlette.responses import StreamingResponse from open_webui.socket.main import ( get_event_call, @@ -20,7 +15,7 @@ from open_webui.socket.main import ( ) from open_webui.functions import generate_function_chat_completion -from open_webui.routers.openai import ( +from beyond_the_loop.routers.openai import ( generate_chat_completion as generate_openai_chat_completion, ) @@ -34,8 +29,6 @@ from open_webui.routers.pipelines import ( ) from open_webui.models.functions import Functions -from beyond_the_loop.models.models import Models - from open_webui.utils.plugin import load_function_module_by_id from open_webui.utils.models import get_all_models, check_model_access diff --git a/backend/open_webui/utils/models.py b/backend/open_webui/utils/models.py index 906ca5de6..f8bf53bbc 100644 --- a/backend/open_webui/utils/models.py +++ b/backend/open_webui/utils/models.py @@ -2,10 +2,10 @@ import time import logging import sys -from aiocache import cached from fastapi import Request -from open_webui.routers import openai, ollama +from open_webui.routers import ollama +from beyond_the_loop.routers import openai from open_webui.functions import get_function_models