文心一言v2接口配置教程

1 获取自已的key

https://console.bce.baidu.com/iam/#/iam/apikey/list

 

2 查看你要模型

查看模型列表:https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Wm9cvy6rl
 

3 修改插件文件

你要修改参数

 

<?php
if(!defined('IN_DISCUZ')) {
    exit('Access Denied');
}


class engine {
    
    
    //新版接口
    public function buildArticle($content) {

        
        $model = '你要的模型';//例:ernie-3.5-8k  ,查看模型列表:https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Wm9cvy6rl
        $key = '你的key'; //例:bce-v3/ALTAK-HGroNwcWpO4FXyGSvHGXo/02cae076f26cdd670fbe9b69ed824d4c8a0b 你的key

        $postData = array('messages'=>array(array('role'=>'user','content'=>$content)),'stream'=>false);
        $postData = [
            'model'=>$model, //模型
            'messages'=>[
                [
                    "role"=>"user",
                    "content"=> $content
                ]
            ],
            'stream'=>false
        ];
        
        
        $postData = json_encode($postData);


        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => "https://qianfan.baidubce.com/v2/chat/completions",
            CURLOPT_TIMEOUT => 30,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER  => false,
            CURLOPT_SSL_VERIFYHOST  => false,
            CURLOPT_CUSTOMREQUEST => 'POST',
            
            CURLOPT_POSTFIELDS =>$postData,
    
            CURLOPT_HTTPHEADER => array(
                'Content-Type: application/json',
                'appid: ',
                'Authorization: Bearer '.$key
            ),

        ));
        $response = curl_exec($curl);
        curl_close($curl);

        
        $response = json_decode($response,true);

        if(isset($response['error'])){
            die(json_encode(['sta'=>0,'msg'=>json_encode($response['error'])]));
        }
        
        return $response['choices'][0]['message']['content'];
    }

    
}

?>

 

将上面代码,替换文件:source/plugin/bphp_ai/engine.class.php

 

 

 

 
posted @ 2025-05-31 00:15  我是谁,我在做什么  阅读(51)  评论(0)    收藏  举报