39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
import httpx
|
|
import asyncio
|
|
|
|
|
|
async def test():
|
|
url = "https://coding.dashscope.aliyuncs.com/v1/chat/completions"
|
|
headers = {
|
|
"Authorization": "Bearer sk-sp-c76f198d1b2840c5b5a58dfd4c0cd218",
|
|
"Content-Type": "application/json"
|
|
}
|
|
payload = {
|
|
"model": "qwen3-coder-plus",
|
|
"messages": [{"role": "user", "content": "你好,请用一句话确认连接正常"}],
|
|
"max_tokens": 100
|
|
}
|
|
async with httpx.AsyncClient(timeout=30) as client:
|
|
resp = await client.post(url, json=payload, headers=headers)
|
|
print(f"Status: {resp.status_code}")
|
|
if resp.status_code == 200:
|
|
data = resp.json()
|
|
print(f"Model: {data['model']}")
|
|
print(f"Content: {data['choices'][0]['message']['content']}")
|
|
print("✅ 百炼 Coding Plan API 连通成功!")
|
|
else:
|
|
print(f"Error: {resp.text}")
|
|
# 如果 qwen3-coder-plus 不行,尝试其他模型
|
|
for model in ["qwen3.5-plus", "qwen3-coder-next", "qwen3-max-2026-01-23"]:
|
|
payload["model"] = model
|
|
resp2 = await client.post(url, json=payload, headers=headers)
|
|
print(f"\nTrying {model}: Status {resp2.status_code}")
|
|
if resp2.status_code == 200:
|
|
data = resp2.json()
|
|
print(f"✅ {model} works! Content: {data['choices'][0]['message']['content']}")
|
|
break
|
|
else:
|
|
print(f"Error: {resp2.text[:200]}")
|
|
|
|
asyncio.run(test())
|