Compare commits

...

2 Commits

Author SHA1 Message Date
GabeKoga
63d7aae865 context error
Patch and later will prioritize this again to have context work with the yaml
2024-05-09 20:26:07 -03:00
GabeKoga
ca08865384 Bug/curly_braces_yaml
Added parser to help users on yaml syntax
2024-05-07 18:19:52 -03:00
3 changed files with 21 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import inspect
import os
from pathlib import Path
from crewai.utilities.parser import YamlParser
import yaml
from dotenv import load_dotenv
@@ -40,6 +41,7 @@ def CrewBase(cls):
@staticmethod
def load_yaml(config_path: str):
with open(config_path, "r") as file:
return yaml.safe_load(file)
parsedContent = YamlParser.parse(file)
return yaml.safe_load(parsedContent)
return WrappedClass

View File

@@ -6,3 +6,4 @@ from .printer import Printer
from .prompts import Prompts
from .rpm_controller import RPMController
from .fileHandler import FileHandler
from .parser import YamlParser

View File

@@ -0,0 +1,17 @@
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