PyGetGPT/src/Server/qwenTurbo.py

32 lines
944 B
Python

import requests , json
# 设置请求的目标URL
url = "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation" # 替换为你的API端点URL
header = {
"Content-Type":"application/json",
"Authorization":"Bearer sk-69129a5d7fc6468a9f6f30d6935254c6"
}
def service(prompt,history = ""):
# 设置请求数据
if history == "":
data = {
"model": "qwen-turbo",
"input":{
"prompt":f"{prompt}"
}
}
else:
data = {
"model": "qwen-turbo",
"input":{
"prompt":f"{prompt}",
"history":history
}
}
# 发送POST请求
response = json.loads(requests.post(url, json=data ,headers=header).text)
if 'code' in response:
return 50,response['code']+response['message'],0
return 200,response['output']['text'],response["usage"]["total_tokens"]