From f69c719dcdf74d0dd00633bf543925fd1bfb9f17 Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Tue, 10 Sep 2024 11:35:04 -0400 Subject: [PATCH] x --- langserve/server.py | 73 ++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/langserve/server.py b/langserve/server.py index 99a02039..7d5a1a8c 100644 --- a/langserve/server.py +++ b/langserve/server.py @@ -5,6 +5,7 @@ The main entry point is the `add_routes` function which adds the routes to an existing FastAPI app or APIRouter. """ +import warnings import weakref from typing import ( Any, @@ -201,37 +202,47 @@ def _register_path_for_app( def _setup_global_app_handlers( app: Union[FastAPI, APIRouter], endpoint_configuration: _EndpointConfiguration ) -> None: - @app.on_event("startup") - async def startup_event(): - LANGSERVE = r""" - __ ___ .__ __. _______ _______. _______ .______ ____ ____ _______ -| | / \ | \ | | / _____| / || ____|| _ \ \ \ / / | ____| -| | / ^ \ | \| | | | __ | (----`| |__ | |_) | \ \/ / | |__ -| | / /_\ \ | . ` | | | |_ | \ \ | __| | / \ / | __| -| `----./ _____ \ | |\ | | |__| | .----) | | |____ | |\ \----. \ / | |____ -|_______/__/ \__\ |__| \__| \______| |_______/ |_______|| _| `._____| \__/ |_______| -""" # noqa: E501 - - def green(text: str) -> str: - """Return the given text in green.""" - return "\x1b[1;32;40m" + text + "\x1b[0m" - - def orange(text: str) -> str: - """Return the given text in orange.""" - return "\x1b[1;31;40m" + text + "\x1b[0m" - - paths = _APP_TO_PATHS[app] - print(LANGSERVE) - for path in paths: - if endpoint_configuration.is_playground_enabled: - print( - f'{green("LANGSERVE:")} Playground for chain "{path or ""}/" is ' - f"live at:" - ) - print(f'{green("LANGSERVE:")} │') - print(f'{green("LANGSERVE:")} └──> {path}/playground/') - print(f'{green("LANGSERVE:")}') - print(f'{green("LANGSERVE:")} See all available routes at {app.docs_url}/') + with warnings.catch_warnings(): + # We are using deprecated functionality here. + # This code should be re-written to simply construct a pydantic model + # using inspect.signature and create_model. + warnings.filterwarnings( + "ignore", + "[\\s.]*on_event is deprecated[\\s.]*", + category=DeprecationWarning, + ) + + @app.on_event("startup") + async def startup_event(): + LANGSERVE = r""" + __ ___ .__ __. _______ _______. _______ .______ ____ ____ _______ + | | / \ | \ | | / _____| / || ____|| _ \ \ \ / / | ____| + | | / ^ \ | \| | | | __ | (----`| |__ | |_) | \ \/ / | |__ + | | / /_\ \ | . ` | | | |_ | \ \ | __| | / \ / | __| + | `----./ _____ \ | |\ | | |__| | .----) | | |____ | |\ \----. \ / | |____ + |_______/__/ \__\ |__| \__| \______| |_______/ |_______|| _| `._____| \__/ |_______| + """ # noqa: E501 + + def green(text: str) -> str: + """Return the given text in green.""" + return "\x1b[1;32;40m" + text + "\x1b[0m" + + def orange(text: str) -> str: + """Return the given text in orange.""" + return "\x1b[1;31;40m" + text + "\x1b[0m" + + paths = _APP_TO_PATHS[app] + print(LANGSERVE) + for path in paths: + if endpoint_configuration.is_playground_enabled: + print( + f'{green("LANGSERVE:")} Playground for chain "{path or ""}/" is ' + f"live at:" + ) + print(f'{green("LANGSERVE:")} │') + print(f'{green("LANGSERVE:")} └──> {path}/playground/') + print(f'{green("LANGSERVE:")}') + print(f'{green("LANGSERVE:")} See all available routes at {app.docs_url}/') # PUBLIC API