- Creating a minimal FastAPI app with a Upsonic agent
- Containerizing it with Docker
- Running it locally
Setup
1
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:
2
Create a `requirements.txt` file and add the required dependencies:
requirements.txt
Step 1: Create a FastAPI App with a Upsonic Agent
1
Create a new Python file, e.g., `main.py`, and add the following code to create a minimal FastAPI app with a Upsonic agent:
main.py
2
Create and activate a virtual environment:
3
Install the required dependencies by running:
4
Set your OPENAI_API_KEY environment variable:
5
Run the FastAPI app with `uvicorn main:app --reload`.
Step 2: Create a Dockerfile
1
In the same directory, create a new file named `Dockerfile` with the following content:
Dockerfile
2
Build the Docker image by running:
3
Run the Docker container with:
4
Access your app
You can now access the FastAPI app at
http://localhost:8000
.Step 3: Advanced Configuration with Structured Responses
1
Enhance your `main.py` file to include structured responses using Pydantic models:
main.py
2
Run the updated Docker container: