mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
fix: gemini filter
This commit is contained in:
parent
25520ba9fe
commit
ced7a5a01f
3 changed files with 60 additions and 45 deletions
41
apps/bym.js
41
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() === '<EMPTY>') {
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue