mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 07:38:29 +00:00
* Bug/curly_braces_yaml Added parser to help users on yaml syntax * context error Patch and later will prioritize this again to have context work with the yaml
18 lines
759 B
Python
18 lines
759 B
Python
import re
|
|
|
|
|
|
class YamlParser:
|
|
def parse(file):
|
|
content = file.read()
|
|
# Replace single { and } with doubled ones, while leaving already doubled ones intact and the other special characters {# and {%
|
|
modified_content = re.sub(r"(?<!\{){(?!\{)(?!\#)(?!\%)", "{{", content)
|
|
modified_content = re.sub(
|
|
r"(?<!\})(?<!\%)(?<!\#)\}(?!})", "}}", modified_content
|
|
)
|
|
# Check for 'context:' not followed by '[' and raise an error
|
|
if re.search(r"context:(?!\s*\[)", modified_content):
|
|
raise ValueError(
|
|
"Context is currently only supported in code when creating a task. Please use the 'context' key in the task configuration."
|
|
)
|
|
return modified_content
|