36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
|
import requests
|
||
|
import json
|
||
|
|
||
|
|
||
|
|
||
|
def send_request(session, data):
|
||
|
url = "https://api.mixrai.com/v1/chat/completions"
|
||
|
|
||
|
try:
|
||
|
headers = {
|
||
|
"Accept": "application/json",
|
||
|
"Authorization":"sk-QxlvoGgkYT1idnvP129595EdA4324330A84f441b58A7E478",
|
||
|
"User-Agent": "Apifox/1.0.0 (https://apifox.com)",
|
||
|
"Content-Type": "application/json",
|
||
|
}
|
||
|
|
||
|
response = session.post(url, json=data, headers=headers)
|
||
|
response.raise_for_status()
|
||
|
result = response.json()
|
||
|
response_text = result["choices"][0]["message"]["content"]
|
||
|
except requests.exceptions.RequestException as e:
|
||
|
print(f"请求失败: {e}")
|
||
|
response_text = "抱歉,我现在太忙了,休息一会,请稍后再试。"
|
||
|
return response_text
|
||
|
|
||
|
messages=[{"role": "system", "content": "你好"}]
|
||
|
data = {
|
||
|
"model": "gpt-3.5-turbo",
|
||
|
"messages": messages,
|
||
|
"temperature": 0.3,
|
||
|
"max_tokens": 2000,
|
||
|
"user": f"user_0"
|
||
|
}
|
||
|
session = requests.Session()
|
||
|
session.verify = False
|
||
|
print(send_request(session,data))
|