|
|
@@ -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
|
}
|