import asyncio import httpx import sys import uuid # LOCAL TARGET 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("────────────────────────────────────────────────────────") # 3-Turn Sequence (User -> Bot -> User -> Bot -> User -> Bot) = 6 Messages 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") # Update History for next turn history.append({"text": text, "sender": "user"}) history.append({"text": reply, "sender": "bot"}) # Check for Callback Conditions 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