forked from formzs/poe-to-gpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_api.py
50 lines (44 loc) · 1.38 KB
/
test_api.py
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
import requests
import json
import os
# API endpoint
url = "http://localhost:8000/v1/chat/completions"
# Get access token from environment variable
access_token = os.getenv("ACCESS_TOKEN", "your-access-token-here")
# Request headers
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {access_token}"
}
# Request body with more parameters
data = {
"model": "gpt-3.5-turbo",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello! How are you?"}
],
"stream": True,
"temperature": 0.7,
"skip_system_prompt": False,
"frequency_penalty": 0.0,
"presence_penalty": 0.0,
"stop_sequences": ["stop"],
"logit_bias": {"50256": -100} # 示例logit_bias
}
# Make the request
try:
response = requests.post(url, headers=headers, json=data)
print(f"Status Code: {response.status_code}")
print("Response Headers:")
print(json.dumps(dict(response.headers), indent=2))
print("\nResponse Body:")
if response.headers.get("content-type") == "text/event-stream":
# Handle streaming response
for line in response.iter_lines():
if line:
print(line.decode('utf-8'))
else:
# Handle regular JSON response
print(json.dumps(response.json(), indent=2))
except Exception as e:
print(f"Error: {e}")