|
|
| import asyncio |
| import httpx |
| import sys |
| import uuid |
|
|
| |
| TARGET_URL = "http://localhost:8000/api/guvi/analyze" |
|
|
| async def run_simulation(): |
| session_id = f"LOCAL-SIM-{uuid.uuid4().hex[:6]}" |
| print(f"π STARTING LOCAL GUVI SIMULATION (Session: {session_id})") |
| print("ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ") |
| |
| |
| turns = [ |
| "Hello, who is this?", |
| "I received a message about my bank account locking.", |
| "Okay, I am ready to pay. Where do I send the money?" |
| ] |
| |
| history = [] |
| |
| async with httpx.AsyncClient(timeout=30.0) as client: |
| for i, text in enumerate(turns): |
| print(f"\nπ€ Sending Turn {i+1}/3: '{text}'") |
| |
| payload = { |
| "sessionId": session_id, |
| "message": { |
| "text": text, |
| "sender": "user" |
| }, |
| "conversationHistory": history, |
| "metadata": {"source": "local_sim"} |
| } |
| |
| try: |
| resp = await client.post(TARGET_URL, json=payload) |
| if resp.status_code == 200: |
| data = resp.json() |
| reply = data.get("reply", "No reply") |
| metrics = data.get("engagementMetrics", {}) |
| |
| print(f"β
Response {i+1}: '{reply[:50]}...'") |
| print(f" Metrics: {metrics.get('totalMessagesExchanged', 0)} msgs, {metrics.get('engagementDurationSeconds', 0)}s") |
| |
| |
| history.append({"text": text, "sender": "user"}) |
| history.append({"text": reply, "sender": "bot"}) |
| |
| |
| if i == 2: |
| print("\nπ Verifying Callback Trigger (Turn 3/3)...") |
| if metrics.get('totalMessagesExchanged', 0) >= 6: |
| print("β
SUCCESS: Message count >= 6. Callback should fire in server logs.") |
| else: |
| print("β FAILURE: Message count < 6.") |
| else: |
| print(f"β Error {resp.status_code}: {resp.text}") |
| |
| except Exception as e: |
| print(f"β οΈ Request Failed: {e}") |
| break |
| |
| print("\nπ Simulation Complete. Check server logs for '[GUVI] Final callback sent'.") |
|
|
| if __name__ == "__main__": |
| try: |
| asyncio.run(run_simulation()) |
| except KeyboardInterrupt: |
| pass |
|
|