Logga in

AIGC:把百度的文心千帆大模型整合进wordpress,并对比GPT

Författare:neo yang Tid:2023/07/26 Läsa: 5988

# 把百度的文心千帆大模型整合进wordpress,并对比GPT

上周末,把百度的文心千帆大模型整合进了wordpress。
一、基本的过程:
1、先在百度申请体验文心千帆大模型,需要先认证。

2、通过后,开通一下大模型,因为百度的大模型使用是收费的,按token收费,需要你的账户中有余额才能开通。

3、然后,创建一个应用,这样就有了appid、api key和secret key

4、然后,再看文档,接相应的接口。
基本就是通过api key和secret key获得access token,然后再提交问题,获取答案。

二、关键代码
1、获取access token的关键代码

“`php
private function getAccessToken(){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => “https://aip.baidubce.com/oauth/2.0/token?client_id=”.$this->client_id.”&client_secret=”.$this->client_secret.”&grant_type=client_credentials”,
CURLOPT_TIMEOUT => 30,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => ‘POST’,
CURLOPT_HTTPHEADER => array(
‘Content-Type: application/json’,
‘Accept: application/json’
),

));
$response = curl_exec($curl);
curl_close($curl);
$rtn = json_decode($response);
return $rtn->access_token;
}
“`

2、调用Ernie Bot大模型的关键代码

“`php
public function runErnieBot($message) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => “https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions?access_token={$this->getAccessToken()}”,
CURLOPT_TIMEOUT => 30,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => ‘POST’,
CURLOPT_POSTFIELDS =>$message,
CURLOPT_HTTPHEADER => array(
‘Content-Type: application/json’
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
“`

3、调用Ernie Bot Turbo大模型的关键代码

“`php
public function runErnieBotTurbo($message) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => “https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token={$this->getAccessToken()}”,
CURLOPT_TIMEOUT => 30,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => ‘POST’,
CURLOPT_POSTFIELDS =>$message,
CURLOPT_HTTPHEADER => array(
‘Content-Type: application/json’
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
“`

这几天的测试,百度文心千帆大模型在中文方面的表现的确比GPT好多了。
GPT的中文水平,就是“说明文”的水平。
百度文心千帆大模型的中文水平,至少也比“说明文”好一些。

taggar: , , ,


copyright © www.lyustu.com alla rättigheter reserverade.
Tema: TheMoon V3.0 Författare:neo yang