forked from colorfulandcjy0806/Arxiv-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sf.py
More file actions
25 lines (22 loc) · 724 Bytes
/
Copy pathtest_sf.py
File metadata and controls
25 lines (22 loc) · 724 Bytes
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
# test_sf.py 用于测试单个程序能否正确调用硅基流动的API
import os, requests
BASE = "https://api.siliconflow.cn"
MODEL = "Qwen/Qwen2.5-7B-Instruct"
KEY = os.getenv("OPENAI_COMPAT_API_KEY", "")
print("key prefix:", (KEY[:8] + "****") if KEY else "<EMPTY>")
payload = {
"model": MODEL,
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Say hello in one short sentence."}
],
"temperature": 0.2,
}
r = requests.post(
f"{BASE}/v1/chat/completions",
json=payload,
headers={"Authorization": f"Bearer {KEY}", "Content-Type": "application/json"},
timeout=30,
)
print("status:", r.status_code)
print(r.text)