登錄百度智能云:百度智能云
文心一言4.0使用
開(kāi)通付費(fèi):
創(chuàng)建應(yīng)用:
自行創(chuàng)建應(yīng)用名稱:
對(duì)話測(cè)試:
API測(cè)試
ERNIE-Bot-4 API:ERNIE-Bot-4
打開(kāi)鏈接查看自己的API Key,Secret Key。
可參考:API在線調(diào)試介紹
找到示例代碼即可:
import requests
import json
def get_access_token():
"""
使用 API Key,Secret Key 獲取access_token,替換下列示例中的應(yīng)用API Key、應(yīng)用Secret Key
"""
url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=[應(yīng)用API Key]&client_secret=[應(yīng)用Secret Key]"
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")
def main():
url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro?access_token=" + get_access_token()
payload = json.dumps({
"messages": [
{
"role": "user",
"content": "介紹一下你自己"
}
]
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
if __name__ == '__main__':
main()
其中,[應(yīng)用API Key]和[應(yīng)用Secret Key]分別復(fù)制client_id和client_secret,注意是完整字符,不帶*。
在PyCharm中即可看到文本回復(fù):
{
“id”:“as-xzha01438e”,
“object”:“chat.completion”,
“created”:1698112809,
“result”:“我的大模型版本是文心一言,英文名是ERNIE Bot,是基于百度文心大模型技術(shù)推出的生成式對(duì)話產(chǎn)品。百度文心大模型是百度自主研發(fā)的產(chǎn)業(yè)級(jí)知識(shí)增強(qiáng)大模型,既包含基礎(chǔ)通用的大模型,也包含面向重點(diǎn)任務(wù)領(lǐng)域和行業(yè)的大模型,以及豐富的工具與平臺(tái),支撐企業(yè)與開(kāi)發(fā)者進(jìn)行高效便捷的應(yīng)用開(kāi)發(fā)。相比Chat GPT,文心一言更適用于中文語(yǔ)境?!?
“is_truncated”:false,
“need_clear_history”:false,
“usage”:{“prompt_tokens”:10,“completion_tokens”:140,“total_tokens”:150}文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-743838.html
}文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-743838.html
到了這里,關(guān)于百度文心一言4.0——使用及API測(cè)試的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!