@3-/aiapi 0.1.72 → 0.1.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ import TYPE from '../TYPE.js';
2
+
3
+ export default {
4
+ type: TYPE.ARRAY,
5
+ description: '事实提取与命题化。将自然语言主张拆解为可独立验证的布尔命题元组,为后续网络搜索查证做准备(如果觉得不太可被搜索验证,不要列出来),如果事实不重要,不要列出来',
6
+ minItems: 0,
7
+ items: {
8
+ type: TYPE.OBJECT,
9
+ properties: {
10
+ 原句: {
11
+ type: TYPE.STRING,
12
+ description: '来源的原始文本片段(去除语气助词、优化语言转录的可读性)'
13
+ },
14
+ 实体: {
15
+ type: TYPE.STRING,
16
+ description: '命题的主体,必须是一个可以被明确搜索的关键词'
17
+ },
18
+ 宾语: {
19
+ type: TYPE.STRING,
20
+ description: '核心核查点,具体的金额、具体的份额等'
21
+ },
22
+ 命题: {
23
+ type: TYPE.STRING,
24
+ description: '完整的陈述句,必须是一个可以独立判定真伪的布尔命题'
25
+ },
26
+ 如何搜索: {
27
+ type: TYPE.STRING,
28
+ description: '如何通过谷歌搜索查证此命题的真伪'
29
+ },
30
+ 重要度: {
31
+ type: TYPE.INTEGER,
32
+ description: '0-10分,命题对于决策判断重要程度,分数越高越重要。有具体数字的内容,可以被搜索到的内容,会比较重要。竞争对手是谁创办的这种不重要。'
33
+ },
34
+ 可查性: {
35
+ type: TYPE.INTEGER,
36
+ description: '0-10分,命题是否可以通过互联网搜索验证,分数越高代表容易被搜索查证。0表示是公司内部数据,无法搜索被验证'
37
+ }
38
+ },
39
+ required: ['实体', '宾语', '命题', '如何搜索', '原句', '可查性']
40
+ }
41
+ };
@@ -0,0 +1,39 @@
1
+ import TYPE from '../TYPE.js';
2
+
3
+ export default {
4
+ type: TYPE.ARRAY,
5
+ description: '第二阶段:检索可行性判断 (Self-RAG 滤网)。对每个命题进行检索必要性打分和隐私判定。',
6
+ minItems: 1,
7
+ items: {
8
+ type: TYPE.OBJECT,
9
+ properties: {
10
+ 对应命题ID: {
11
+ type: TYPE.STRING,
12
+ description: '关联的第一阶段命题ID'
13
+ },
14
+ 检索必要性得分: {
15
+ type: TYPE.NUMBER,
16
+ description: '0-1之间的分数,分数越高代表越需要检索'
17
+ },
18
+ 隐私边界: {
19
+ type: TYPE.STRING,
20
+ description: '判定类别:可公开检索/半公开推论/内部隐私',
21
+ enum: ['可公开检索', '半公开推论', '内部隐私']
22
+ },
23
+ 数据类型: {
24
+ type: TYPE.STRING,
25
+ description: '数据性质:硬数据(法律/备案等)或 软数据(侧面印证/舆情)',
26
+ enum: ['硬数据', '软数据']
27
+ },
28
+ 是否需要尽调: {
29
+ type: TYPE.BOOLEAN,
30
+ description: '对于内部隐私或不可验证的数据,标记为True'
31
+ },
32
+ 推断逻辑: {
33
+ type: TYPE.STRING,
34
+ description: '简述判定的理由'
35
+ }
36
+ },
37
+ required: ['对应命题ID', '检索必要性得分', '隐私边界', '数据类型']
38
+ }
39
+ };
@@ -0,0 +1,57 @@
1
+ import TYPE from '../TYPE.js';
2
+
3
+ export default {
4
+ type: TYPE.ARRAY,
5
+ description: '第三阶段:规划与工具调用 (Agentic Workflow)。将自然语言主张转化为可执行的验证程序步骤。',
6
+ minItems: 1,
7
+ items: {
8
+ type: TYPE.OBJECT,
9
+ properties: {
10
+ 场景类型: {
11
+ type: TYPE.STRING,
12
+ description: '验证场景分类',
13
+ enum: ['数值验证', '逻辑验证', '负面排除', '其他']
14
+ },
15
+ 目标命题ID: {
16
+ type: TYPE.ARRAY,
17
+ description: '该计划覆盖的命题ID列表',
18
+ items: {
19
+ type: TYPE.STRING
20
+ }
21
+ },
22
+ SOTA策略: {
23
+ type: TYPE.STRING,
24
+ description: '使用的策略名称,如 HyDE, ReAct, Query Expansion'
25
+ },
26
+ 执行步骤: {
27
+ type: TYPE.ARRAY,
28
+ description: '具体的每一步执行动作',
29
+ items: {
30
+ type: TYPE.OBJECT,
31
+ properties: {
32
+ 步骤序号: {
33
+ type: TYPE.NUMBER
34
+ },
35
+ 步骤描述: {
36
+ type: TYPE.STRING,
37
+ description: '自然语言描述该步骤要做什么'
38
+ },
39
+ 搜索关键词: {
40
+ type: TYPE.ARRAY,
41
+ description: '生成的搜索Query列表',
42
+ items: {
43
+ type: TYPE.STRING
44
+ }
45
+ },
46
+ 预期动作: {
47
+ type: TYPE.STRING,
48
+ description: '执行的具体操作,如:提取Top5、对比数据、向量匹配'
49
+ }
50
+ },
51
+ required: ['步骤序号', '步骤描述', '搜索关键词']
52
+ }
53
+ }
54
+ },
55
+ required: ['场景类型', 'SOTA策略', '执行步骤']
56
+ }
57
+ };
@@ -0,0 +1,54 @@
1
+ import TYPE from '../TYPE.js';
2
+
3
+ export default {
4
+ type: TYPE.ARRAY,
5
+ description: '第四阶段:多源证据推理 (Multi-Hop Reasoning)。进行证据一致性校验与矛盾检测。',
6
+ minItems: 1,
7
+ items: {
8
+ type: TYPE.OBJECT,
9
+ properties: {
10
+ 对应命题ID: {
11
+ type: TYPE.STRING
12
+ },
13
+ 证据三角化状态: {
14
+ type: TYPE.STRING,
15
+ description: '证据的支持情况',
16
+ enum: ['直接支持', '直接反驳', '时间线矛盾', '数量级偏差', '证据缺失']
17
+ },
18
+ 证据来源: {
19
+ type: TYPE.ARRAY,
20
+ description: '引用的具体证据源',
21
+ items: {
22
+ type: TYPE.OBJECT,
23
+ properties: {
24
+ 来源名称: {
25
+ type: TYPE.STRING,
26
+ description: '来源标题或网站名'
27
+ },
28
+ 链接: {
29
+ type: TYPE.STRING,
30
+ description: 'URL链接'
31
+ },
32
+ 引文片段: {
33
+ type: TYPE.STRING,
34
+ description: '相关的原文片段'
35
+ }
36
+ }
37
+ }
38
+ },
39
+ 判定详情: {
40
+ type: TYPE.STRING,
41
+ description: '具体的判定理由,解释为何支持或反驳'
42
+ },
43
+ 时间线矛盾: {
44
+ type: TYPE.BOOLEAN,
45
+ description: '是否存在时间逻辑上的矛盾(如:成立前就拿订单)'
46
+ },
47
+ 数量级偏差: {
48
+ type: TYPE.BOOLEAN,
49
+ description: '是否存在数量级或定义的营销性夸大'
50
+ }
51
+ },
52
+ required: ['对应命题ID', '证据三角化状态', '判定详情']
53
+ }
54
+ };
@@ -0,0 +1,59 @@
1
+ import TYPE from '../TYPE.js';
2
+
3
+ export default {
4
+ type: TYPE.ARRAY,
5
+ description: '第五阶段:合成与对抗 (Adversarial Review)。引入红蓝军对抗,输出最终结论。',
6
+ minItems: 1,
7
+ items: {
8
+ type: TYPE.OBJECT,
9
+ properties: {
10
+ 对抗辩论: {
11
+ type: TYPE.OBJECT,
12
+ description: '红蓝军自我博弈记录',
13
+ properties: {
14
+ 律师陈述: {
15
+ type: TYPE.STRING,
16
+ description: 'Agent A (律师) 辩护词:尽力为创作者说法辩护,寻找合理解释'
17
+ },
18
+ 检察官陈述: {
19
+ type: TYPE.STRING,
20
+ description: 'Agent B (检察官) 控诉词:尽力寻找漏洞,攻击其真实性'
21
+ }
22
+ },
23
+ required: ['律师陈述', '检察官陈述']
24
+ },
25
+ 法官判决: {
26
+ type: TYPE.OBJECT,
27
+ description: 'Agent C (法官) 的最终裁决',
28
+ properties: {
29
+ 可信度评分: {
30
+ type: TYPE.NUMBER,
31
+ description: '0-100分,分数越高越可信'
32
+ },
33
+ 风险警示灯: {
34
+ type: TYPE.STRING,
35
+ description: '直观的风险等级',
36
+ enum: ['绿色-可靠', '黄色-警示', '红色-造假风险']
37
+ },
38
+ 风险提示报告: {
39
+ type: TYPE.STRING,
40
+ description: '详细的风险点分析'
41
+ },
42
+ 最终结论: {
43
+ type: TYPE.STRING,
44
+ description: '综合结论摘要'
45
+ },
46
+ 建议追问: {
47
+ type: TYPE.ARRAY,
48
+ description: '建议投资经理进一步核实的问题清单',
49
+ items: {
50
+ type: TYPE.STRING
51
+ }
52
+ }
53
+ },
54
+ required: ['可信度评分', '风险警示灯', '最终结论']
55
+ }
56
+ },
57
+ required: ['对抗辩论', '法官判决']
58
+ }
59
+ };
package/fmtJson.js CHANGED
@@ -3,15 +3,12 @@ import fmtSeg from './fmtSeg.js';
3
3
 
