A FastAPI application that exposes multiple “task” endpoints and functions for data processing, file formatting, image manipulation, and more. This project is designed to demonstrate how to dispatch tasks using function-calling logic (similar to OpenAI function calls).
-
Operations Tasks (Phase A):
- Install
uvand run data generation script (datagen.py). - Format files using Prettier.
- Count weekday occurrences in date files.
- Sort JSON contacts by name.
- Extract log lines, index markdown files, etc.
- Use GPT-like calls to extract email addresses, credit card numbers, or find similar comments.
- Install
-
Business Tasks (Phase B):
- Fetch data from an API.
- Clone a Git repository and commit a message.
- Run SQL queries on a local SQLite database.
- Scrape website HTML, resize images, transcribe audio, convert Markdown to HTML, etc.
-
Python 3.10 (or compatible 3.x).
-
Docker (if running inside a Docker container).
-
For local usage, install dependencies:
pip install -r requirements.txt
-
You also need Node.js available if you plan to format files using Prettier directly from this code. The provided Dockerfile automatically installs Node.js.
-
Build the Docker image:
docker build -t fastapi-task-runner . -
Run the container:
docker run -d -p 8000:80 --name my_task_runner fastapi-task-runner
- This publishes the container’s port 80 to the host’s port 8000.
- Access the FastAPI application at:
http://localhost:8000
-
Check the application health (basic check; you can also do a
GETon/docsin your browser to see FastAPI docs):curl http://localhost:8000/docs
-
Run a Task:
The main endpoint is
/run. You pass a URL-encoded task query parameter which the code interprets. For example:curl -X POST "http://localhost:8000/run?task=install%20uv%20and%20run%20datagen"Internally, it uses the GPT-like function calling logic to pick the correct Python function. The tasks are auto-dispatched by the
handle_task(...)function inmain.py.
- Place sensitive keys in a file named
.envat the project root (or set them in your environment):OPENAI_API_KEY: Required for any LLM-based tasks (extracting emails, credit cards, or embeddings).OPENAI_API_BASE: Base URL for the OpenAI-like API endpoint. Defaults tohttps://aiproxy.sanand.workers.dev/openai/v1if not set.
- Clone this repository or copy
main.py,requirements.txt,Dockerfile, andREADME.mdinto your own project. - Install dependencies:
pip install --no-cache-dir -r requirements.txt
- Run locally with Uvicorn:
uvicorn main:app --host 0.0.0.0 --port 8000
- Visit
http://localhost:8000/docsto see interactive API docs.
- Some tasks require data files in a local
data/directory (e.g., logs, images, CSVs, Markdown files). Make sure your Docker container or local environment has those files mounted or included. - The code checks if the path is under
/datafor safety. This ensures only files within thedata/directory can be read or written. - Node.js is installed in the Docker image for the Prettier-based tasks. If you do not need Prettier or do not plan to run those tasks, feel free to remove Node.js installation from the Dockerfile.