File size: 452 Bytes
c32ec0d
 
faf4ba4
c32ec0d
fcdbd7f
 
 
c32ec0d
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 
}