[import requests
import json
def get_access_token():
url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=输入自己的id&client_secret=输入自己id的密码"
payload = json.dumps("")
headers = {"Content-Type": "application/json","Accept": "application/json"}
response = requests.request("POST",url,headers=headers,data=payload)
return response.json().get("access_token") #获取acces_token
def main():
url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions?access_token=" + get_access_token()
payload = json.dumps({"messages": [{"role": "user","content": "如何使用httpx?" }]}) #提问
headers = {"Content-Type": "application/json"}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
if name == "main":
main()]()