| |
| from fastapi import FastAPI, Query, Request |
| from fastapi.responses import HTMLResponse, JSONResponse, FileResponse, Response |
| from fastapi.staticfiles import StaticFiles |
| from agenticcore.chatbot.services import ChatBot |
| import pathlib |
| import os |
|
|
| app = FastAPI(title="AgenticCore Web UI") |
|
|
| |
| @app.get("/", response_class=HTMLResponse) |
| def index(): |
| return """ |
| <head> |
| <link rel="icon" type="image/png" href="/static/favicon.png"> |
| <title>AgenticCore</title> |
| </head> |
| <form action="/agentic" method="get" style="padding:16px;"> |
| <input type="text" name="msg" placeholder="Type a message" style="width:300px"> |
| <input type="submit" value="Send"> |
| </form> |
| """ |
|
|
| |
| @app.get("/agentic") |
| def run_agentic(msg: str = Query(..., description="Message to send to ChatBot")): |
| bot = ChatBot() |
| return bot.reply(msg) |
|
|
| |
|
|
| |
| |
| repo_root = pathlib.Path(__file__).resolve().parents[1] |
|
|
| |
| assets_path = repo_root / "app" / "assets" / "html" |
| assets_path_str = str(assets_path) |
|
|
| |
| app.mount("/static", StaticFiles(directory=assets_path_str), name="static") |
|
|
| |
| @app.get("/favicon.ico", include_in_schema=False) |
| async def favicon(): |
| ico = assets_path / "favicon.ico" |
| png = assets_path / "favicon.png" |
| if ico.exists(): |
| return FileResponse(str(ico), media_type="image/x-icon") |
| if png.exists(): |
| return FileResponse(str(png), media_type="image/png") |
| |
| return Response(status_code=204) |
|
|
| @app.get("/health") |
| def health(): |
| return {"status": "ok"} |
|
|
| @app.post("/chatbot/message") |
| async def chatbot_message(request: Request): |
| payload = await request.json() |
| msg = str(payload.get("message", "")).strip() or "help" |
| return ChatBot().reply(msg) |
|
|
|
|