|
""" |
|
curl -X GET http://localhost:7680/api/models |
|
|
|
curl -X POST https://sanbo1200-degpt.hf.space/hf/v1/chat/completions \ |
|
-H "Content-Type: application/json" \ |
|
-d '{ |
|
"model": "Qwen2.5-72B", |
|
"messages": [ |
|
{"role": "system", "content": "You are a helpful assistant."}, |
|
{"role": "user", "content": "你是什么模型,你有什么特点?"} |
|
] |
|
}' |
|
|
|
|
|
""" |
|
import requests |
|
|
|
|
|
url = 'https://sanbo1200-degpt.hf.space/hf/v1/chat/completions' |
|
|
|
|
|
headers = { |
|
|
|
'Content-Type': 'application/json', |
|
} |
|
|
|
|
|
data = { |
|
'model': 'gpt-4o', |
|
'messages': [ |
|
{'role': 'user', 'content': '你好,你是谁?'}, |
|
], |
|
'max_tokens': 100, |
|
} |
|
|
|
|
|
response = requests.post(url, headers=headers, json=data) |
|
|
|
|
|
if response.status_code == 200: |
|
|
|
|
|
response_data = response.json() |
|
|
|
generated_text = response_data['choices'][0]['message']['content'] |
|
print('ChatGPT 的回复:', generated_text) |
|
else: |
|
print('请求失败,状态码:', response.status_code) |
|
print('错误信息:', response.text) |