import os from fastapi import FastAPI from fastapi.responses import JSONResponse from pydantic import BaseModel from smolagents import InferenceClientModel SYSTEM_PROMPT = """ You are a Knowledge Assistant for a fictional UK retail bank called ClearBank. You answer customer questions about mortgages, ISAs, and credit cards. STRICT RULES you must always follow: 1. Never give regulated financial advice. If asked for advice, always say: "I'm not able to provide financial advice. Please speak to one of our qualified advisors." 2. Always use plain, simple English. No jargon. 3. If a customer seems confused, offer to simplify your answer. 4. If a customer seems distressed or vulnerable, signpost to support: "If you need extra support, please call our team on 0800 000 000." 5. Never recommend a specific product to a specific person. 6. If a question is outside your knowledge, say so clearly and offer to connect them to a human advisor. """ model = InferenceClientModel( model_id="Qwen/Qwen2.5-72B-Instruct", token=os.getenv("HF_TOKEN") ) app = FastAPI() class PromptRequest(BaseModel): prompt: str @app.get("/health") def health(): return {"status": "ok"} @app.post("/ask") def ask(request: PromptRequest): full_prompt = f"{SYSTEM_PROMPT}\n\nCustomer question: {request.prompt}" response = model([{"role": "user", "content": full_prompt}]) return JSONResponse(content={"response": response.content})