php和python调用百度文心一言大模型api笔记
首先注册百度开发者,然后开通大模型
地址:https://console.bce.baidu.com/qianfan/chargemanage/list
选择一个,每个模型都有调用的价格,不仅可以调用文心一言,还可以训练自己的模型。
下面我们创建一个应用获取key等参数:
https://console.bce.baidu.com/qianfan/ais/console/applicationConsole/application
记录一下apikey及secret
下面就能使用php调用了
<?php // API Key和Secret Key $app_id = '$app_id'; $api_key = '$api_key'; $secret_key = '$secret_key'; $url = 'https://aip.baidubce.com/oauth/2.0/token'; $params = array( 'grant_type' => 'client_credentials', 'client_id' => $api_key, 'client_secret' => $secret_key ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $result = json_decode($response, true); $access_token = $result[...
点击查看剩余70%
网友评论