百度文心一言api接口调用使用教程,自媒体/网站优化批量改写文章可用

SEO教程2025-06-2444
    正在检查是否收录...

大家好,我是淘小白~

年前就有老客户需要写一个百度文心一言改写的软件,但是过年直接躺平了,年后抓紧给写出来了,通过百度文心一言可以改写文章,自媒体的洗稿可用。

网站优化也可以用,但是不推荐,免费调用很少,回报周期长,利润低的话不推荐使用文心一言改写。

这篇文章主要记录一下主要的几个方法和注意事项,避免自己忘记,如果文章对你有用,可以收藏一下,感谢大家~

1、百度文心一言的api 接口在千帆平台上;

2、代码语言:【Python】

3、千帆平台创建应用

网址:https://console.bce.baidu.com/qianfan/ais/console/applicationConsole/application

创建好应用之后,我们需要保存一下 API Key  和 Secret Key 这两个参数需要用来后去accesstoken

4、获取accesstoken

def GetAccessToken(APIKey, SecretKey): """ 使用 API Key,Secret Key 获取access_token,替换下列示例中的应用API Key、应用Secret Key 网址:https://console.bce.baidu.com/qianfan/ais/console/applicationConsole/application """ url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={}&client_secret={}".format( APIKey, SecretKey) 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")

5、请求接口方法

def GetBaiduAi(question, model_url, APIKey, SecretKey): try: url = "{}?access_token=".format(model_url) + GetAccessToken(APIKey, SecretKey) payload = json.dumps({ "temperature": 0.95, "top_p": 0.7, "system": '你是一名智能百科助手', "messages": [ { "role": "user", "content": question } ] }) headers = { 'Content-Type': 'application/json' } response = requests.request("POST", url, headers=headers, data=payload) content = response.text content = json.loads(content) resultContent = content["result"] return resultContent except Exception as e: print(e) return str(e)

6、常用的模型api请求网址

模型

调用网址

ERNIE-Bot 4.0大模型公有云在线调用服务

https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro

ERNIE-Bot-turbo-0922大模型公有云在线调用服务

https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant

ERNIE-Bot大模型公有云在线调用服务

https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro

 7、查询可以调用的模型

网址:百度智能云千帆大模型平台

百度文心一言的免费试用量很少,token价格:

 有需要调用api改写文章的朋友,可以联系作者,❤ TXB2196

如果文章对你有帮助,可以收藏一下哦~

apitokenbaidujsonappurl大模型百度文心botchat公有云cli写文章百度智能网站优化python免费试用baiduaistem自媒体