ai-manga-factory / src /lib /cleanJson.ts
jbilcke-hf's picture
jbilcke-hf HF staff
added suggestion from user + work on the progressive loader
faf4ba4
raw
history blame
452 Bytes
import { dirtyLLMResponseCleaner } from "./dirtyLLMResponseCleaner"
export function cleanJson(input: string): string {
if (input.includes('```')) {
input = input.split('```')[0]
}
let tmp = dirtyLLMResponseCleaner(input)
// we only keep what's after the first [
tmp = `[${tmp.split("[").pop() || ""}`
// and before the first ]
tmp = `${tmp.split("]").shift() || ""}]`
tmp = dirtyLLMResponseCleaner(tmp)
return tmp
}