-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_chat_endpoint.py
More file actions
65 lines (53 loc) · 1.94 KB
/
test_chat_endpoint.py
File metadata and controls
65 lines (53 loc) · 1.94 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
#!/usr/bin/env python3
"""Test the chat completions endpoint directly"""
import requests
import json
import urllib3
# Disable SSL warnings for testing
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def test_chat_endpoint():
"""Test the chat completions endpoint"""
url = "http://localhost:8443/v1/chat/completions"
headers = {
"Authorization": "Bearer demo-key",
"Content-Type": "application/json"
}
payload = {
"model": "gpt-3.5-turbo",
"messages": [
{"role": "user", "content": "Hello, can you hear me?"}
],
"max_tokens": 100
}
try:
print("Testing chat completions endpoint...")
print(f"URL: {url}")
print(f"Headers: {headers}")
print(f"Payload: {json.dumps(payload, indent=2)}")
print()
response = requests.post(url, headers=headers, json=payload, timeout=30)
print(f"Response Status: {response.status_code}")
print(f"Response Headers: {dict(response.headers)}")
print()
if response.status_code == 200:
result = response.json()
print("✅ SUCCESS - Response received:")
print(json.dumps(result, indent=2))
# Extract the response content
content = result.get('choices', [{}])[0].get('message', {}).get('content', '')
if content:
print(f"\nResponse Content: {content}")
return True
else:
print(f"❌ FAILED - Status: {response.status_code}")
print(f"Response: {response.text}")
return False
except requests.exceptions.ConnectionError as e:
print(f"❌ CONNECTION FAILED: {e}")
return False
except Exception as e:
print(f"❌ ERROR: {e}")
return False
if __name__ == "__main__":
success = test_chat_endpoint()
exit(0 if success else 1)