|
1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #! /usr/bin/python
- import requests
- import json
-
- def do_request():
- url = "https://api.baichuan-ai.com/v1/chat/completions"
- api_key = "9f7d5847897f8090195cdc2c3249d0a7"
-
- data = {
- "model": "Baichuan2",
- "messages": [
- {
- "role": "user",
- "content": "世界第一高峰是"
- }
- ],
- "stream": True
- }
-
- json_data = json.dumps(data)
-
- headers = {
- "Content-Type": "application/json",
- "Authorization": "Bearer " + api_key
- }
-
- response = requests.post(url, data=json_data, headers=headers, timeout=60)
-
- if response.status_code == 200:
- print("请求成功!")
- print("响应body:", response.text)
- print("请求成功,X-BC-Request-Id:", response.headers.get("X-BC-Request-Id"))
- else:
- print("请求失败,状态码:", response.status_code)
- print("请求失败,body:", response.text)
- print("请求失败,X-BC-Request-Id:", response.headers.get("X-BC-Request-Id"))
-
- if __name__ == "__main__":
- do_request()
-
-
|