Skip to content

Commit f71c25f

Browse files
committed
update:增加讯飞星火 Spark4.0 Ultra
1 parent a10df0b commit f71c25f

File tree

10 files changed

+172
-20
lines changed

10 files changed

+172
-20
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ nodejs作为服务端的drpy实现。全面升级异步写法
1919
更新至V1.0.26
2020

2121
1. 设置中心优化,样式适配装逼壳。并支持全局站源动作
22+
2. 新增AI动作交互,用设置中心的连续对话即可测试
2223

2324
[点此查看完整更新记录](docs/updateRecord.md)
2425

@@ -45,6 +46,8 @@ todo:
4546
* [crypto-js-wasm使用教程](docs/crypto-js-wasm/readme-CN.md)
4647
* [puppeteer使用教程](docs/pupInstall.md)
4748
* [drpyS源属性说明](docs/ruleAttr.md)
49+
* [讯飞星火开放平台](https://console.xfyun.cn/services/bm4)
50+
* [讯飞星火智能体数据集](https://xinghuo.xfyun.cn/botcenter/private-dataset)
4851

4952
## 问题说明
5053

custom.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"more": {
1313
"sourceTag": "设置,动作",
1414
"actions": [
15+
{
16+
"name": "连续对话",
17+
"action": "{\"actionId\":\"连续对话\",\"id\":\"talk\",\"type\":\"input\",\"title\":\"连续对话\",\"tip\":\"请输入消息\",\"value\":\"\",\"msg\":\"开始新的对话\",\"button\":3,\"imageUrl\":\"https://img2.baidu.com/it/u=1206278833,3265480730&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800\",\"imageHeight\":200,\"imageType\":\"card_pic_3\",\"keep\":true}"
18+
},
1519
{
1620
"name": "查看夸克cookie",
1721
"action": "查看夸克cookie"

docs/updateRecord.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,38 @@
99
简体转繁体: `simplecc("发财了去植发", "s2t")`
1010
繁体转简体: `simplecc("發財了去植髮", "t2s")`
1111
3. 增加源相互调用功能,仅支持在源的特定函数里使用,示例:
12+
1213
```javascript
1314
let {proxyUrl, getRule} = this;
1415
const tx_rule = await getRule('腾云驾雾[官]');
1516
if (tx_rule) {
16-
log(tx_rule.url);
17-
log(tx_rule.title);
18-
// log(JSON.stringify(tx_rule));
19-
let data1 = await tx_rule.callRuleFn('搜索', ['斗罗大陆'])
20-
log(data1);
21-
let data2 = await tx_rule.callRuleFn('一级', ['tv'])
22-
log(data2);
23-
}else{
24-
log('没有这个原')
17+
log(tx_rule.url);
18+
log(tx_rule.title);
19+
// log(JSON.stringify(tx_rule));
20+
let data1 = await tx_rule.callRuleFn('搜索', ['斗罗大陆'])
21+
log(data1);
22+
let data2 = await tx_rule.callRuleFn('一级', ['tv'])
23+
log(data2);
24+
} else {
25+
log('没有这个原')
2526
}
2627
```
2728

29+
4. 增加讯飞星火AI对话交互动作,设置中心推荐栏可用。 源里可使用这个对象 `SparkAI`,调用示例:
30+
```javascript
31+
const sparkAI = new SparkAI({
32+
authKey: ENV.get('spark_ai_authKey'),
33+
baseURL: 'https://spark-api-open.xf-yun.com',
34+
});
35+
rule.askLock = 1;
36+
try {
37+
replyContent = await sparkAI.ask(prompt, {temperature: 1.0});
38+
} catch (error) {
39+
replyContent = error.message;
40+
}
41+
rule.askLock = 0;
42+
```
43+
2844
### 20241229
2945

3046
更新至V1.0.25

index.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"more": {
1313
"sourceTag": "设置,动作",
1414
"actions": [
15+
{
16+
"name": "连续对话",
17+
"action": "{\"actionId\":\"连续对话\",\"id\":\"talk\",\"type\":\"input\",\"title\":\"连续对话\",\"tip\":\"请输入消息\",\"value\":\"\",\"msg\":\"开始新的对话\",\"button\":3,\"imageUrl\":\"https://img2.baidu.com/it/u=1206278833,3265480730&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800\",\"imageHeight\":200,\"imageType\":\"card_pic_3\",\"keep\":true}"
18+
},
1519
{
1620
"name": "查看夸克cookie",
1721
"action": "查看夸克cookie"

js/_fq3.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ const rule = {
9191
log('proxyUrl:', proxyUrl);
9292
log('type of getRule:', typeof getRule);
9393
// test_rc4()
94+
95+
const sparkAI = new SparkAI({
96+
authKey: '12', // 替换为你的鉴权信息
97+
baseURL: 'https://spark-api-open.xf-yun.com',
98+
});
99+
100+
try {
101+
const prompt = '你好,今天的天气怎么样?';
102+
const answer = await sparkAI.ask(prompt, {temperature: 0.7});
103+
console.log('AI 回复:', answer);
104+
} catch (error) {
105+
console.error('调用失败:', error.message);
106+
}
107+
108+
/*
94109
const tx_rule = await getRule('腾云驾雾[官]');
95110
if (tx_rule) {
96111
log(tx_rule.url);
@@ -103,6 +118,9 @@ const rule = {
103118
} else {
104119
log('没有这个原')
105120
}
121+
122+
*/
123+
106124
/*
107125
(async ()=>{
108126
for (let i = 1; i <= 100; i++) {

js/_lib.action.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const action_data = [
99
value: '',
1010
msg: '开始新的对话',
1111
button: 3,
12-
imageUrl: 'https://pic.imgdb.cn/item/667ce9f4d9c307b7e9f9d052.webp',
12+
imageUrl: 'https://img2.baidu.com/it/u=1206278833,3265480730&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800',
1313
imageHeight: 200,
1414
imageType: 'card_pic_3',
1515
keep: true,

js/设置中心.js

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ var rule = {
1717
let {publicUrl} = this;
1818
// log('publicUrl:', publicUrl);
1919
let setIcon = urljoin(publicUrl, './images/icon_cookie/设置.png');
20+
let chatIcon = urljoin(publicUrl, './images/icon_cookie/chat.webp');
2021
action_data.forEach(it => {
2122
if (!it.vod_pic) {
2223
it.vod_pic = setIcon;
2324
}
24-
})
25+
if (it.vod_name === '连续对话') {
26+
it.vod_pic = chatIcon;
27+
}
28+
});
2529
return action_data;
2630
},
2731
类型: '设置',
@@ -34,6 +38,22 @@ var rule = {
3438
more: {
3539
sourceTag: '设置,动作',
3640
actions: [
41+
{
42+
name: '连续对话', action: JSON.stringify({
43+
actionId: '连续对话',
44+
id: 'talk',
45+
type: 'input',
46+
title: '连续对话',
47+
tip: '请输入消息',
48+
value: '',
49+
msg: '开始新的对话',
50+
button: 3,
51+
imageUrl: 'https://img2.baidu.com/it/u=1206278833,3265480730&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800',
52+
imageHeight: 200,
53+
imageType: 'card_pic_3',
54+
keep: true,
55+
})
56+
},
3757
{name: '查看夸克cookie', action: '查看夸克cookie'},
3858
{name: '设置夸克cookie', action: '设置夸克cookie'},
3959
{name: '夸克扫码', action: '夸克扫码'},
@@ -210,6 +230,8 @@ var rule = {
210230
d.push(getInput('get_hide_adult', '查看青少年模式', images.settings));
211231
d.push(genMultiInput('thread', '设置播放代理线程数', '默认为1,可自行配置成其他值如:10', images.settings));
212232
d.push(getInput('get_thread', '查看播放代理线程数', images.settings));
233+
d.push(genMultiInput('spark_ai_authKey', '设置讯飞AI鉴权', '在这个页面的http鉴权信息:https://console.xfyun.cn/services/bm4', images.settings));
234+
d.push(getInput('get_spark_ai_authKey', '查看讯飞AI鉴权', images.settings));
213235
break;
214236
case 'test':
215237
d.push({
@@ -281,26 +303,61 @@ var rule = {
281303

282304
if (action === '连续对话') {
283305
let content = JSON.parse(value);
284-
try {
285-
a = b;
286-
} catch (e) {
287-
console.error('测试出错捕获:', e);
306+
let prompt = content.talk.trim();
307+
if (!prompt) {
308+
return JSON.stringify({
309+
action: {
310+
actionId: '__keep__',
311+
},
312+
toast: '输入内容不可以为空哦~'
313+
});
314+
// return '输入内容不可以为空哦~'
288315
}
289-
console.error('对象日志测试:', 0, '==== ', content, ' ====', true);
290-
if (content.talk.indexOf('http') > -1) {
316+
// try {
317+
// a = b;
318+
// } catch (e) {
319+
// console.error('测试出错捕获:', e);
320+
// }
321+
// console.error('对象日志测试:', 0, '==== ', content, ' ====', true);
322+
323+
if (prompt.startsWith('http')) {
291324
return JSON.stringify({
292325
action: {
293326
actionId: '__detail__',
294327
skey: 'push_agent',
295-
ids: content.talk,
328+
ids: prompt,
296329
},
297330
toast: '你要去看视频了'
298331
});
299332
}
333+
let replyContent = prompt;
334+
if (ENV.get('spark_ai_authKey')) {
335+
if (rule.askLock) {
336+
return JSON.stringify({
337+
action: {
338+
actionId: '__keep__',
339+
msg: '请等待AI思考完成...',
340+
reset: false
341+
},
342+
toast: 'AI思考中,请稍候继续提问'
343+
});
344+
}
345+
const sparkAI = new SparkAI({
346+
authKey: ENV.get('spark_ai_authKey'),
347+
baseURL: 'https://spark-api-open.xf-yun.com',
348+
});
349+
rule.askLock = 1;
350+
try {
351+
replyContent = await sparkAI.ask(prompt, {temperature: 1.0});
352+
} catch (error) {
353+
replyContent = error.message;
354+
}
355+
rule.askLock = 0;
356+
}
300357
return JSON.stringify({
301358
action: {
302359
actionId: '__keep__',
303-
msg: '回音:' + content.talk,
360+
msg: '你:' + prompt + '\n' + 'AI:' + replyContent,
304361
reset: true
305362
},
306363
toast: '你有新的消息'
@@ -736,6 +793,7 @@ var rule = {
736793
'bili_cookie',
737794
'hide_adult',
738795
'thread',
796+
'spark_ai_authKey',
739797
];
740798
let get_cookie_sets = [
741799
'get_quark_cookie',
@@ -744,6 +802,7 @@ var rule = {
744802
'get_bili_cookie',
745803
'get_hide_adult',
746804
'get_thread',
805+
'get_spark_ai_authKey',
747806
];
748807
if (cookie_sets.includes(action) && value) {
749808
try {

libs/drpyS.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {existsSync, readFileSync} from 'fs';
33
import {fileURLToPath} from "url";
44
import {createRequire} from 'module';
55
import {XMLHttpRequest} from 'xmlhttprequest';
6-
import { simplecc } from "simplecc-wasm";
6+
import {simplecc} from "simplecc-wasm";
77
import path from "path";
88
import vm from 'vm';
99
import '../libs_drpy/es6-extend.js'
@@ -14,6 +14,7 @@ import {ENV} from '../utils/env.js';
1414
import {Quark} from "../utils/quark.js";
1515
import {UC} from "../utils/uc.js";
1616
import {Ali} from "../utils/ali.js";
17+
import SparkAI from '../utils/SparkAI.js';
1718
// const { req } = await import('../utils/req.js');
1819
import {gbkTool} from '../libs_drpy/gbk.js'
1920
// import {atob, btoa, base64Encode, base64Decode, md5} from "../libs_drpy/crypto-util.js";
@@ -49,6 +50,7 @@ globalThis.require = createRequire(import.meta.url);
4950
globalThis._fetch = fetch;
5051
globalThis.XMLHttpRequest = XMLHttpRequest;
5152
globalThis.simplecc = simplecc;
53+
globalThis.SparkAI = SparkAI;
5254
globalThis.pathLib = {
5355
basename: path.basename,
5456
extname: path.extname,
@@ -151,6 +153,7 @@ export async function getSandbox(env = {}) {
151153
_fetch,
152154
XMLHttpRequest,
153155
simplecc,
156+
SparkAI,
154157
batchFetch,
155158
JSProxyStream,
156159
JSFile,

public/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ <h3 id="20241230">20241230</h3>
2424
<p>更新至V1.0.26</p>
2525
<ol>
2626
<li>设置中心优化,样式适配装逼壳。并支持全局站源动作</li>
27+
<li>新增AI动作交互,用设置中心的连续对话即可测试</li>
2728
</ol>
2829
<p><a href="docs/updateRecord.md">点此查看完整更新记录</a></p>
2930
<h2 id="基础框架">基础框架</h2>
@@ -47,6 +48,8 @@ <h2 id="参考资料">参考资料</h2>
4748
<li><a href="docs/crypto-js-wasm/readme-CN.md">crypto-js-wasm使用教程</a></li>
4849
<li><a href="docs/pupInstall.md">puppeteer使用教程</a></li>
4950
<li><a href="docs/ruleAttr.md">drpyS源属性说明</a></li>
51+
<li><a href="https://console.xfyun.cn/services/bm4">讯飞星火开放平台</a></li>
52+
<li><a href="https://xinghuo.xfyun.cn/botcenter/private-dataset">讯飞星火智能体数据集</a></li>
5053
</ul>
5154
<h2 id="问题说明">问题说明</h2>
5255
<ol>

utils/SparkAI.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import axios from 'axios';
2+
3+
class SparkAI {
4+
constructor({authKey, baseURL}) {
5+
if (!authKey || !baseURL) {
6+
throw new Error('Missing required configuration parameters.');
7+
}
8+
this.authKey = authKey;
9+
this.baseURL = baseURL;
10+
}
11+
12+
async ask(prompt, options = {}) {
13+
const payload = {
14+
model: '4.0Ultra', // 使用的模型名称
15+
user: "道长",
16+
messages: [{role: 'user', content: prompt}],
17+
...options, // 其他选项,如 temperature、max_tokens 等
18+
};
19+
20+
try {
21+
const response = await axios.post(`${this.baseURL}/v1/chat/completions`, payload, {
22+
headers: {
23+
'Content-Type': 'application/json',
24+
Authorization: `Bearer ${this.authKey}`, // 使用鉴权信息
25+
},
26+
});
27+
28+
if (response.data && response.data.choices) {
29+
return response.data.choices[0].message.content;
30+
} else {
31+
throw new Error(
32+
`Error from Spark AI: ${response.data.error || 'Unknown error'}`
33+
);
34+
}
35+
} catch (error) {
36+
console.error('Error while communicating with Spark AI:', error.message);
37+
throw error;
38+
}
39+
}
40+
}
41+
42+
export default SparkAI;

0 commit comments

Comments
 (0)