4
4
  import partition from './partition.js';
5
5
 
6
- import RmCnSpace from '@3-/rm_cn_space';
7
-
8
6
  export default async(chat, txt) => {
9
7
  var pli;
10
- if (!txt) {
8
+ pli = (await partition(chat, txt));
9
+ if (!pli.length) {
11
10
  return [];
12
11
  }
13
- txt = RmCnSpace(txt);
14
- pli = (await partition(chat, txt));
15
12
  return Promise.all(pli.map(async([title, li]) => {
16
13
  console.log('\n---\n→ ' + title + '\n' + li.join('\n') + '\n---\n');
17
14
  return [title, (await fmtSeg(chat, li.join('\n')))];
@@ -1,58 +1,32 @@
1
1
  #!/usr/bin/env -S node --trace-uncaught --expose-gc --unhandled-rejections=strict --experimental-wasm-modules
2
- var check;
2
+ import fmtSeg from './fmtSeg.js';
3
3
 
4
- import fmtJson from './fmtJson.js';
4
+ import partition from './partition.js';
5
5
 
6
- import fmtJsonMd from './fmtJsonMd.js';
6
+ import GEN_QA from './check/GEN_QA.js';
7
7
 
8
- import factCheck from './factCheck.js';
9
-
10
- import txtFmt from '@3-/txt_li/txtFmt.js';
11
-
12
- // @3-/read
13
- // @3-/write
14
- check = async(chat, json) => {
15
- var checked, j, k, li, n, tip, x, y, z, 答, 问, 问答;
16
- li = [];
17
- for (x of json) {
18
- ({问答} = x);
19
- for (y of 问答) {
20
- ({问, 答} = y);
21
- li.push(`问:${txtFmt(问)}\n答:${txtFmt(答)}`);
22
- }
8
+ export default async(chat, txt) => {
9
+ var pli;
10
+ pli = (await partition(chat, txt));
11
+ if (!pli.length) {
12
+ return [];
23
13
  }
24
- checked = (await factCheck(chat, li));
25
- n = 0;
26
- for (z of json) {
27
- ({问答} = z);
28
- for (j of 问答) {
29
- li = checked.get(++n);
30
- if (li) {
31
- for (k of li) {
32
- if (k.失实度 === '严重失实') {
33
- tip = '❗ 失实:';
34
- } else {
35
- tip = '⚠️';
36
- }
37
- j.答 += `\n#### ${tip} ${k.标题}
38
-
39
- 观点: ${k.观点}
40
-
41
- 事实: ${k.事实}`;
42
- }
14
+ return (await Promise.all(pli.map(async([title, li]) => {
15
+ var i, ref, t;
16
+ t = li.join('\n');
17
+ console.log('\n---\n→ ' + title + '\n' + t + '\n---\n');
18
+ ref = (await chat(t, GEN_QA, "请帮忙筛选出可以被搜索验证、影响决策的核心问题。如果是公司内部的数据、资料,不要列成搜索问题。如果搜索主体的名字不明确,不要列成问题。"));
19
+ for (i of ref) {
20
+ if (i.可查性 > 6 && i.重要度 > 6) {
21
+ console.log(i);
43
22
  }
44
23
  }
45
- }
24
+ })));
46
25
  };
47
26
 
48
- export default async(chat, txt) => {
49
- var json_li;
50
- json_li = (await fmtJson(chat, txt));
51
- // write('/tmp/chat.json', JSON.stringify(json_li))
52
- // json_li = JSON.parse read('/tmp/chat.json')
53
- // await check(chat, json_li[0])
54
- await Promise.all(json_li.map((i) => {
55
- return check(chat, i);
56
- }));
57
- return fmtJsonMd(json_li);
58
- };
27
+ // return Promise.all
28
+ // console.log '\n---\n→ '+title+'\n'+li.join('\n')+'\n---\n'
29
+ // [
30
+ // title
31
+ // await fmtSeg(chat, li.join('\n'))
32
+ // ]
package/gemini.js CHANGED
@@ -3,8 +3,8 @@ import sleep from '@3-/sleep';
3
3
 
4
4
  import merge from 'lodash-es/merge.js';
5
5
 
6
- // model='gemini-3-flash-preview'
7
- export default (token_li, model = 'gemini-3-pro-preview') => { // model='gemini-2.5-pro'
6
+ export default (token_li, model = 'gemini-3-flash-preview') => { // model='gemini-3-pro-preview'
7
+ // model='gemini-2.5-pro'
8
8
  var _NEXT_TOKEN, _nextToken, generate_content_url, nextToken;
9
9
  generate_content_url = 'https://generativelanguage.googleapis.com/v1beta/models/' + model + ':generateContent';
10
10
  token_li.sort(() => {
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@3-/aiapi","version":"0.1.72","repository":{"type":"git","url":"git+https://atomgit.com/i18n/lib.git"},"homepage":"https://atomgit.com/i18n/lib/tree/dev/aiapi","author":"i18n.site@gmail.com","license":"MulanPSL-2.0","exports":{".":"./lib.js","./*":"./*"},"files":["./*"],"devDependencies":{"@3-/read":"^0.1.4"},"scripts":{},"type":"module","dependencies":{"@3-/retry":"^0.0.2","@3-/rm_cn_space":"^0.1.1","@3-/sleep":"^0.0.4","@3-/txt_li":"^0.1.5","@3-/utf8":"^0.0.4","lodash-es":"^4.17.21"}}
1
+ {"name":"@3-/aiapi","version":"0.1.76","repository":{"type":"git","url":"git+https://atomgit.com/i18n/lib.git"},"homepage":"https://atomgit.com/i18n/lib/tree/dev/aiapi","author":"i18n.site@gmail.com","license":"MulanPSL-2.0","exports":{".":"./lib.js","./*":"./*"},"files":["./*"],"devDependencies":{"@3-/read":"^0.1.4"},"scripts":{},"type":"module","dependencies":{"@3-/retry":"^0.0.2","@3-/rm_cn_space":"^0.1.1","@3-/sleep":"^0.0.4","@3-/txt_li":"^0.1.5","@3-/utf8":"^0.0.4","lodash-es":"^4.17.21"}}
package/partition.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import seg from "./seg.js";
2
2
  import txtLi from "@3-/txt_li";
3
+ import rmCnSpace from "@3-/rm_cn_space";
3
4
 
4
5
  const partition = async (li, title_number, remain_seg) => {
5
6
  const order = title_number.sort((a, b) => a[1] - b[1]);
@@ -41,6 +42,9 @@ const partition = async (li, title_number, remain_seg) => {
41
42
  };
42
43
 
43
44
  export default async (chat, txt) => {
44
- const li = txtLi(txt);
45
+ if (!txt) {
46
+ return [];
47
+ }
48
+ const li = txtLi(txt).map((i) => rmCnSpace(i));
45
49
  return partition(li, await seg(chat, li), repartition(chat, li.length));
46
50
  };