File size: 550 Bytes
f02d14f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | from haystack import component
from typing import List
@component
class JSONGrabber:
"""
A component that takes out a JSON body from a given string.
The string should have a JSON body encased with "<start>" and "<stop>" strings.
"""
@component.output_types(body=str)
def run(self, replies: List[str]):
reply = replies[0]
body = reply[reply.find("<start>") + len("<start>") :].strip()
body = body[: body.find("<stop>")].strip()
print(f"Grabbed JSON:\n{body}")
return {"body": body}
|