@shun-js/aibaiban-server 0.8.4 → 0.8.5
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.5",
|
|
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": "f3fa85784a8d086877a5057a29964d862126791c"
|
|
48
48
|
}
|
|
@@ -116,6 +116,8 @@ exports.drawAgent = async (req, res) => {
|
|
|
116
116
|
const intentResult = await callLLMForJSON(prompts.ROUTER_PROMPT.replace('{input}', input), res, 'router');
|
|
117
117
|
const intent = intentResult.intent;
|
|
118
118
|
req.logger.info(methodName, 'intent', intent);
|
|
119
|
+
// 发送结果
|
|
120
|
+
res.streaming(`data: ${JSON.stringify({ step: 'router', intent })}\n\n`);
|
|
119
121
|
|
|
120
122
|
// 非白板请求
|
|
121
123
|
if (intent === 'irrelevant') {
|
|
@@ -132,6 +134,8 @@ exports.drawAgent = async (req, res) => {
|
|
|
132
134
|
const classifyResult = await callLLMForJSON(prompts.CLASSIFY_PROMPT.replace('{input}', input), res, 'classify');
|
|
133
135
|
const diagramType = classifyResult.diagramType;
|
|
134
136
|
req.logger.info(methodName, 'diagramType', diagramType);
|
|
137
|
+
// 发送结果
|
|
138
|
+
res.streaming(`data: ${JSON.stringify({ step: 'classify', diagramType })}\n\n`);
|
|
135
139
|
|
|
136
140
|
// 3. elaborate - 细化内容
|
|
137
141
|
res.streaming(`data: ${JSON.stringify({ step: 'elaborate', status: 'start' })}\n\n`);
|
|
@@ -142,6 +146,8 @@ exports.drawAgent = async (req, res) => {
|
|
|
142
146
|
'elaborate',
|
|
143
147
|
);
|
|
144
148
|
req.logger.info(methodName, 'elaboration', elaboration.slice(0, 100) + '...');
|
|
149
|
+
// 发送结果(不显示内容,只标记完成)
|
|
150
|
+
res.streaming(`data: ${JSON.stringify({ step: 'elaborate', done: true })}\n\n`);
|
|
145
151
|
|
|
146
152
|
// 4. review - 质量检查
|
|
147
153
|
res.streaming(`data: ${JSON.stringify({ step: 'review', status: 'start' })}\n\n`);
|
|
@@ -154,6 +160,8 @@ exports.drawAgent = async (req, res) => {
|
|
|
154
160
|
'review',
|
|
155
161
|
);
|
|
156
162
|
req.logger.info(methodName, 'reviewResult', reviewResult);
|
|
163
|
+
// 发送结果
|
|
164
|
+
res.streaming(`data: ${JSON.stringify({ step: 'review', result: reviewResult.result })}\n\n`);
|
|
157
165
|
|
|
158
166
|
// 信息不足,追问用户
|
|
159
167
|
if (reviewResult.result === 'need_more_info') {
|
package/server/util/llm-agent.js
CHANGED
|
@@ -43,9 +43,9 @@ function extractJSON(text) {
|
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* 流式调用 LLM 并解析 JSON
|
|
46
|
-
*
|
|
46
|
+
* 不发送中间 delta,只返回解析后的结果
|
|
47
47
|
*/
|
|
48
|
-
exports.callLLMForJSON = async (prompt
|
|
48
|
+
exports.callLLMForJSON = async (prompt) => {
|
|
49
49
|
// 非流式调用,等待完整响应
|
|
50
50
|
const response = await llm.chat({
|
|
51
51
|
model: llmConfig.modelName,
|
|
@@ -53,16 +53,15 @@ exports.callLLMForJSON = async (prompt, res, step) => {
|
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
const fullContent = response.content || '';
|
|
56
|
-
//
|
|
57
|
-
res.streaming(`data: ${JSON.stringify({ step, delta: fullContent })}\n\n`);
|
|
58
|
-
|
|
56
|
+
// 不发送 delta,直接返回结果让调用方处理
|
|
59
57
|
return extractJSON(fullContent);
|
|
60
58
|
};
|
|
61
59
|
|
|
62
60
|
/**
|
|
63
61
|
* 流式调用 LLM(普通文本)
|
|
62
|
+
* 不发送中间 delta,只返回完整内容
|
|
64
63
|
*/
|
|
65
|
-
exports.callLLM = async (prompt
|
|
64
|
+
exports.callLLM = async (prompt) => {
|
|
66
65
|
let fullContent = '';
|
|
67
66
|
|
|
68
67
|
await llm.chatWithStreaming(
|
|
@@ -70,8 +69,7 @@ exports.callLLM = async (prompt, res, step) => {
|
|
|
70
69
|
{
|
|
71
70
|
contentCallback: (chunk) => {
|
|
72
71
|
fullContent += chunk;
|
|
73
|
-
//
|
|
74
|
-
res.streaming(`data: ${JSON.stringify({ step, delta: chunk })}\n\n`);
|
|
72
|
+
// 不发送中间 delta,避免显示问题
|
|
75
73
|
},
|
|
76
74
|
},
|
|
77
75
|
);
|