| from fastapi import FastAPI |
| from fastapi.responses import JSONResponse |
| from .schemas import MessageIn, MessageOut |
| from .guardrails import enforce_guardrails |
| from .rules import route |
|
|
| app = FastAPI(title='Anonymous Rule-Based Bot', version='1.0') |
|
|
| |
| |
|
|
| @app.post("/message", response_model=MessageOut) |
| def message(inbound: MessageIn): |
| ok, cleaned_or_reason = enforce_guardrails(inbound.message) |
| if not ok: |
| return JSONResponse(status_code=200, |
| content={'reply': cleaned_or_reason, 'blocked': True}) |
|
|
| |
| reply = route(cleaned_or_reason) |
| return {'reply': reply, 'blocked': False} |