支持gemini

This commit is contained in:
IndieKKY
2024-01-20 13:35:26 +08:00
parent c70fa81482
commit d97af83c9e

View File

@@ -253,16 +253,16 @@ export const extractJsonObject = (content: string) => {
const start = content.indexOf('```') const start = content.indexOf('```')
const end = content.lastIndexOf('```') const end = content.lastIndexOf('```')
if (start >= 0 && end >= 0) { if (start >= 0 && end >= 0) {
// 异常情况 if (start === end) { // 异常情况
if (start === end) {
if (content.startsWith('```')) { if (content.startsWith('```')) {
content = content.slice(3) content = content.slice(3)
} else { } else {
content = content.slice(0, -3) content = content.slice(0, -3)
} }
} } else {
content = content.slice(start + 3, end) content = content.slice(start + 3, end)
} }
}
// get content between { and } // get content between { and }
const start2 = content.indexOf('{') const start2 = content.indexOf('{')
const end2 = content.lastIndexOf('}') const end2 = content.lastIndexOf('}')
@@ -277,16 +277,16 @@ export const extractJsonArray = (content: string) => {
const start = content.indexOf('```') const start = content.indexOf('```')
const end = content.lastIndexOf('```') const end = content.lastIndexOf('```')
if (start >= 0 && end >= 0) { if (start >= 0 && end >= 0) {
// 异常情况 if (start === end) { // 异常情况
if (start === end) {
if (content.startsWith('```')) { if (content.startsWith('```')) {
content = content.slice(3) content = content.slice(3)
} else { } else {
content = content.slice(0, -3) content = content.slice(0, -3)
} }
} } else {
content = content.slice(start + 3, end) content = content.slice(start + 3, end)
} }
}
// get content between [ and ] // get content between [ and ]
const start3 = content.indexOf('[') const start3 = content.indexOf('[')
const end3 = content.lastIndexOf(']') const end3 = content.lastIndexOf(']')