from fastapi import FastAPI, APIRouter from pydantic import BaseModel # Import adhd_gemini function from adhd_gemini module from adhd_gemini import adhd_gemini # Create FastAPI app instance app = FastAPI() # Define a router for API documentation router = APIRouter() # Define request/response models class QueryIn(BaseModel): query: str class QueryOut(BaseModel): response: str # Define your endpoints @app.post("/adhd_gemini/", response_model=QueryOut) async def adhd_gemini_func(q: QueryIn): """ Endpoint to receive a query and return the response. """ response = adhd_gemini(query=q.query) return QueryOut(response=response) @app.post("/adhd_openai/", response_model=QueryOut) async def adhd_openai_func(q: QueryIn): """ Endpoint to receive a query and return the response. """ response = adhd_gemini(query=q.query) return QueryOut(response=response) # Add a default endpoint to display available endpoints @router.get("/") async def root(): return {"message": "Welcome to the chatbot API. Available endpoints:", "endpoints": [ "/adhd_gemini/ - POST method", "/adhd_openai/ - POST method" ]} # Include the router into the main app app.include_router(router) # Optionally, generate OpenAPI schema @app.get("/openapi.json") async def get_openapi(): return app.openapi() # This is optional, if you want to see the generated OpenAPI schema in Swagger UI @app.get("/docs") async def get_docs(): return app.openapi_schema() # This is also optional, for using Redoc @app.get("/redoc") async def redoc(): return app.openapi_schema(url="/openapi.json")