langserve icon indicating copy to clipboard operation
langserve copied to clipboard

servery.py on_event deprecated

Open albertoecf opened this issue 1 year ago • 3 comments

Issue Description:

The on_event decorator used in langserve/server.py is deprecated. As of the current FastAPI version, lifespan event handlers should be used instead of on_event. This change is in line with the deprecation warning message.

Recommendation:

Please consider updating the code to use the new lifespan event handlers. You can find more information about lifespan events in the FastAPI documentation.

Motivation

While writing tests for our Langchain app, we encountered deprecation warnings related to the usage of the on_event decorator in the test setup.

from fastapi.testclient import TestClient
import pytest
from app.server import app

client = TestClient(app)

def test_server_startup():
    """
    Test if the FastAPI server starts correctly and responds to /docs endpoint.
    """
    with client:
        response = client.get("/docs")
        assert response.status_code == 200

warnings:

DeprecationWarning: on_event is deprecated, use lifespan event handlers instead. Read more about it in the FastAPI docs for Lifespan Events.

albertoecf avatar Feb 05 '24 08:02 albertoecf