creativesar/taskflow
0
1"""2Test chat API endpoint with OpenRouter and token limits3"""4import asyncio5import os6from dotenv import load_dotenv7 8load_dotenv()9 10async def test_chat_endpoint():11 """Test the actual chat endpoint that will be used by frontend"""12 from agent import run_agent13 14 print("[TEST] Testing Chat API with OpenRouter (Token Limit: 1000)")15 print(f"[MODEL] {os.getenv('AI_MODEL')}")16 print(f"[MAX_TOKENS] {os.getenv('MAX_TOKENS')}")17 print()18 19 # Simulate a real user conversation20 conversation = []21 22 # Test 1: Simple greeting23 print("[TEST 1] Simple greeting...")24 result = await run_agent("Hello, can you help me manage my tasks?", conversation)25 26 if result["error"]:27 print(f"[FAILED] {result['error']}")28 return False29 30 print(f"[SUCCESS] {result['response'][:100]}...")31 conversation.append({"role": "user", "content": "Hello, can you help me manage my tasks?"})32 conversation.append({"role": "assistant", "content": result['response']})33 print()34 35 # Test 2: Add task (will trigger tool call)36 print("[TEST 2] Add task command...")37 result = await run_agent("Add a task: Buy groceries", conversation)38 39 if result["error"]:40 if "402" in str(result["error"]):41 print(f"[FAILED] 402 Error still occurring: {result['error']}")42 return False43 print(f"[FAILED] {result['error']}")44 return False45 46 print(f"[SUCCESS] {result['response'][:100]}...")47 print(f"[TOOLS] {len(result['tool_calls'])} tool(s) called")48 print()49 50 # Test 3: List tasks51 print("[TEST 3] List tasks command...")52 result = await run_agent("Show me my tasks", conversation)53 54 if result["error"]:55 if "402" in str(result["error"]):56 print(f"[FAILED] 402 Error still occurring: {result['error']}")57 return False58 print(f"[FAILED] {result['error']}")59 return False60 61 print(f"[SUCCESS] {result['response'][:100]}...")62 print()63 64 print("[ALL TESTS PASSED] No 402 errors! Token limits working correctly.")65 return True66 67if __name__ == "__main__":68 success = asyncio.run(test_chat_endpoint())69 exit(0 if success else 1)70 