#!/usr/bin/env python3 """ Simple test to verify tool call fix is working. """ import requests import json import time def test_tool_call_fix(): """Test if tool call fix prevents the specific error.""" print("๐Ÿงช Simple Tool Call Fix Test") print("=" * 40) try: # Test with a simple ticker response = requests.get( 'http://localhost:8000/analyze/stream', params={'ticker': 'AAPL'}, stream=True, timeout=30 ) if response.status_code != 200: print(f"โŒ API error: {response.status_code}") return False print("โœ… API accessible") chunk_count = 0 tool_call_error_found = False # Read first 20 chunks to check for tool call errors for line in response.iter_lines(): if line and chunk_count < 20: try: decoded_line = line.decode('utf-8') if decoded_line.startswith('data: '): data = json.loads(decoded_line[6:]) chunk_count += 1 msg_type = data.get('type', 'unknown') print(f"๐Ÿ“ฆ Chunk {chunk_count}: {msg_type}") # Check for the specific tool call error if msg_type == 'error': error_msg = data.get('message', '') print(f"โŒ Error: {error_msg}") if 'tool_calls' in error_msg and 'must be followed by tool messages' in error_msg: print("โŒ TOOL CALL ERROR DETECTED - Fix failed!") tool_call_error_found = True break # If we get through some chunks without the error, the fix is working if chunk_count >= 15: break except Exception as e: print(f"โš ๏ธ Parse error: {e}") continue else: break if tool_call_error_found: print("โŒ RESULT: Tool call error still occurs") return False else: print("โœ… RESULT: No tool call errors detected in first 15 chunks") print(" Fix appears to be working!") return True except Exception as e: print(f"โŒ Test error: {e}") return False if __name__ == "__main__": success = test_tool_call_fix() print(f"\n{'๐ŸŽ‰ PASS' if success else '๐Ÿ’ฅ FAIL'}")