mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-14 02:28:30 +00:00
Bug/curly_braces_yaml
Added parser to help users on yaml syntax
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
12
src/crewai/utilities/parser.py
Normal file
12
src/crewai/utilities/parser.py
Normal file
@@ -0,0 +1,12 @@
|
||||
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
|
||||
)
|
||||
return modified_content
|
||||
Reference in New Issue
Block a user