raghavNCI
commited on
Commit
·
975c3a7
1
Parent(s):
68f07e2
wa fixes
Browse files
models_initialization/mistral_registry.py
CHANGED
@@ -18,7 +18,8 @@ def mistral_generate(prompt: str, max_new_tokens=128, temperature=0.7) -> str:
|
|
18 |
"inputs": prompt,
|
19 |
"parameters": {
|
20 |
"max_new_tokens": max_new_tokens,
|
21 |
-
"temperature": temperature
|
|
|
22 |
}
|
23 |
}
|
24 |
|
|
|
18 |
"inputs": prompt,
|
19 |
"parameters": {
|
20 |
"max_new_tokens": max_new_tokens,
|
21 |
+
"temperature": temperature,
|
22 |
+
"wait_for_model": True
|
23 |
}
|
24 |
}
|
25 |
|
routes/wa_gateway.py
CHANGED
@@ -15,9 +15,6 @@ VERIFY_TOKEN = os.getenv("VERIFY_TOKEN")
|
|
15 |
ACCESS_TOKEN = os.getenv("WHATSAPP_ACCESS_TOKEN")
|
16 |
PHONE_NUMBER_ID = os.getenv("WHATSAPP_PHONE_NUMBER_ID")
|
17 |
|
18 |
-
# ------------------------------------------------------------------
|
19 |
-
# Helper: actually POST a plain-text WhatsApp message via Graph API
|
20 |
-
# ------------------------------------------------------------------
|
21 |
def send_whatsapp_text(to: str, text: str) -> dict:
|
22 |
"""
|
23 |
Send a plain text message (max 4096 chars per WhatsApp limits).
|
@@ -32,7 +29,7 @@ def send_whatsapp_text(to: str, text: str) -> dict:
|
|
32 |
"messaging_product": "whatsapp",
|
33 |
"to": to,
|
34 |
"type": "text",
|
35 |
-
"text": {"body": text[:4096]},
|
36 |
}
|
37 |
|
38 |
try:
|
@@ -42,9 +39,6 @@ def send_whatsapp_text(to: str, text: str) -> dict:
|
|
42 |
except Exception as e:
|
43 |
return {"status": "failed", "error": str(e)}
|
44 |
|
45 |
-
# ------------------------------------------------------------------
|
46 |
-
# Helper: glue logic – ask Mistral and relay the reply to WhatsApp
|
47 |
-
# ------------------------------------------------------------------
|
48 |
async def nuse_interact(to: str, name: str, prompt: str) -> dict:
|
49 |
"""
|
50 |
1. Call ask_question() directly (no HTTP round-trip);
|
@@ -63,9 +57,6 @@ async def nuse_interact(to: str, name: str, prompt: str) -> dict:
|
|
63 |
# 2) Send to WhatsApp
|
64 |
return send_whatsapp_text(to, answer_text)
|
65 |
|
66 |
-
# ------------------------------------------------------------------
|
67 |
-
# Webhook verification (unchanged)
|
68 |
-
# ------------------------------------------------------------------
|
69 |
@wa_router.get("/webhook")
|
70 |
async def verify_webhook(request: Request):
|
71 |
params = request.query_params
|
@@ -73,9 +64,6 @@ async def verify_webhook(request: Request):
|
|
73 |
return PlainTextResponse(content=params.get("hub.challenge"))
|
74 |
return JSONResponse(status_code=403, content={"error": "Verification failed"})
|
75 |
|
76 |
-
# ------------------------------------------------------------------
|
77 |
-
# Incoming WhatsApp messages
|
78 |
-
# ------------------------------------------------------------------
|
79 |
@wa_router.post("/webhook")
|
80 |
async def receive_whatsapp_event(request: Request):
|
81 |
body = await request.json()
|
|
|
15 |
ACCESS_TOKEN = os.getenv("WHATSAPP_ACCESS_TOKEN")
|
16 |
PHONE_NUMBER_ID = os.getenv("WHATSAPP_PHONE_NUMBER_ID")
|
17 |
|
|
|
|
|
|
|
18 |
def send_whatsapp_text(to: str, text: str) -> dict:
|
19 |
"""
|
20 |
Send a plain text message (max 4096 chars per WhatsApp limits).
|
|
|
29 |
"messaging_product": "whatsapp",
|
30 |
"to": to,
|
31 |
"type": "text",
|
32 |
+
"text": {"body": text[:4096]},
|
33 |
}
|
34 |
|
35 |
try:
|
|
|
39 |
except Exception as e:
|
40 |
return {"status": "failed", "error": str(e)}
|
41 |
|
|
|
|
|
|
|
42 |
async def nuse_interact(to: str, name: str, prompt: str) -> dict:
|
43 |
"""
|
44 |
1. Call ask_question() directly (no HTTP round-trip);
|
|
|
57 |
# 2) Send to WhatsApp
|
58 |
return send_whatsapp_text(to, answer_text)
|
59 |
|
|
|
|
|
|
|
60 |
@wa_router.get("/webhook")
|
61 |
async def verify_webhook(request: Request):
|
62 |
params = request.query_params
|
|
|
64 |
return PlainTextResponse(content=params.get("hub.challenge"))
|
65 |
return JSONResponse(status_code=403, content={"error": "Verification failed"})
|
66 |
|
|
|
|
|
|
|
67 |
@wa_router.post("/webhook")
|
68 |
async def receive_whatsapp_event(request: Request):
|
69 |
body = await request.json()
|