-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Expand file tree
/
Copy pathutils.py
More file actions
40 lines (36 loc) · 1.15 KB
/
utils.py
File metadata and controls
40 lines (36 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import re
import os
import stat
import yaml
from crewai import LLM
from crewai.tasks import TaskOutput
# Load YAML configurations
def load_yaml_config(path):
with open(path, 'r') as f:
return yaml.safe_load(f)
# Initialize LLM
def load_llm():
llm = LLM(
model="ollama/deepseek-r1:7b",
base_url="http://localhost:11434"
)
return llm
# Check for mermaid syntax
def check_mermaid_syntax(task_output: TaskOutput):
text = task_output.raw
mermaid_blocks = re.findall(r'```mermaid\n(.*?)\n```', text, re.DOTALL)
# Find all mermaid code blocks in the text
for block in mermaid_blocks:
diagram_text = block.strip()
lines = diagram_text.split('\n')
corrected_lines = []
for line in lines:
corrected_line = re.sub(r'\|.*?\|>', lambda match: match.group(0).replace('|>', '|'), line)
corrected_lines.append(corrected_line)
text = text.replace(block, "\n".join(corrected_lines))
task_output.raw = text
return (True, task_output)
# Force remove readonly files (for .git files)
def remove_readonly(func, path, _):
os.chmod(path, stat.S_IWRITE)
func(path)