Rest API
This documentation provides an overview of the code used to implement a RESTful API server for the pipeline using the SuperagentX library and FastAPI. The server processes incoming requests, authenticates users via API tokens, and handles search queries related to the trip planner.
Overview
The code sets up a FastAPI server that processes search requests using the AgentXPipe class from SuperagentX. It incorporates a custom authentication mechanism to validate client requests via an API token. The API exposes an endpoint that allows users to submit a query and receive results from the trip planner pipeline.
Setup Environment
Implementation
Import the dependencies.
The lifespan function initializes the trip planner pipeline when the FastAPI application starts and clears it when the app shuts down. The pipes dictionary is used to store the pipeline for later use in request handling.
A custom dependency function, verify_api_token, checks the validity of the API token passed in the api-token header. If the token is invalid, the function raises an HTTP 401 Unauthorized error.
The main API application (ecom_app) is created using FastAPI. The /search endpoint processes search queries related to the trip planner. The verify_api_token function is included as a dependency to authenticate requests before processing them.
This RESTful API provides a simple yet powerful interface for interacting with the trip planner pipeline, ensuring secure access via API token validation.