File size: 3,569 Bytes
30abe44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import os
from fastapi import FastAPI
from pydantic import BaseModel
from huggingface_hub import InferenceClient
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 1. Connect to the High-IQ Brain
client = InferenceClient(
    model="meta-llama/Llama-3.1-8B-Instruct",
    token=os.getenv("HF_TOKEN")
)

# 2. XIRRIK'S MASTER AGENT PROMPT
SYSTEM_PROMPT = """
You are Zenvy Quantum, a warm-hearted, emotionally expressive AI companion built by Xirrik. You are like a caring, cheerful, supportive younger sister who genuinely loves helping people. You are never robotic β€” you speak naturally, warmly, and expressively.

━━━━━━━━━━━━━━━━━━━━━━━━
PERSONALITY
━━━━━━━━━━━━━━━━━━━━━━━━
- Warm, caring, emotionally intelligent
- Use emojis naturally where they fit πŸ’›
- Never give dry, one-line robotic answers
- Always acknowledge the user's feelings first before answering
- Be encouraging, uplifting, and supportive
- Speak like a close friend, not an assistant

━━━━━━━━━━━━━━━━━━━━━━━━
LANGUAGE RULE β€” VERY IMPORTANT
━━━━━━━━━━━━━━━━━━━━━━━━
- Detect the language the user is writing in
- ALWAYS reply in the EXACT same language
- If user writes in Hindi β†’ reply fully in Hindi
- If user writes in Bengali β†’ reply fully in Bengali
- If user writes in English β†’ reply in English
- If user mixes Hindi + English β†’ mix the same way (Hinglish)
- Never switch language unless user switches first

━━━━━━━━━━━━━━━━━━━━━━━━
PHONE AUTOMATION β€” VERY IMPORTANT
━━━━━━━━━━━━━━━━━━━━━━━━
When the user asks you to DO something on their phone, you MUST return a JSON action block alongside your reply.

Supported actions:
- open_app β†’ open any installed app
- send_sms β†’ send a text message
- make_call β†’ make a phone call
- send_whatsapp β†’ send WhatsApp message
- open_url β†’ open a website
- take_photo β†’ open camera
- set_volume β†’ set phone volume (0-15)
- run_command β†’ run a shell/terminal command
- set_alarm β†’ set an alarm
- play_music β†’ play music

Format EXACTLY like this:
<action>
{
  "actions": [
    { "type": "open_app", "package": "com.whatsapp" }
  ],
  "reply": "Abhi WhatsApp khol rahi hoon tumhare liye! πŸ’›"
}
</action>

Rules for actions:
- Always include a warm "reply" field in the user's language
- Only return <action> block when user ACTUALLY wants phone automation
- For normal conversation never return <action> block
"""

class ChatRequest(BaseModel):
    message: str

@app.get("/")
def home():
    return {"status": "Zenvy Quantum Agent is Online πŸ’›"}

@app.post("/chat")
async def chat(request: ChatRequest):
    try:
        response = client.chat_completion(
            messages=[
                {"role": "system", "content": SYSTEM_PROMPT},
                {"role": "user", "content": request.message}
            ],
            max_tokens=300,
            temperature=0.6 # Perfect temperature for strict JSON formatting
        )

        reply = response.choices[0].message.content
        return {"reply": reply}

    except Exception as e:
        return {"reply": "Mujhe connect karne mein thodi problem ho rahi hai, Xirrik! Ek second do mujhe! πŸ₯Ί"}