Spaces:
Runtime error
Runtime error
Download utils.py from DAMO-NLP-SG/CoI_Agent: direct link, hf CLI and curl.
- Browser
- Download file 937 Bytes
-
https://huggingface.co/spaces/DAMO-NLP-SG/CoI_Agent/resolve/main/utils.py
- Command line
-
hf download hf://spaces/DAMO-NLP-SG/CoI_Agent/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/DAMO-NLP-SG/CoI_Agent/resolve/main/utils.py
937 Bytes
| def get_content_between_a_b(start_tag, end_tag, text): | |
| extracted_text = "" | |
| start_index = text.find(start_tag) | |
| while start_index != -1: | |
| end_index = text.find(end_tag, start_index + len(start_tag)) | |
| if end_index != -1: | |
| extracted_text += text[start_index + len(start_tag) : end_index] + " " | |
| start_index = text.find(start_tag, end_index + len(end_tag)) | |
| else: | |
| break | |
| return extracted_text.strip() | |
| def extract(text, type,hard = True): | |
| if text: | |
| target_str = get_content_between_a_b(f"<{type}>", f"</{type}>", text) | |
| if target_str: | |
| return target_str | |
| elif hard: | |
| return text | |
| else: | |
| return "" | |
| else: | |
| return "" | |
| def extract_json(text): | |
| if "```json" in text: | |
| target_str = get_content_between_a_b("```json", "```", text) | |
| return target_str | |
| else: | |
| return text | |