Create output folder if it doesn't exits (#2573)

When running this project, I got an error because the output folder had not been created. 

I added a line to check if the output folder exists and create it if needed.
This commit is contained in:
Jesse R Weigel
2025-04-11 09:14:05 -04:00
committed by GitHub
parent d2caf11191
commit 4bff5408d8

View File

@@ -263,6 +263,7 @@ Let's create our flow in the `main.py` file:
```python
#!/usr/bin/env python
import json
import os
from typing import List, Dict
from pydantic import BaseModel, Field
from crewai import LLM
@@ -341,6 +342,9 @@ class GuideCreatorFlow(Flow[GuideCreatorState]):
outline_dict = json.loads(response)
self.state.guide_outline = GuideOutline(**outline_dict)
# Ensure output directory exists before saving
os.makedirs("output", exist_ok=True)
# Save the outline to a file
with open("output/guide_outline.json", "w") as f:
json.dump(outline_dict, f, indent=2)