diff --git a/apps/bym.js b/apps/bym.js index 9e9fb07..f15016b 100644 --- a/apps/bym.js +++ b/apps/bym.js @@ -18,6 +18,7 @@ import { KickOutTool } from '../utils/tools/KickOutTool.js' import { SetTitleTool } from '../utils/tools/SetTitleTool.js' import { SerpTool } from '../utils/tools/SerpTool.js' import { SendMessageToSpecificGroupOrUserTool } from '../utils/tools/SendMessageToSpecificGroupOrUserTool.js' +import { customSplitRegex, filterResponseChunk } from '../utils/text.js' export class bym extends plugin { constructor () { @@ -170,43 +171,3 @@ export class bym extends plugin { return false } } - -/** - * 过滤 - * @param msg - */ -function filterResponseChunk (msg) { - if (!msg || typeof msg !== 'string') { - return false - } - if (!msg.trim()) { - return false - } - if (msg.trim() === '```') { - return false - } - if (msg.trim() === '') { - return false - } - return msg -} - -function customSplitRegex (text, regex, limit) { - const result = [] - let match - let lastIndex = 0 - const globalRegex = new RegExp(regex, 'g') - - while ((match = globalRegex.exec(text)) !== null) { - if (result.length < limit - 1) { - result.push(text.slice(lastIndex, match.index)) - lastIndex = match.index + match[0].length - } else { - break - } - } - - // 添加剩余部分 - result.push(text.slice(lastIndex)) - return result -} diff --git a/client/CustomGoogleGeminiClient.js b/client/CustomGoogleGeminiClient.js index 1ed5542..2dbcecf 100644 --- a/client/CustomGoogleGeminiClient.js +++ b/client/CustomGoogleGeminiClient.js @@ -10,7 +10,8 @@ export const HarmCategory = { HARM_CATEGORY_HATE_SPEECH: 'HARM_CATEGORY_HATE_SPEECH', HARM_CATEGORY_SEXUALLY_EXPLICIT: 'HARM_CATEGORY_SEXUALLY_EXPLICIT', HARM_CATEGORY_HARASSMENT: 'HARM_CATEGORY_HARASSMENT', - HARM_CATEGORY_DANGEROUS_CONTENT: 'HARM_CATEGORY_DANGEROUS_CONTENT' + HARM_CATEGORY_DANGEROUS_CONTENT: 'HARM_CATEGORY_DANGEROUS_CONTENT', + HARM_CATEGORY_CIVIC_INTEGRITY: 'HARM_CATEGORY_CIVIC_INTEGRITY' } export const HarmBlockThreshold = { @@ -18,7 +19,8 @@ export const HarmBlockThreshold = { BLOCK_LOW_AND_ABOVE: 'BLOCK_LOW_AND_ABOVE', BLOCK_MEDIUM_AND_ABOVE: 'BLOCK_MEDIUM_AND_ABOVE', BLOCK_ONLY_HIGH: 'BLOCK_ONLY_HIGH', - BLOCK_NONE: 'BLOCK_NONE' + BLOCK_NONE: 'BLOCK_NONE', + OFF: 'OFF' } /** @@ -170,18 +172,22 @@ export class CustomGoogleGeminiClient extends GoogleGeminiClient { safetySettings: [ { category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, - threshold: HarmBlockThreshold.BLOCK_NONE + threshold: HarmBlockThreshold.OFF }, { category: HarmCategory.HARM_CATEGORY_HARASSMENT, - threshold: HarmBlockThreshold.BLOCK_NONE + threshold: HarmBlockThreshold.OFF }, { category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT, - threshold: HarmBlockThreshold.BLOCK_NONE + threshold: HarmBlockThreshold.OFF }, { category: HarmCategory.HARM_CATEGORY_HATE_SPEECH, + threshold: HarmBlockThreshold.OFF + }, + { + category: HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITY, threshold: HarmBlockThreshold.BLOCK_NONE } ], diff --git a/utils/text.js b/utils/text.js new file mode 100644 index 0000000..ab8ba11 --- /dev/null +++ b/utils/text.js @@ -0,0 +1,48 @@ +/** + * 过滤 + * @param msg + */ +export function filterResponseChunk (msg) { + if (!msg || typeof msg !== 'string') { + return false + } + if (!msg.trim()) { + return false + } + if (msg.trim() === '```') { + return false + } + if (msg.trim() === '') { + return false + } + msg = trimSpecific(msg, '