#!/usr/bin/env python3 """ Test script to verify non-streaming responses work correctly. """ import os import json import requests # Set debug mode os.environ['DEBUG_MODE'] = 'true' def test_non_streaming(): """Test that non-streaming responses work correctly.""" print("๐Ÿงช Testing non-streaming response...") # Simple request with streaming disabled request_data = { "model": "claude-3-7-sonnet-20250219", "messages": [ { "role": "user", "content": "What is 2+2?" } ], "stream": False, "temperature": 0.0 } try: # Send non-streaming request response = requests.post( "http://localhost:8000/v1/chat/completions", json=request_data, timeout=30 ) print(f"โœ… Response status: {response.status_code}") if response.status_code != 200: print(f"โŒ Request failed: {response.text}") return False # Parse response data = response.json() # Check response structure if 'choices' in data and len(data['choices']) > 0: message = data['choices'][0]['message'] content = message['content'] print(f"๐Ÿ“Š Response content: {content}") # Check if we got actual content instead of fallback message fallback_messages = [ "I'm unable to provide a response at the moment", "I understand you're testing the system" ] is_fallback = any(msg in content for msg in fallback_messages) if not is_fallback and len(content) > 0: print("\n๐ŸŽ‰ Non-streaming response is working!") print("โœ… Real content extracted successfully") return True else: print("\nโŒ Non-streaming response is not working") print("โš ๏ธ Still receiving fallback content or no content") return False else: print("โŒ Unexpected response structure") return False except Exception as e: print(f"โŒ Test failed with exception: {e}") return False def main(): """Test non-streaming responses.""" print("๐Ÿ” Testing Non-Streaming Responses") print("=" * 50) success = test_non_streaming() print("\n" + "=" * 50) if success: print("๐ŸŽ‰ Non-streaming test PASSED!") print("โœ… Both streaming and non-streaming responses work correctly") else: print("โŒ Non-streaming test FAILED") print("โš ๏ธ Issue may still persist") return success if __name__ == "__main__": success = main() exit(0 if success else 1)