chengjie 4 months ago
parent
commit
747d629f60
3 changed files with 20 additions and 27 deletions
  1. 13 26
      src/api/yjbdc/aiController.js
  2. 3 0
      src/config/index.js
  3. 4 1
      src/util/constant/index.js

+ 13 - 26
src/api/yjbdc/aiController.js

@@ -297,36 +297,19 @@ class TencentHunyuanAIProvider extends AIProvider {
297 297
 /**
298 298
  * 百度文心一言平台实现
299 299
  */
300
+
300 301
 class BaiduAIProvider extends AIProvider {
301
-    constructor() {
302
+    constructor(model = 'deepseek-v3') {
302 303
         super();
303 304
         this.headers = {
305
+            "Authorization": "Bearer " + config.baiducloud.apikey,
304 306
             "Content-Type": "application/json"
305 307
         };
306
-        this.url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions";
307
-        this.model = "ernie-bot-4";
308
-        this.accessToken = null;
309
-    }
310
-
311
-    async getAccessToken() {
312
-        if (this.accessToken) return this.accessToken;
313
-        
314
-        const tokenUrl = `https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=${config.baidu.apiKey}&client_secret=${config.baidu.secretKey}`;
315
-        
316
-        try {
317
-            const response = await axios.post(tokenUrl);
318
-            this.accessToken = response.data.access_token;
319
-            return this.accessToken;
320
-        } catch (error) {
321
-            console.error("Baidu access token error:", error);
322
-            throw error;
323
-        }
308
+        this.url = 'https://qianfan.baidubce.com/v2/chat/completions';
309
+        this.model = model;
324 310
     }
325 311
 
326 312
     async generateArticle(content) {
327
-        const accessToken = await this.getAccessToken();
328
-        const apiUrl = `${this.url}?access_token=${accessToken}`;
329
-        
330 313
         const postJSON = {
331 314
             "model": this.model,
332 315
             "messages": [
@@ -338,15 +321,17 @@ class BaiduAIProvider extends AIProvider {
338 321
         };
339 322
 
340 323
         try {
341
-            const response = await axios.post(apiUrl, postJSON, { headers: this.headers });
342
-            return response.data.result;
324
+            console.log(`百度云${this.model}`);
325
+            const response = await axios.post(this.url, postJSON, { headers: this.headers });
326
+            return response.data.choices[0].message.content;
343 327
         } catch (error) {
344
-            console.error("Baidu AI API error:", error);
328
+            console.error("OpenAI API error:", error);
345 329
             throw error;
346 330
         }
347 331
     }
348 332
 }
349 333
 
334
+
350 335
 /**
351 336
  * AI提供者工厂类
352 337
  * 根据配置创建不同的AI平台实例
@@ -376,8 +361,10 @@ class AIProviderFactory {
376 361
                 return new XunFeiYunAIProvider();
377 362
             case 'tencent-hunyuan-turbos':
378 363
                 return new TencentHunyuanAIProvider();
379
-            case 'baidu':
364
+            case 'baidu-deepseek-v3':
380 365
                 return new BaiduAIProvider();
366
+            case 'baidu-deepseek-r1':
367
+                return new BaiduAIProvider("deepseek-r1");
381 368
             default:
382 369
                 return new VolcesAIProvider(providerLower); // 默认使用火山云1.5
383 370
         }

+ 3 - 0
src/config/index.js

@@ -83,6 +83,9 @@ const commonConfig = {
83 83
         apikeyCJ: "sk-12e38cdfe5b1477880e5c99efbd10b48",
84 84
         apikeyHLR:"sk-b3ea1a818aad4386b7f50133411fb6e8",
85 85
     },
86
+    baiducloud:{
87
+        apikey:"bce-v3/ALTAK-rJ28kWUiu2wE7AmSwCA6x/f7e1c801b6a569766add8f8e27223bafae158c32",
88
+    },
86 89
     xfyun:{
87 90
         appid: "620d2552", // 讯飞星火APPID
88 91
         apikey: "a3be608fe7fb367adae0169324faf3aa", // 讯飞星火APIKey

+ 4 - 1
src/util/constant/index.js

@@ -28,7 +28,10 @@ export default {
28 28
             {Version:"x1",BuildSecond:60,Model:"xf-yun-spark-x1",Content:"讯飞sparkX1\n平均60秒生成",CSS:""},
29 29
             {Version:"qwp",BuildSecond:30,Model:"ali-qwen-plus",Content:"通义千问plus\n平均30秒生成",CSS:""},
30 30
             {Version:"qwm",BuildSecond:45,Model:"ali-qwen-plus",Content:"通义千问Max\n平均45秒生成",CSS:""},
31
-            {Version:"hyt",BuildSecond:30,Model:"tencent-hunyuan-turbos",Content:"腾讯混元turbos\n平均30秒生成",CSS:""}];
31
+            {Version:"hyt",BuildSecond:30,Model:"tencent-hunyuan-turbos",Content:"腾讯混元turbos\n平均30秒生成",CSS:""},
32
+            {Version:"bd3",BuildSecond:30,Model:"baidu-deepseek-v3",Content:"百度deepseek_v3\n平均30秒生成",CSS:""},
33
+            {Version:"bdr",BuildSecond:60,Model:"baidu-deepseek-r1",Content:"百度deepseek_r1\n平均60秒生成",CSS:""},
34
+        ];
32 35
 
33 36
         return result;
34 37
     },