@shun-js/aibaiban-server 0.8.5 → 0.8.7
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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shun-js/aibaiban-server",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.7",
|
|
4
4
|
"description": "aibaiban.com server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai aibaiban"
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"access": "public",
|
|
45
45
|
"registry": "https://registry.npmjs.org/"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "87f3b0d45f4f95caca6d23b861e262f443dc891b"
|
|
48
48
|
}
|
|
@@ -5,18 +5,8 @@ const service = require('../service/LLMService.js');
|
|
|
5
5
|
* controller
|
|
6
6
|
*/
|
|
7
7
|
module.exports = (app) => {
|
|
8
|
-
//
|
|
9
|
-
app.post('/
|
|
10
|
-
service.intent(req, res);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
// drawWithTools (使用结构化 JSON 输出)
|
|
14
|
-
app.post('/drawWithTools', (req, res) => {
|
|
15
|
-
service.drawWithTools(req, res);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
// draw/agent (流式 Agent)
|
|
19
|
-
app.post('/draw/agent', (req, res) => {
|
|
8
|
+
// draw agent
|
|
9
|
+
app.post('/chat-streaming', (req, res) => {
|
|
20
10
|
service.drawAgent(req, res);
|
|
21
11
|
});
|
|
22
12
|
};
|
|
@@ -1,93 +1,7 @@
|
|
|
1
|
-
// llm
|
|
2
|
-
const { llmParseIntent } = require('../util/llm-intent.js');
|
|
3
|
-
|
|
4
|
-
// structured json output
|
|
5
|
-
const { generateFlowchartWithTools } = require('../util/llm-toolcall.js');
|
|
6
|
-
|
|
7
|
-
// util
|
|
8
|
-
const { chatFeishuMsg, chatResFeishuMsg, errorFeishuMsg } = require('../util/feishu.js');
|
|
9
|
-
|
|
10
1
|
// llm agent
|
|
11
2
|
const { callLLMForJSON, callLLM } = require('../util/llm-agent.js');
|
|
12
3
|
const prompts = require('../util/prompt-agent.js');
|
|
13
4
|
|
|
14
|
-
/**
|
|
15
|
-
* intent
|
|
16
|
-
* @param {*} req
|
|
17
|
-
* @param {*} res
|
|
18
|
-
* @returns
|
|
19
|
-
*/
|
|
20
|
-
exports.intent = async (req, res) => {
|
|
21
|
-
const methodName = 'intent';
|
|
22
|
-
|
|
23
|
-
// check
|
|
24
|
-
if (!req.body.userPrompt) {
|
|
25
|
-
const msg = 'need userPrompt';
|
|
26
|
-
req.logger.error(methodName, msg);
|
|
27
|
-
res.jsonFail(msg);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// const
|
|
32
|
-
const userPrompt = decodeURIComponent(req.body.userPrompt);
|
|
33
|
-
req.logger.info(methodName, 'userPrompt', userPrompt);
|
|
34
|
-
chatFeishuMsg(req);
|
|
35
|
-
|
|
36
|
-
// go
|
|
37
|
-
try {
|
|
38
|
-
const llmParseIntentRes = await llmParseIntent(userPrompt);
|
|
39
|
-
const llmParseIntentObj = JSON.parse(llmParseIntentRes);
|
|
40
|
-
req.logger.info(methodName, 'llmParseIntentObj', llmParseIntentObj);
|
|
41
|
-
|
|
42
|
-
// r
|
|
43
|
-
chatResFeishuMsg(req, JSON.stringify(llmParseIntentObj));
|
|
44
|
-
res.jsonSuccess('success', llmParseIntentObj);
|
|
45
|
-
} catch (error) {
|
|
46
|
-
const msg = 'parse intent error';
|
|
47
|
-
errorFeishuMsg(req, msg);
|
|
48
|
-
req.logger.error(methodName, msg, error);
|
|
49
|
-
res.jsonFail(msg);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* drawWithTools - 使用结构化 JSON 输出生成流程图
|
|
55
|
-
* @param {*} req
|
|
56
|
-
* @param {*} res
|
|
57
|
-
* @returns
|
|
58
|
-
*/
|
|
59
|
-
exports.drawWithTools = async (req, res) => {
|
|
60
|
-
const methodName = 'drawWithTools';
|
|
61
|
-
|
|
62
|
-
// check
|
|
63
|
-
if (!req.body.userPrompt) {
|
|
64
|
-
const msg = 'need userPrompt';
|
|
65
|
-
req.logger.error(methodName, msg);
|
|
66
|
-
res.jsonFail(msg);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// const
|
|
71
|
-
const userPrompt = decodeURIComponent(req.body.userPrompt);
|
|
72
|
-
req.logger.info(methodName, 'userPrompt', userPrompt);
|
|
73
|
-
chatFeishuMsg(req);
|
|
74
|
-
|
|
75
|
-
// go
|
|
76
|
-
try {
|
|
77
|
-
const diagram = await generateFlowchartWithTools(userPrompt);
|
|
78
|
-
req.logger.info(methodName, 'diagram', diagram);
|
|
79
|
-
|
|
80
|
-
// r
|
|
81
|
-
chatResFeishuMsg(req, JSON.stringify(diagram));
|
|
82
|
-
res.jsonSuccess('success', diagram);
|
|
83
|
-
} catch (error) {
|
|
84
|
-
const msg = 'draw with tools error';
|
|
85
|
-
errorFeishuMsg(req, msg);
|
|
86
|
-
req.logger.error(methodName, msg, error);
|
|
87
|
-
res.jsonFail(msg);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
|
|
91
5
|
/**
|
|
92
6
|
* drawAgent - 流式 Agent 接口
|
|
93
7
|
* 流程:router -> classify -> elaborate -> review -> generate
|
|
@@ -74,6 +74,12 @@ module.exports = {
|
|
|
74
74
|
图表类型: {diagramType}
|
|
75
75
|
细化描述: {elaboration}
|
|
76
76
|
|
|
77
|
+
⚠️ 重要语法限制:
|
|
78
|
+
1. 禁止使用以下 Mermaid 保留字作为节点名称: start, end, stop, pause, resume, done, state, choice, fork, join
|
|
79
|
+
2. 如果流程有"开始"或"结束",使用"开始"((开始))、"结束"((结束)) 或 图标如((●))、((○)) 代替
|
|
80
|
+
3. 节点名称避免使用特殊符号如括号()[]{},可以用中文双引号""包裹
|
|
81
|
+
4. 连接线避免使用特殊字符,用中文描述如"是"、"否"、"到"
|
|
82
|
+
|
|
77
83
|
要求:
|
|
78
84
|
1. 生成合法的 Mermaid 语法
|
|
79
85
|
2. 使用中文标签
|