File size: 989 Bytes
51769a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
POST /ai/explain
Explain selected H-Script code in simple Hinglish.
"""
from fastapi import APIRouter
from pydantic import BaseModel
from core.gemini_client import ask_gemini

router = APIRouter()

class ExplainRequest(BaseModel):
    code: str
    selection: str | None = None   # optional — explain just selected text

class ExplainResponse(BaseModel):
    explanation: str

@router.post("/explain", response_model=ExplainResponse)
async def explain_code(body: ExplainRequest):
    target = body.selection or body.code
    prompt = f"""
The user wants a simple explanation of this H-Script code.
Explain it line by line in simple Hinglish — like you're a friendly tutor
talking to a beginner. Use emojis and keep it fun.

Code to explain:
```
{target}
```

Give a clear, friendly explanation. Mention what each part does.
If there's a bug or potential issue, point it out gently.
"""
    explanation = await ask_gemini(prompt)
    return ExplainResponse(explanation=explanation)