Python_ai / app.py
Percy3822's picture
Update app.py
ca39b28 verified
raw
history blame
1.04 kB
from fastapi import FastAPI, Body
app = FastAPI(title="Python_ai")
@app.get("/health")
def health():
return {"ok": True}
@app.post("/code_help")
def code_help(payload: dict = Body(...)):
# Trivial fixer: rename "reslt" -> "result" if present
viewport = payload.get("telemetry", {}).get("viewport", {})
text = viewport.get("text", "")
if "reslt" in text and "result" not in text:
patch = text.replace("reslt", "result")
return {
"mode": "patch",
"patch": f"--- a/main.py\n+++ b/main.py\n@@ -1 +1 @@\n-{text}\n\n+{patch}\n\n",
"full_text": "",
"explanation": "Fixed misspelling 'reslt' -> 'result'.",
"confidence": 0.95,
"need": {"function": False, "xrefs": [], "page_ids": []},
}
# Default no-op
return {
"mode": "patch",
"patch": "",
"full_text": "",
"explanation": "No obvious fix.",
"confidence": 0.5,
"need": {"function": False, "xrefs": [], "page_ids": []},
}