mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
修改suno伪造生成策略,支持更多模型调用
This commit is contained in:
parent
123e5304a7
commit
d111d2625e
7 changed files with 86 additions and 30 deletions
|
|
@ -1243,6 +1243,34 @@ function maskString (str) {
|
|||
return firstThreeChars + maskedChars + lastThreeChars
|
||||
}
|
||||
|
||||
/**
|
||||
* generated by ai
|
||||
* @param rawJsonString
|
||||
* @returns {string}
|
||||
*/
|
||||
function fixNewlinesInJsonString(rawJsonString) {
|
||||
// 标记是否在字符串内
|
||||
let inString = false
|
||||
// 结果字符串
|
||||
let result = ''
|
||||
for (let i = 0; i < rawJsonString.length; i++) {
|
||||
const currentChar = rawJsonString[i]
|
||||
const nextChar = i + 1 < rawJsonString.length ? rawJsonString[i + 1] : ''
|
||||
// 检查当前字符是否为双引号,且不是转义的双引号
|
||||
if (currentChar === '"' && (i === 0 || rawJsonString[i - 1] !== '\\')) {
|
||||
inString = !inString // 切换在字符串内的标记
|
||||
}
|
||||
// 如果在字符串内且遇到换行符,则替换为\\n
|
||||
if (inString && (currentChar === '\n' || (currentChar === '\r' && nextChar === '\n'))) {
|
||||
result += '\\n'
|
||||
if (currentChar === '\r') i++ // 跳过\n
|
||||
} else {
|
||||
result += currentChar
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* generated by ai
|
||||
* @param text
|
||||
|
|
@ -1259,7 +1287,7 @@ export function extractMarkdownJson(text) {
|
|||
// 如果已经在一个 JSON 中,先结束当前的 JSON
|
||||
if (currentJson) {
|
||||
try {
|
||||
const parsedJson = JSON.parse(currentJson)
|
||||
const parsedJson = JSON.parse(fixNewlinesInJsonString(currentJson))
|
||||
mdJsonPairs.push({ json: parsedJson, markdown: currentMd + '```' })
|
||||
} catch (e) {
|
||||
console.error('JSON解析错误:', e)
|
||||
|
|
@ -1271,7 +1299,7 @@ export function extractMarkdownJson(text) {
|
|||
} else if (line.startsWith('```') && currentJson) {
|
||||
// 结束当前的 JSON
|
||||
try {
|
||||
const parsedJson = JSON.parse(currentJson)
|
||||
const parsedJson = JSON.parse(fixNewlinesInJsonString(currentJson))
|
||||
mdJsonPairs.push({ json: parsedJson, markdown: currentMd + line })
|
||||
} catch (e) {
|
||||
console.error('JSON解析错误:', e)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue