https://console.bce.baidu.com/qianfan/overview)
import requests
import json
def main():
url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=替换为自己的AK&client_secret=替换为自己的SK"
payload = ""
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
items = json.loads(response.text)
return items["access_token"]
if __name__ == '__main__':
access_token = main()
content = "成考时间线"
url = f"https://aip.baidubce.com/rest/2.0/wenxinworkshop/api/v1/template/info?access_token={access_token}&id=2174&content={content}"
payload = ""
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
response = requests.request("GET", url, headers=headers)
print(response.text)
ret = json.loads(response.text)["result"]["content"]
url_content = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token=" + access_token
payload = json.dumps({
"messages": [
{
"role": "user",
"content": ret
}
]
})
headers = {
'Content-Type': 'application/json'
}
resp= requests.request("POST", url_content, headers=headers, data=payload)
print(resp.text)
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/274170.html