@shun-js/aibaiban-server 0.7.7 → 0.8.0
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/LICENSE +21 -0
- package/assets/bing.txt +1 -0
- package/assets/robots.txt +36 -0
- package/assets/sitemap.xml +16 -0
- package/package.json +6 -2
- package/server/controller/IndexController.js +12 -0
- package/server/controller/LLMController.js +17 -0
- package/server/controller/SEOController.js +18 -0
- package/server/log-options.js +34 -0
- package/server/service/IndexService.js +16 -0
- package/server/service/LLMService.js +85 -0
- package/server/service/SEOService.js +38 -0
- package/server/util/check.js +23 -0
- package/server/util/feishu.js +77 -0
- package/server/util/llm-intent.js +79 -0
- package/server/util/llm-toolcall.js +314 -0
- package/server/util/prompt-intent.md +277 -0
- package/server/util/prompt-toolcall.md +273 -0
- package/views/index.html +146 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 qiaowenbin<uikoo9@qq.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/assets/bing.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
4cb288d7aef5469c92616c0f5b5aeb89
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# AI白板 - robots.txt
|
|
2
|
+
# 更新时间: 2026-01-26
|
|
3
|
+
|
|
4
|
+
# 允许所有搜索引擎爬虫
|
|
5
|
+
User-agent: *
|
|
6
|
+
Allow: /
|
|
7
|
+
|
|
8
|
+
# 禁止爬取静态资源文件(可选,减少服务器负载)
|
|
9
|
+
# Disallow: /assets/
|
|
10
|
+
# Disallow: /*.js$
|
|
11
|
+
# Disallow: /*.css$
|
|
12
|
+
|
|
13
|
+
# 禁止爬取 API 接口
|
|
14
|
+
Disallow: /api/
|
|
15
|
+
|
|
16
|
+
# 爬虫访问速率限制(可选,防止爬虫过度占用带宽1)
|
|
17
|
+
# Crawl-delay: 1
|
|
18
|
+
|
|
19
|
+
# 站点地图
|
|
20
|
+
Sitemap: https://aibaiban.com/sitemap.xml
|
|
21
|
+
|
|
22
|
+
# 特定爬虫配置
|
|
23
|
+
# Google Bot
|
|
24
|
+
User-agent: Googlebot
|
|
25
|
+
Allow: /
|
|
26
|
+
Crawl-delay: 0
|
|
27
|
+
|
|
28
|
+
# Bing Bot
|
|
29
|
+
User-agent: Bingbot
|
|
30
|
+
Allow: /
|
|
31
|
+
Crawl-delay: 0
|
|
32
|
+
|
|
33
|
+
# 百度爬虫
|
|
34
|
+
User-agent: Baiduspider
|
|
35
|
+
Allow: /
|
|
36
|
+
Crawl-delay: 1
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<urlset
|
|
3
|
+
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
|
4
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
5
|
+
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
|
|
6
|
+
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
|
|
7
|
+
|
|
8
|
+
<!-- 首页/落地页 - 最高优先级 -->
|
|
9
|
+
<url>
|
|
10
|
+
<loc>https://aibaiban.com/</loc>
|
|
11
|
+
<lastmod>2026-02-03</lastmod>
|
|
12
|
+
<changefreq>weekly</changefreq>
|
|
13
|
+
<priority>1.0</priority>
|
|
14
|
+
</url>
|
|
15
|
+
|
|
16
|
+
</urlset>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shun-js/aibaiban-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "aibaiban.com server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai aibaiban"
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
"url": "https://github.com/uikoo9/shun-js/issues"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
|
+
"server",
|
|
20
|
+
"assets",
|
|
21
|
+
"views",
|
|
19
22
|
"app.js"
|
|
20
23
|
],
|
|
21
24
|
"scripts": {
|
|
@@ -40,5 +43,6 @@
|
|
|
40
43
|
"publishConfig": {
|
|
41
44
|
"access": "public",
|
|
42
45
|
"registry": "https://registry.npmjs.org/"
|
|
43
|
-
}
|
|
46
|
+
},
|
|
47
|
+
"gitHead": "6d0b2408e4398e16f0f4c6e32d204e511957035a"
|
|
44
48
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// service
|
|
2
|
+
const service = require('../service/LLMService.js');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* controller
|
|
6
|
+
*/
|
|
7
|
+
module.exports = (app) => {
|
|
8
|
+
// intent
|
|
9
|
+
app.post('/intent', (req, res) => {
|
|
10
|
+
service.intent(req, res);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// drawWithTools (使用结构化 JSON 输出)
|
|
14
|
+
app.post('/drawWithTools', (req, res) => {
|
|
15
|
+
service.drawWithTools(req, res);
|
|
16
|
+
});
|
|
17
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// service
|
|
2
|
+
const service = require('../service/SEOService.js');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* controller
|
|
6
|
+
*/
|
|
7
|
+
module.exports = (app) => {
|
|
8
|
+
// seo
|
|
9
|
+
app.get('/robots.txt', (req, res) => {
|
|
10
|
+
service.robots(req, res);
|
|
11
|
+
});
|
|
12
|
+
app.get('/sitemap.xml', (req, res) => {
|
|
13
|
+
service.sitemap(req, res);
|
|
14
|
+
});
|
|
15
|
+
app.get('/4cb288d7aef5469c92616c0f5b5aeb89.txt', (req, res) => {
|
|
16
|
+
service.bingIndexNow(req, res);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* log options
|
|
3
|
+
* @returns
|
|
4
|
+
*/
|
|
5
|
+
module.exports = () => {
|
|
6
|
+
// log options
|
|
7
|
+
const logLevel = 'debug';
|
|
8
|
+
const logPattern = 'yyyy-MM-dd-hh';
|
|
9
|
+
const logPath = require('path').resolve(__dirname, '../logs/qiao-z.log');
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
pm2: true,
|
|
13
|
+
pm2InstanceVar: 'INSTANCE_ID',
|
|
14
|
+
appenders: {
|
|
15
|
+
stdout: {
|
|
16
|
+
type: 'stdout',
|
|
17
|
+
},
|
|
18
|
+
datefile: {
|
|
19
|
+
type: 'dateFile',
|
|
20
|
+
pattern: logPattern,
|
|
21
|
+
filename: logPath,
|
|
22
|
+
keepFileExt: true,
|
|
23
|
+
numBackups: 30,
|
|
24
|
+
compress: true,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
categories: {
|
|
28
|
+
default: {
|
|
29
|
+
level: logLevel,
|
|
30
|
+
appenders: ['stdout', 'datefile'],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* index
|
|
3
|
+
* @param {*} req
|
|
4
|
+
* @param {*} res
|
|
5
|
+
*/
|
|
6
|
+
exports.index = async (req, res) => {
|
|
7
|
+
// const
|
|
8
|
+
const pagePath = './views/index.html';
|
|
9
|
+
|
|
10
|
+
// is static
|
|
11
|
+
const isStatic = await res.staticRender(pagePath);
|
|
12
|
+
if (isStatic) return;
|
|
13
|
+
|
|
14
|
+
// render
|
|
15
|
+
res.render(pagePath, {}, true);
|
|
16
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* intent
|
|
12
|
+
* @param {*} req
|
|
13
|
+
* @param {*} res
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
exports.intent = async (req, res) => {
|
|
17
|
+
const methodName = 'intent';
|
|
18
|
+
|
|
19
|
+
// check
|
|
20
|
+
if (!req.body.userPrompt) {
|
|
21
|
+
const msg = 'need userPrompt';
|
|
22
|
+
req.logger.error(methodName, msg);
|
|
23
|
+
res.jsonFail(msg);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// const
|
|
28
|
+
const userPrompt = decodeURIComponent(req.body.userPrompt);
|
|
29
|
+
req.logger.info(methodName, 'userPrompt', userPrompt);
|
|
30
|
+
chatFeishuMsg(req);
|
|
31
|
+
|
|
32
|
+
// go
|
|
33
|
+
try {
|
|
34
|
+
const llmParseIntentRes = await llmParseIntent(userPrompt);
|
|
35
|
+
const llmParseIntentObj = JSON.parse(llmParseIntentRes);
|
|
36
|
+
req.logger.info(methodName, 'llmParseIntentObj', llmParseIntentObj);
|
|
37
|
+
|
|
38
|
+
// r
|
|
39
|
+
chatResFeishuMsg(req, JSON.stringify(llmParseIntentObj));
|
|
40
|
+
res.jsonSuccess('success', llmParseIntentObj);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
const msg = 'parse intent error';
|
|
43
|
+
errorFeishuMsg(req, msg);
|
|
44
|
+
req.logger.error(methodName, msg, error);
|
|
45
|
+
res.jsonFail(msg);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* drawWithTools - 使用结构化 JSON 输出生成流程图
|
|
51
|
+
* @param {*} req
|
|
52
|
+
* @param {*} res
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
exports.drawWithTools = async (req, res) => {
|
|
56
|
+
const methodName = 'drawWithTools';
|
|
57
|
+
|
|
58
|
+
// check
|
|
59
|
+
if (!req.body.userPrompt) {
|
|
60
|
+
const msg = 'need userPrompt';
|
|
61
|
+
req.logger.error(methodName, msg);
|
|
62
|
+
res.jsonFail(msg);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// const
|
|
67
|
+
const userPrompt = decodeURIComponent(req.body.userPrompt);
|
|
68
|
+
req.logger.info(methodName, 'userPrompt', userPrompt);
|
|
69
|
+
chatFeishuMsg(req);
|
|
70
|
+
|
|
71
|
+
// go
|
|
72
|
+
try {
|
|
73
|
+
const diagram = await generateFlowchartWithTools(userPrompt);
|
|
74
|
+
req.logger.info(methodName, 'diagram', diagram);
|
|
75
|
+
|
|
76
|
+
// r
|
|
77
|
+
chatResFeishuMsg(req, JSON.stringify(diagram));
|
|
78
|
+
res.jsonSuccess('success', diagram);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
const msg = 'draw with tools error';
|
|
81
|
+
errorFeishuMsg(req, msg);
|
|
82
|
+
req.logger.error(methodName, msg, error);
|
|
83
|
+
res.jsonFail(msg);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// path
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
// qiao
|
|
5
|
+
const { readFile } = require('qiao-file');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* robots
|
|
9
|
+
* @param {*} req
|
|
10
|
+
* @param {*} res
|
|
11
|
+
*/
|
|
12
|
+
exports.robots = async (req, res) => {
|
|
13
|
+
const txtPath = path.resolve(__dirname, '../../assets/robots.txt');
|
|
14
|
+
const txt = await readFile(txtPath);
|
|
15
|
+
res.send(txt);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* sitemap
|
|
20
|
+
* @param {*} req
|
|
21
|
+
* @param {*} res
|
|
22
|
+
*/
|
|
23
|
+
exports.sitemap = async (req, res) => {
|
|
24
|
+
const sitemapPath = path.resolve(__dirname, '../../assets/sitemap.xml');
|
|
25
|
+
const sitemap = await readFile(sitemapPath);
|
|
26
|
+
res.send(sitemap);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* bingIndexNow
|
|
31
|
+
* @param {*} req
|
|
32
|
+
* @param {*} res
|
|
33
|
+
*/
|
|
34
|
+
exports.bingIndexNow = async (req, res) => {
|
|
35
|
+
const txtPath = path.resolve(__dirname, '../../assets/bing.txt');
|
|
36
|
+
const txt = await readFile(txtPath);
|
|
37
|
+
res.send(txt);
|
|
38
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// qiao
|
|
2
|
+
const { userCheck } = require('qiao-z-service');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* checkUserAuth
|
|
6
|
+
* @param {*} req
|
|
7
|
+
* @param {*} res
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
exports.checkUserAuth = async function (req, res) {
|
|
11
|
+
const userCheckRes = await userCheck(global.QZ_CONFIG.user, {
|
|
12
|
+
userid: req.headers.userid,
|
|
13
|
+
usertoken: req.headers.usertoken,
|
|
14
|
+
paths: JSON.stringify(global.QZ_CONFIG.paths),
|
|
15
|
+
path: req.url.pathname,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// pass
|
|
19
|
+
if (userCheckRes && userCheckRes.type === 'success') return true;
|
|
20
|
+
|
|
21
|
+
// r
|
|
22
|
+
res.json(userCheckRes);
|
|
23
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// services
|
|
2
|
+
const { feishuBot } = require('@shun-js/shun-service');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* feishuMsg
|
|
6
|
+
* @param {*} msg
|
|
7
|
+
*/
|
|
8
|
+
exports.feishuMsg = (msg) => {
|
|
9
|
+
if (global.QZ_CONFIG.env !== 'production') return;
|
|
10
|
+
|
|
11
|
+
feishuBot({
|
|
12
|
+
url: global.QZ_CONFIG.feishu.url,
|
|
13
|
+
feishuUrl: global.QZ_CONFIG.feishu.feishuUrl,
|
|
14
|
+
feishuMsg: msg,
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// is bot
|
|
19
|
+
function isBot(req) {
|
|
20
|
+
const ua = req.useragent;
|
|
21
|
+
const hasOSName = ua && ua.os && ua.os.name;
|
|
22
|
+
const isGoogleBot = ua && ua.browser && ua.browser.name === 'Googlebot';
|
|
23
|
+
const isMetaBot = ua && ua.browser && ua.browser.name === 'meta-externalagent';
|
|
24
|
+
const isSafariBot = ua && ua.engine && ua.engine.name === 'WebKit' && ua.engine.version === '605.1.15';
|
|
25
|
+
return !hasOSName || isGoogleBot || isMetaBot || isSafariBot;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* errorFeishuMsg
|
|
30
|
+
* @param {*} req
|
|
31
|
+
* @param {*} msg
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
exports.errorFeishuMsg = (req, msg) => {
|
|
35
|
+
// check
|
|
36
|
+
if (isBot(req)) return;
|
|
37
|
+
|
|
38
|
+
// msg
|
|
39
|
+
const uaJson = JSON.stringify(req.useragent || {});
|
|
40
|
+
exports.feishuMsg(`【通知】服务异常,${msg},请查看日志,ua:${uaJson}`);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* chatFeishuMsg
|
|
45
|
+
* @param {*} req
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
exports.chatFeishuMsg = (req) => {
|
|
49
|
+
// check
|
|
50
|
+
if (isBot(req)) return;
|
|
51
|
+
|
|
52
|
+
// msg
|
|
53
|
+
const uaJson = JSON.stringify(req.useragent || {});
|
|
54
|
+
const userid = req.headers.userid;
|
|
55
|
+
const prompt = decodeURIComponent(req.body.userPrompt);
|
|
56
|
+
|
|
57
|
+
const msg = `【通知】/chat被访问\nuserid:${userid}\nua:\n${uaJson}\nprompt:\n${prompt}`;
|
|
58
|
+
exports.feishuMsg(msg);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* chatResFeishuMsg
|
|
63
|
+
* @param {*} req
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
exports.chatResFeishuMsg = (req, chatRes) => {
|
|
67
|
+
// check
|
|
68
|
+
if (isBot(req)) return;
|
|
69
|
+
|
|
70
|
+
// msg
|
|
71
|
+
const uaJson = JSON.stringify(req.useragent || {});
|
|
72
|
+
const userid = req.headers.userid;
|
|
73
|
+
const prompt = decodeURIComponent(req.body.userPrompt);
|
|
74
|
+
|
|
75
|
+
const msg = `【通知】/chat生成成功\nuserid:${userid}\nua:\n${uaJson}\nprompt:\n${prompt}\nres:${chatRes}`;
|
|
76
|
+
exports.feishuMsg(msg);
|
|
77
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// path
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { readFile } = require('qiao-file');
|
|
4
|
+
|
|
5
|
+
// z
|
|
6
|
+
const { z } = require('zod');
|
|
7
|
+
const { zodToJsonSchema } = require('zod-to-json-schema');
|
|
8
|
+
|
|
9
|
+
// llm
|
|
10
|
+
const { GeminiVertex } = require('viho-llm');
|
|
11
|
+
const gemini = GeminiVertex({
|
|
12
|
+
projectId: global.QZ_CONFIG.gemini.projectId,
|
|
13
|
+
location: global.QZ_CONFIG.gemini.location,
|
|
14
|
+
modelName: global.QZ_CONFIG.gemini.modelName,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// const
|
|
18
|
+
const chatConfig = {
|
|
19
|
+
responseMimeType: 'application/json',
|
|
20
|
+
temperature: 0.2, // 保持较低温度,确保输出稳定
|
|
21
|
+
topP: 0.9,
|
|
22
|
+
topK: 40,
|
|
23
|
+
maxOutputTokens: 8192, // 足够大以支持复杂图表
|
|
24
|
+
thinkingConfig: {
|
|
25
|
+
thinkingBudget: 0,
|
|
26
|
+
includeThoughts: false,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
const safetySettings = [
|
|
30
|
+
{
|
|
31
|
+
category: 'HARM_CATEGORY_HATE_SPEECH',
|
|
32
|
+
threshold: 'BLOCK_ONLY_HIGH',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
category: 'HARM_CATEGORY_DANGEROUS_CONTENT',
|
|
36
|
+
threshold: 'BLOCK_ONLY_HIGH',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
category: 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
|
|
40
|
+
threshold: 'BLOCK_ONLY_HIGH',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
category: 'HARM_CATEGORY_HARASSMENT',
|
|
44
|
+
threshold: 'BLOCK_ONLY_HIGH',
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* llmParseIntent
|
|
50
|
+
* @param {*} userPrompts
|
|
51
|
+
*/
|
|
52
|
+
let intentSystemPrompt = null;
|
|
53
|
+
exports.llmParseIntent = async (userPrompts) => {
|
|
54
|
+
// intent system prompt - 支持版本切换
|
|
55
|
+
if (!intentSystemPrompt) {
|
|
56
|
+
const promptFile = './prompt-intent.md';
|
|
57
|
+
intentSystemPrompt = await readFile(path.resolve(__dirname, promptFile));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// chat config - 新增 confidence 字段支持
|
|
61
|
+
chatConfig.responseJsonSchema = zodToJsonSchema(
|
|
62
|
+
z.object({
|
|
63
|
+
intent: z.enum(['DRAW', 'REJECT']).describe('用户意图:DRAW(绘图)或 REJECT(非绘图)'),
|
|
64
|
+
reason: z.string().describe('判断理由(一句话说明)'),
|
|
65
|
+
confidence: z.number().min(0).max(1).optional().describe('置信度评分(0.0-1.0),可选字段'),
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
// chat options
|
|
70
|
+
const chatOptions = {
|
|
71
|
+
contents: userPrompts,
|
|
72
|
+
systemInstruction: intentSystemPrompt,
|
|
73
|
+
config: chatConfig,
|
|
74
|
+
safetySettings: safetySettings,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// go
|
|
78
|
+
return await gemini.chat(chatOptions);
|
|
79
|
+
};
|