forked from ALTIbaba/claude-code-openai-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_non_streaming.py
More file actions
97 lines (78 loc) · 2.83 KB
/
Copy pathtest_non_streaming.py
File metadata and controls
97 lines (78 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/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)