Created
March 23, 2026 08:00
-
-
Save wooparadog/9e84ca609dd19a40233149d28ac348e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/orion/__init__.py b/orion/__init__.py | |
| index 7191d3248..bea10788f 100644 | |
| --- a/orion/__init__.py | |
| +++ b/orion/__init__.py | |
| @@ -10,11 +10,15 @@ import os | |
| import time | |
| import logging | |
| +t0 = time.time() | |
| logger = logging.getLogger(__name__) | |
| +def _is_truthy(value: str) -> bool: | |
| + return value.lower() in {"1", "true", "yes", "on"} | |
| + | |
| + | |
| def init_app(): | |
| - t0 = time.time() | |
| logger.info("init_app: before register_handlers") | |
| import orion.agi # type: ignore # noqa | |
| import orion.biz # type: ignore # noqa | |
| @@ -47,8 +51,26 @@ def init_openai(): | |
| openai.proxy = os.environ.get("https_proxy") # type: ignore | |
| +def init_fastapi_performance(): | |
| + from orion.utils.fastapi_performance import apply_fastapi_startup_caches | |
| + | |
| + apply_fastapi_startup_caches() | |
| + | |
| + | |
| +def should_init_sentry() -> bool: | |
| + if os.environ.get("DISABLED_SENTRY"): | |
| + return False | |
| + | |
| + if _is_truthy(os.environ.get("ENABLE_SENTRY_IN_DEV", "")): | |
| + return True | |
| + | |
| + env = os.environ.get("ENV", "dev").lower() | |
| + return env not in {"dev", "test"} | |
| + | |
| + | |
| init_logger() | |
| -if not os.environ.get("DISABLED_SENTRY"): | |
| +if should_init_sentry(): | |
| init_sentry() | |
| init_openai() | |
| +init_fastapi_performance() | |
| init_app() | |
| diff --git a/orion/biz/app/api.py b/orion/biz/app/api.py | |
| index 3acdcee69..0120fc6b1 100644 | |
| --- a/orion/biz/app/api.py | |
| +++ b/orion/biz/app/api.py | |
| @@ -28,6 +28,7 @@ from orion.server.auth import ( | |
| get_current_active_user, | |
| has_any_permission, | |
| ) | |
| +from orion.utils.fastapi_flags import LEAN_ROUTE_SCHEMA_MODE | |
| logger = logging.getLogger(__name__) | |
| @@ -98,7 +99,10 @@ class RerankResponse(PydanticV1BaseModel): | |
| results: List[RerankItem] | |
| -@app.post("/workflows/{workflow_uuid}") | |
| +@app.post( | |
| + "/workflows/{workflow_uuid}", | |
| + response_model=None if LEAN_ROUTE_SCHEMA_MODE else WorkflowApiResponse, | |
| +) | |
| async def execute_workflow( | |
| workflow_uuid: str, | |
| request: WorkflowApiRequest, | |
| diff --git a/orion/biz/app/app/app.py b/orion/biz/app/app/app.py | |
| index 20a5b2628..fcdd45ed3 100644 | |
| --- a/orion/biz/app/app/app.py | |
| +++ b/orion/biz/app/app/app.py | |
| @@ -3,6 +3,8 @@ import re | |
| import time | |
| from typing import Annotated, Callable | |
| +import os | |
| + | |
| from fastapi import Depends, FastAPI, Header, Request, Response, Security, status | |
| from fastapi.exceptions import RequestValidationError | |
| from fastapi.openapi.utils import get_openapi | |
| @@ -41,6 +43,12 @@ from .stackie import app as stackie_app | |
| from .user import app as user_app | |
| logger = logging.getLogger(__name__) | |
| +_ENABLE_SCHEMA_DUMMY_ROUTES = os.getenv("ENABLE_SCHEMA_DUMMY_ROUTES", "").lower() in { | |
| + "1", | |
| + "true", | |
| + "yes", | |
| + "on", | |
| +} | |
| app = FastAPI( | |
| @@ -260,9 +268,11 @@ async def logout( | |
| return Response(status_code=status.HTTP_204_NO_CONTENT) | |
| -@app.get("/dummy/errors", response_model=errors.AppError) | |
| -async def app_errors_dummy(): | |
| - raise errors.AppSystemUnknownError() | |
| +if _ENABLE_SCHEMA_DUMMY_ROUTES: | |
| + | |
| + @app.get("/dummy/errors", response_model=errors.AppError) | |
| + async def app_errors_dummy(): | |
| + raise errors.AppSystemUnknownError() | |
| app.include_router(oauth_app, prefix="/oauth") | |
| diff --git a/orion/biz/app/app/chat/chat.py b/orion/biz/app/app/chat/chat.py | |
| index 761a25e29..2cbbec6d4 100644 | |
| --- a/orion/biz/app/app/chat/chat.py | |
| +++ b/orion/biz/app/app/chat/chat.py | |
| @@ -1,6 +1,7 @@ | |
| import datetime | |
| import json | |
| import logging | |
| +import os | |
| import time | |
| from enum import StrEnum | |
| from typing import List, Optional | |
| @@ -37,6 +38,12 @@ from orion.server.auth import get_current_end_user, get_current_end_user_and_dat | |
| from orion.utils.cache import cache_redis, operation_mutex, limit_request_per_window | |
| logger = logging.getLogger(__name__) | |
| +_ENABLE_SCHEMA_DUMMY_ROUTES = os.getenv("ENABLE_SCHEMA_DUMMY_ROUTES", "").lower() in { | |
| + "1", | |
| + "true", | |
| + "yes", | |
| + "on", | |
| +} | |
| app = APIRouter(tags=["chat"]) | |
| @@ -372,6 +379,8 @@ async def inner_stackie_chat(request: InnerChatRequest, http_request: Request): | |
| return await _inner_chat(Product.STACKIE, request, http_request=http_request) | |
| -@app.get("/dummy/websocket", response_model=WebSocketEvent, tags=["chat_types"]) | |
| -async def app_chat_websocket_dummy(): | |
| - raise UserException() | |
| +if _ENABLE_SCHEMA_DUMMY_ROUTES: | |
| + | |
| + @app.get("/dummy/websocket", response_model=WebSocketEvent, tags=["chat_types"]) | |
| + async def app_chat_websocket_dummy(): | |
| + raise UserException() | |
| diff --git a/orion/biz/app/app/dola/events.py b/orion/biz/app/app/dola/events.py | |
| index 9654de093..75676a282 100644 | |
| --- a/orion/biz/app/app/dola/events.py | |
| +++ b/orion/biz/app/app/dola/events.py | |
| @@ -1,6 +1,7 @@ | |
| import datetime | |
| import json | |
| import logging | |
| +import os | |
| import re | |
| import time | |
| from enum import StrEnum | |
| @@ -132,6 +133,12 @@ app = APIRouter( | |
| dependencies=[Security(get_current_end_user, scopes=["openid"])], | |
| ) | |
| logger = logging.getLogger(__name__) | |
| +_ENABLE_SCHEMA_DUMMY_ROUTES = os.getenv("ENABLE_SCHEMA_DUMMY_ROUTES", "").lower() in { | |
| + "1", | |
| + "true", | |
| + "yes", | |
| + "on", | |
| +} | |
| recurrence_id_doc = ( | |
| "Recurrence ID, works when it's recurrence event, in datetime/date ISO 8601 format. " | |
| "Date for all-day event, datetime for event with time. " | |
| @@ -1196,13 +1203,15 @@ TokiRelatedObjects = Union[ | |
| ] | |
| -@app.get( | |
| - "/dummy/toki/related_objects", | |
| - response_model=TokiRelatedObjects, | |
| - tags=["chat_types"], | |
| -) | |
| -async def app_related_objects_dummy(): | |
| - raise UserException() | |
| +if _ENABLE_SCHEMA_DUMMY_ROUTES: | |
| + | |
| + @app.get( | |
| + "/dummy/toki/related_objects", | |
| + response_model=TokiRelatedObjects, | |
| + tags=["chat_types"], | |
| + ) | |
| + async def app_related_objects_dummy(): | |
| + raise UserException() | |
| class DolaUpdateReactionRequest(PydanticV1BaseModel): | |
| diff --git a/orion/biz/app/app/dola/otp.py b/orion/biz/app/app/dola/otp.py | |
| index 93dcdf253..92d5c3539 100644 | |
| --- a/orion/biz/app/app/dola/otp.py | |
| +++ b/orion/biz/app/app/dola/otp.py | |
| @@ -50,6 +50,7 @@ from orion.config import settings | |
| from orion.errors import RateLimitError | |
| from orion.metrics import otp_login, otp_new_user, otp_send | |
| from orion.server.auth import get_current_end_user_or_none | |
| +from orion.utils.fastapi_flags import LEAN_ROUTE_SCHEMA_MODE | |
| from orion.utils.version import version_compare | |
| logger = logging.getLogger(__name__) | |
| @@ -273,12 +274,16 @@ class LoginWithOtpRequest(PydanticV2BaseModel): | |
| @app.post( | |
| "/login", | |
| - response_model=Token, | |
| - responses={ | |
| - 400: {"model": AppRequestVerificationCodeExpiredError}, | |
| - 418: {"model": AppRequestRegionNotSupportedError}, | |
| - 429: {"model": AppRequestVerificationTooManyRequestsError}, | |
| - }, | |
| + response_model=None if LEAN_ROUTE_SCHEMA_MODE else Token, | |
| + responses=( | |
| + {400: {}, 418: {}, 429: {}} | |
| + if LEAN_ROUTE_SCHEMA_MODE | |
| + else { | |
| + 400: {"model": AppRequestVerificationCodeExpiredError}, | |
| + 418: {"model": AppRequestRegionNotSupportedError}, | |
| + 429: {"model": AppRequestVerificationTooManyRequestsError}, | |
| + } | |
| + ), | |
| ) | |
| async def login_with_otp( | |
| request: LoginWithOtpRequest, | |
| diff --git a/orion/biz/app/app/files.py b/orion/biz/app/app/files.py | |
| index 60c8ca0a2..30ed2cf6a 100644 | |
| --- a/orion/biz/app/app/files.py | |
| +++ b/orion/biz/app/app/files.py | |
| @@ -33,6 +33,7 @@ from orion.storage.utils import ( | |
| get_user_attachment_key, | |
| get_user_attachment_url, | |
| ) | |
| +from orion.utils.fastapi_flags import LEAN_ROUTE_SCHEMA_MODE | |
| logger = logging.getLogger(__name__) | |
| @@ -433,7 +434,12 @@ class CreateUserAttachmentResponse(PydanticV2BaseModel): | |
| file_url: str | |
| -@app.post("/attachment", response_model=CreateUserAttachmentResponse) | |
| +@app.post( | |
| + "/attachment", | |
| + response_model=( | |
| + None if LEAN_ROUTE_SCHEMA_MODE else CreateUserAttachmentResponse | |
| + ), | |
| +) | |
| async def create_user_attachment( | |
| request: CreateUserAttachmentRequest, | |
| current_user: Annotated[User, Depends(get_current_end_user)], | |
| diff --git a/orion/biz/app/app/stackie/conversations.py b/orion/biz/app/app/stackie/conversations.py | |
| index a17aebe35..54f66604d 100644 | |
| --- a/orion/biz/app/app/stackie/conversations.py | |
| +++ b/orion/biz/app/app/stackie/conversations.py | |
| @@ -84,6 +84,7 @@ from orion.storage.utils import ( | |
| get_object_name_from_url, | |
| get_user_attachment_url, | |
| ) | |
| +from orion.utils.fastapi_flags import LEAN_ROUTE_SCHEMA_MODE | |
| from orion.utils.sentry import capture_error_to_sentry | |
| logger = logging.getLogger(__name__) | |
| @@ -467,8 +468,11 @@ async def _yield_stream_response( | |
| @app.post( | |
| "", | |
| - response_model=StackieConversationSendMessageResponse | |
| - | list[StackieConversationEvent], | |
| + response_model=( | |
| + None | |
| + if LEAN_ROUTE_SCHEMA_MODE | |
| + else StackieConversationSendMessageResponse | list[StackieConversationEvent] | |
| + ), | |
| ) | |
| async def stackie_send_message( | |
| request: StackieConversationSendMessageRequest, | |
| diff --git a/orion/biz/app/app/stackie/log.py b/orion/biz/app/app/stackie/log.py | |
| index 8416aae48..de8f543fc 100644 | |
| --- a/orion/biz/app/app/stackie/log.py | |
| +++ b/orion/biz/app/app/stackie/log.py | |
| @@ -1,5 +1,6 @@ | |
| import asyncio | |
| import logging | |
| +import os | |
| import uuid | |
| from typing import Any, Literal | |
| @@ -52,6 +53,12 @@ from orion.storage.utils import get_object_name_from_s3_url, get_user_attachment | |
| from .conversations import _generate_conversation_id | |
| logger = logging.getLogger(__name__) | |
| +_ENABLE_SCHEMA_DUMMY_ROUTES = os.getenv("ENABLE_SCHEMA_DUMMY_ROUTES", "").lower() in { | |
| + "1", | |
| + "true", | |
| + "yes", | |
| + "on", | |
| +} | |
| app = APIRouter( | |
| @@ -374,6 +381,8 @@ async def _new_log_streaming_response( | |
| pass | |
| -@app.trace("/dummy", response_model=StackieNewLogEvent) | |
| -def stackie_new_log_dummy(): | |
| - """Dummy endpoint for adding models to the OpenAPI schema""" | |
| +if _ENABLE_SCHEMA_DUMMY_ROUTES: | |
| + | |
| + @app.trace("/dummy", response_model=StackieNewLogEvent) | |
| + def stackie_new_log_dummy(): | |
| + """Dummy endpoint for adding models to the OpenAPI schema""" | |
| diff --git a/orion/biz/app/app/stackie/message_state.py b/orion/biz/app/app/stackie/message_state.py | |
| index 754661408..0be0e688f 100644 | |
| --- a/orion/biz/app/app/stackie/message_state.py | |
| +++ b/orion/biz/app/app/stackie/message_state.py | |
| @@ -1,3 +1,5 @@ | |
| +import os | |
| + | |
| from fastapi import APIRouter, Security | |
| from orion.common import PydanticV2BaseModel | |
| @@ -7,12 +9,20 @@ app = APIRouter( | |
| tags=["stackie_message_state"], | |
| dependencies=[Security(get_current_end_user, scopes=["openid"])], | |
| ) | |
| +_ENABLE_SCHEMA_DUMMY_ROUTES = os.getenv("ENABLE_SCHEMA_DUMMY_ROUTES", "").lower() in { | |
| + "1", | |
| + "true", | |
| + "yes", | |
| + "on", | |
| +} | |
| class StackieMessageState(PydanticV2BaseModel): | |
| cancelled: bool | None = False | |
| -@app.trace("/dummy", response_model=StackieMessageState) | |
| -def stackie_message_state_dummy(): | |
| - """Dummy endpoint for adding models to the OpenAPI schema""" | |
| +if _ENABLE_SCHEMA_DUMMY_ROUTES: | |
| + | |
| + @app.trace("/dummy", response_model=StackieMessageState) | |
| + def stackie_message_state_dummy(): | |
| + """Dummy endpoint for adding models to the OpenAPI schema""" | |
| diff --git a/orion/biz/app/app/stackie/rich_message.py b/orion/biz/app/app/stackie/rich_message.py | |
| index a1752c153..41e3a1366 100644 | |
| --- a/orion/biz/app/app/stackie/rich_message.py | |
| +++ b/orion/biz/app/app/stackie/rich_message.py | |
| @@ -1,3 +1,4 @@ | |
| +import os | |
| from typing import Annotated, Any, Literal | |
| from fastapi import APIRouter, Depends, Query, Security | |
| @@ -17,6 +18,12 @@ app = APIRouter( | |
| tags=["stackie_rich_message"], | |
| dependencies=[Security(get_current_end_user, scopes=["openid"])], | |
| ) | |
| +_ENABLE_SCHEMA_DUMMY_ROUTES = os.getenv("ENABLE_SCHEMA_DUMMY_ROUTES", "").lower() in { | |
| + "1", | |
| + "true", | |
| + "yes", | |
| + "on", | |
| +} | |
| class StackieRichMessageProcessing(PydanticV2BaseModel): | |
| @@ -55,9 +62,11 @@ class StackieRichMessage(PydanticV2RootModel): | |
| ] | |
| -@app.trace("/dummy", response_model=StackieRichMessage) | |
| -def stackie_rich_message_dummy(): | |
| - """Dummy endpoint for adding models to the OpenAPI schema""" | |
| +if _ENABLE_SCHEMA_DUMMY_ROUTES: | |
| + | |
| + @app.trace("/dummy", response_model=StackieRichMessage) | |
| + def stackie_rich_message_dummy(): | |
| + """Dummy endpoint for adding models to the OpenAPI schema""" | |
| class StackieRichMessageResolveSqlResponse(PydanticV2BaseModel): | |
| diff --git a/orion/biz/app/syft/ask/_dummy.py b/orion/biz/app/syft/ask/_dummy.py | |
| index 3b6cb7b91..447546cd8 100644 | |
| --- a/orion/biz/app/syft/ask/_dummy.py | |
| +++ b/orion/biz/app/syft/ask/_dummy.py | |
| @@ -1,3 +1,4 @@ | |
| +import os | |
| from typing import Union | |
| from fastapi import APIRouter, Request | |
| @@ -15,20 +16,27 @@ from orion.biz.handlers.subscription.ask.types import ( | |
| from orion.errors import UserException | |
| app = APIRouter(prefix="/_") | |
| +_ENABLE_SCHEMA_DUMMY_ROUTES = os.getenv("ENABLE_SCHEMA_DUMMY_ROUTES", "").lower() in { | |
| + "1", | |
| + "true", | |
| + "yes", | |
| + "on", | |
| +} | |
| +if _ENABLE_SCHEMA_DUMMY_ROUTES: | |
| -@app.delete( | |
| - "", | |
| - response_model=Union[ | |
| - AskAck, | |
| - AskAckSyncLatest, | |
| - AskInputMessage, | |
| - AskAckInput, | |
| - AskInterruptMessage, | |
| - AskOutEvent, | |
| - AskOutMessage, | |
| - AskSyncLatestMessage, | |
| - ], | |
| -) | |
| -async def o(_: Request): | |
| - raise UserException() | |
| + @app.delete( | |
| + "", | |
| + response_model=Union[ | |
| + AskAck, | |
| + AskAckSyncLatest, | |
| + AskInputMessage, | |
| + AskAckInput, | |
| + AskInterruptMessage, | |
| + AskOutEvent, | |
| + AskOutMessage, | |
| + AskSyncLatestMessage, | |
| + ], | |
| + ) | |
| + async def o(_: Request): | |
| + raise UserException() | |
| diff --git a/orion/biz/app/syftpp/_ws.py b/orion/biz/app/syftpp/_ws.py | |
| index c56876651..e7975936f 100644 | |
| --- a/orion/biz/app/syftpp/_ws.py | |
| +++ b/orion/biz/app/syftpp/_ws.py | |
| @@ -1,3 +1,4 @@ | |
| +import os | |
| from typing import Union | |
| from fastapi import APIRouter, Request | |
| @@ -20,27 +21,34 @@ from orion.biz.handlers.syftpp.summarizer.types import SummaryRequest, SummaryRe | |
| from orion.errors import UserException | |
| app = APIRouter() | |
| +_ENABLE_SCHEMA_DUMMY_ROUTES = os.getenv("ENABLE_SCHEMA_DUMMY_ROUTES", "").lower() in { | |
| + "1", | |
| + "true", | |
| + "yes", | |
| + "on", | |
| +} | |
| +if _ENABLE_SCHEMA_DUMMY_ROUTES: | |
| -@app.delete( | |
| - "", | |
| - response_model=Union[ | |
| - DetailRequest, | |
| - DetailResponse, | |
| - HeadlineRequest, | |
| - HeadlineResponse, | |
| - HeadlineCategoriesResponse, | |
| - InterestMoreRequest, | |
| - InterestMoreResponse, | |
| - MoreRequest, | |
| - MoreResponse, | |
| - SummaryRequest, | |
| - SummaryResponse, | |
| - ExploreCategoriesRequest, | |
| - ExploreCategoriesResponse, | |
| - ExploreRequest, | |
| - ExploreResponse, | |
| - ], | |
| -) | |
| -async def wstypes(_: Request): | |
| - raise UserException() | |
| + @app.delete( | |
| + "", | |
| + response_model=Union[ | |
| + DetailRequest, | |
| + DetailResponse, | |
| + HeadlineRequest, | |
| + HeadlineResponse, | |
| + HeadlineCategoriesResponse, | |
| + InterestMoreRequest, | |
| + InterestMoreResponse, | |
| + MoreRequest, | |
| + MoreResponse, | |
| + SummaryRequest, | |
| + SummaryResponse, | |
| + ExploreCategoriesRequest, | |
| + ExploreCategoriesResponse, | |
| + ExploreRequest, | |
| + ExploreResponse, | |
| + ], | |
| + ) | |
| + async def wstypes(_: Request): | |
| + raise UserException() | |
| diff --git a/orion/biz/app/user_checkout.py b/orion/biz/app/user_checkout.py | |
| index 15483c256..07e6f3622 100644 | |
| --- a/orion/biz/app/user_checkout.py | |
| +++ b/orion/biz/app/user_checkout.py | |
| @@ -53,6 +53,7 @@ from orion.config import settings | |
| from orion.errors import ObjectNotFound | |
| from orion.server.auth import get_current_end_user, get_current_end_user_or_none | |
| from orion.utils.cache import redis_cacher | |
| +from orion.utils.fastapi_flags import LEAN_ROUTE_SCHEMA_MODE | |
| app = APIRouter( | |
| tags=["checkout"], | |
| @@ -245,7 +246,10 @@ class CheckoutSessionResponse(BaseModel): | |
| pix: CheckoutSessionPixInfo | None = None | |
| -@app.post("/quick/subscription/google", response_model=CheckoutSessionResponse) | |
| +@app.post( | |
| + "/quick/subscription/google", | |
| + response_model=None if LEAN_ROUTE_SCHEMA_MODE else CheckoutSessionResponse, | |
| +) | |
| async def quick_start_subscription_checkout_via_google_oauth( | |
| current_user: Annotated[User, Depends(get_current_end_user)], | |
| request: CreateSubscriptionCheckoutSessionRequest, | |
| @@ -282,7 +286,10 @@ async def quick_start_subscription_checkout_via_google_oauth( | |
| return CheckoutSessionResponse(url=url) | |
| -@app.post("/v2/quick/subscription/google", response_model=CheckoutSessionResponse) | |
| +@app.post( | |
| + "/v2/quick/subscription/google", | |
| + response_model=None if LEAN_ROUTE_SCHEMA_MODE else CheckoutSessionResponse, | |
| +) | |
| async def quick_start_subscription_checkout_via_google_oauth_v2( | |
| current_user: Annotated[User, Depends(get_current_end_user)], | |
| request: CreateSubscriptionCheckoutSessionRequest, | |
| diff --git a/orion/live_settings.py b/orion/live_settings.py | |
| index 7120b1b74..d7f1fd9e1 100644 | |
| --- a/orion/live_settings.py | |
| +++ b/orion/live_settings.py | |
| @@ -113,9 +113,24 @@ class LiveSettings(LiveSettingsBase): | |
| live_settings = LiveSettings() | |
| reloader = LiveSettingsReloader("orion", live_settings_redis, live_settings) | |
| + | |
| +def _is_truthy(value: str) -> bool: | |
| + return value.lower() in {"1", "true", "yes", "on"} | |
| + | |
| + | |
| +def _should_wait_connect() -> bool: | |
| + override = os.getenv("LIVE_SETTINGS_WAIT_CONNECT") | |
| + if override is not None: | |
| + return _is_truthy(override) | |
| + | |
| + env = os.getenv("ENV", "dev").lower() | |
| + return env not in {"dev", "test"} | |
| + | |
| + | |
| if not os.getenv("SKIP_LIVE_SETTINGS_LOAD", ""): | |
| reloader.background_start(interval_secs=30) | |
| - reloader.wait_connect(interval_secs=1) | |
| + if _should_wait_connect(): | |
| + reloader.wait_connect(interval_secs=1) | |
| # | |
| # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment