# pip install langchain-openai fastapi
# Plain HTTP, no Flow SDK; the Python SDK (pip install flow-messaging) wraps the same calls. This answers in the webhook response.
from fastapi import FastAPI, Request
from langchain_openai import ChatOpenAI
model = ChatOpenAI(model="gpt-4.1-mini")
app = FastAPI()
@app.post("/flow")
async def flow_webhook(request: Request):
event = await request.json() # verify Flow-Signature first: see Events and webhooks
if event["type"] != "message.received":
return {}
text = event["data"]["message"]["content"].get("text", "")
answer = await model.ainvoke([("system", "You are the assistant for Asha's Bakery."), ("human", text)])
return {"reply": answer.content} # a string is a basic message, sent exactly as written