Deploy Localy
Deploy your agents with fastapi and docker
This guide will walk you through:
-
Creating a minimal FastAPI app with a Upsonic agent
-
Containerizing it with Docker
-
Running it locally
Setup
Create a new directory for your project
Create a new directory for your project and navigate to it:
After following this guide, your project structure will look like this:
Create a `requirements.txt` file and add the required dependencies:
Step 1: Create a FastAPI App with a Upsonic Agent
Create a new Python file, e.g., `main.py`, and add the following code to create a minimal FastAPI app with a Upsonic agent:
Create and activate a virtual environment:
Install the required dependencies by running:
Set your OPENAI_API_KEY environment variable:
Run the FastAPI app with `uvicorn main:app --reload`.
Step 2: Create a Dockerfile
In the same directory, create a new file named `Dockerfile` with the following content:
Build the Docker image by running:
Run the Docker container with:
Access your app
You can now access the FastAPI app at http://localhost:8000
.
Step 3: Advanced Configuration with Structured Responses
Enhance your `main.py` file to include structured responses using Pydantic models:
Run the updated Docker container:
Now your API provides both a general-purpose query endpoint and a specialized endpoint that returns structured travel recommendations.
You can test the structured response endpoint with:
This will return a JSON object with structured travel recommendation information.