TrainingCourseGen / components /json_grabber.py
martinezjandrew's picture
fully implemented the generate script functionality
f02d14f
Raw History Blame Contribute Delete
550 Bytes
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}