文章目录
前言
我的第一个python对接文心一言开发程序
从注册API到调用API的过程
提示:以下是本篇文章正文内容,下面案例可供参考
一、注册百度千帆大模型平台
1、注册账号,注册时按个人或企业选择创建
地址:https://console.bce.baidu.com/qianfan/overview
2、创建应用
填写对应信息后确定即可
点击应用详情查看
API Key:和Secret Key,供后续调用使用
3、明确模型收费规则
找到计费管理,查看收费详情价格一栏,¥0元/千tokens 代表的是免费,后续调用可以调用免费的模型即可,其他功能模型详细信息请见API列表
我这里使用的是ERNIE-Speed-8K
二、Python调用模型
1、找到对应调用方法
API文档中心
2、查看默认调用文档
3、选择python对应方法
代码示例如下:(应用API Key、应用Secret Key请放自己的密钥)
import requests
import json
def get_access_token():
"""
使用 API Key,Secret Key 获取access_token,替换下列示例中的应用API Key、应用Secret Key
"""
url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=fEuMu12344448u9&client_secret=WYHqD123435yfINo7s"
payload = json.dumps("")
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
response = requests.request("POST", url,