mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
Merge branch 'ikechan8370:v2' into v2
This commit is contained in:
commit
447070283c
1 changed files with 22 additions and 1 deletions
23
apps/bym.js
23
apps/bym.js
|
|
@ -332,7 +332,8 @@ export class bym extends plugin {
|
|||
client.addTools(tools)
|
||||
let rsp = await client.sendMessage(e.msg, opt)
|
||||
let text = rsp.text
|
||||
let texts = text.split(/(?<!\?)[。?\n](?!\?)/, 3)
|
||||
let texts = customSplitRegex(text, /(?<!\?)[。?\n](?!\?)/, 3)
|
||||
// let texts = text.split(/(?<!\?)[。?\n](?!\?)/, 3)
|
||||
for (let t of texts) {
|
||||
if (!t || !t.trim()) {
|
||||
continue
|
||||
|
|
@ -407,3 +408,23 @@ function filterResponseChunk (msg) {
|
|||
}
|
||||
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