Commit d0fa9c59 authored by Kostas Chartsias's avatar Kostas Chartsias
Browse files

refactor: migration from quart to FastAPI

parent 58403fca
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -18,4 +18,4 @@ RUN pip install --no-cache-dir \

COPY . /app/ai_agent

CMD ["python", "-m", "ai_agent.app"]
CMD ["sh", "-c", "uvicorn ai_agent.app:app --host ${APP_HOST:-0.0.0.0} --port ${APP_PORT:-9013}"]
+4 −5
Original line number Diff line number Diff line
# AI Agent 

This repository contains a lightweight **[`Quart`](https://quart.palletsprojects.com/en/latest/) backend server** that exposes API endpoints for interacting with different AI sub-agents. 
This repository contains a lightweight **[`FastAPI`](https://fastapi.tiangolo.com/)** backend server that exposes API endpoints for interacting with different AI sub-agents. 

---

@@ -96,7 +96,7 @@ Follow these steps to set up and run the app locally.
Start the backend server using:

```
python app.py
python -m ai_agent.app
```

The server will start at:
@@ -138,10 +138,9 @@ To add new functionality:
Example:

```
from ai_agent.routes.my_agent import register_my_agent_routes
register_my_agent_routes(app)
from ai_agent.routes.my_agent import router as my_agent_router
app.include_router(my_agent_router)
```

---
+16 −9
Original line number Diff line number Diff line
import os
import logging
from quart import Quart
from quart_cors import cors
from dotenv import load_dotenv
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from ai_agent.routes.groq import register_groq_routes
from ai_agent.routes.debug import register_debug_routes
from ai_agent.routes.groq import router as groq_router
from ai_agent.routes.debug import router as debug_router

load_dotenv()

logging.basicConfig(level=logging.INFO)

app = Quart(__name__)
app = cors(app, allow_origin="*")
app = FastAPI()
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=False,
    allow_methods=["*"],
    allow_headers=["*"],
)

register_groq_routes(app)
register_debug_routes(app)
app.include_router(groq_router)
app.include_router(debug_router)


if __name__ == "__main__":
    host = os.getenv("APP_HOST", "127.0.0.1")
    port = int(os.getenv("APP_PORT", "9013"))
    app.run(host=host, port=port, debug=False, use_reloader=False)
 No newline at end of file
    uvicorn.run("ai_agent.app:app", host=host, port=port, reload=False)
+2 −2
Original line number Diff line number Diff line
@@ -2,5 +2,5 @@ langchain_groq==1.1.2
mcp_use==1.6.0
objgraph==3.6.2
python-dotenv==1.2.1
quart==0.20.0
quart_cors==0.8.0
fastapi==0.118.0
uvicorn==0.37.0
+16 −13
Original line number Diff line number Diff line
import io
import sys
import objgraph
from quart import Response, jsonify
from fastapi import APIRouter
from fastapi.responses import PlainTextResponse

def register_debug_routes(app):
router = APIRouter()

    @app.route("/health", methods=["GET"])

@router.get("/health")
async def health_check():
    """Health check endpoint for Kubernetes liveness/readiness probes"""
        return jsonify({"status": "healthy"}), 200
    return {"status": "healthy"}


    @app.route("/debug/objgraph", methods=["GET"])
@router.get("/debug/objgraph")
async def debug_objgraph():
    buf = io.StringIO()
    original_stdout = sys.stdout
    sys.stdout = buf

    try:
        objgraph.show_growth(limit=10)

        sys.stdout = sys.__stdout__
        return Response(buf.getvalue(), mimetype="text/plain")
    finally:
        sys.stdout = original_stdout
    return PlainTextResponse(buf.getvalue())
Loading