Effect CommunityEC
Effect Community2y ago
3 replies
Alex Dixon

Example of Using Schema for String Parsing in GPT Output

Just wanted to share an example of using Schema for string parsing of gpt output:

export const XMLContents = (tag: string) =>
  S.String.pipe(
    S.transform(S.String, {
      decode: (a) => {
        const start = `<${tag}>`
        const end = `</${tag}>`
        const startIndex = a.indexOf(start)
        const endIndex = a.indexOf(end)
        return a.slice(startIndex + start.length, endIndex).trim()
      },

      encode: (a) => `<${tag}>${a}</${tag}>`
    })
  )
Was this page helpful?