Skip to content

Main

lifespan(app) async

Control the FastAPI lifecycle.

Source code in projects/gptstonks_api/gptstonks/api/main.py
@asynccontextmanager
async def lifespan(app: FastAPI):
    """Control the FastAPI lifecycle."""
    # Initialize everything
    init_api(app_data=app_data)
    yield

process_query_async(request, query_in) async

Asynchronous endpoint to start processing the given query. The processing runs in the background and the result is eventually returned.

Parameters:

Name Type Description Default
request `Request`

FastAPI request object containing the query to be processed.

required
query_in `QueryIn`

validated query by the user.

required

Returns:

Type Description
BaseAgentResponse | DataAgentResponse

BaseAgentResponse | DataAgentResponse: the standard response by the API.

Source code in projects/gptstonks_api/gptstonks/api/main.py
@app.post("/process_query_async")
async def process_query_async(
    request: Request, query_in: QueryIn
) -> BaseAgentResponse | DataAgentResponse:
    """Asynchronous endpoint to start processing the given query. The processing runs in the
    background and the result is eventually returned.

    Args:
        request (`Request`): FastAPI request object containing the query to be processed.
        query_in (`QueryIn`): validated query by the user.

    Returns:
        `BaseAgentResponse | DataAgentResponse`: the standard response by the API.
    """
    return await run_agent_in_background(query=query_in.query, app_data=app_data)