File size: 821 Bytes
732e77c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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')

# No sessions, cookies, or user IDs — truly anonymous and stateless.
# No logging of raw user input here (keeps it anonymous and reduces risk).

@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})

    # Rule-based reply (deterministic: no persistence)
    reply = route(cleaned_or_reason)
    return {'reply': reply, 'blocked': False}