Spaces:
Sleeping
Sleeping
File size: 420 Bytes
2f7798c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import { LLMResponse } from "@/types"
export function dirtyLLMJsonParser(input: string): string[] {
// we only keep what's after the first [
let jsonOrNot = `[${input.split("[").pop() || ""}`
// and before the first ]
jsonOrNot = `${jsonOrNot.split("]").shift() || ""}]`
const jsonData = JSON.parse(jsonOrNot) as LLMResponse
const captions = jsonData.map(item => item.caption.trim())
return captions
} |