Download components/json_grabber.py from ZoqiAndrewSeniorProject/TrainingCourseGen: direct link, hf CLI and curl.
- Browser
- Download file 550 Bytes
-
https://huggingface.co/spaces/ZoqiAndrewSeniorProject/TrainingCourseGen/resolve/main/components/json_grabber.py
- Command line
-
hf download hf://spaces/ZoqiAndrewSeniorProject/TrainingCourseGen/components/json_grabber.py
-
curl -L -o json_grabber.py https://huggingface.co/spaces/ZoqiAndrewSeniorProject/TrainingCourseGen/resolve/main/components/json_grabber.py
550 Bytes
| from haystack import component | |
| from typing import List | |
| 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. | |
| """ | |
| 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} | |