From 4bff5408d870249271d69f4c7f4e82634e61a3d6 Mon Sep 17 00:00:00 2001 From: Jesse R Weigel Date: Fri, 11 Apr 2025 09:14:05 -0400 Subject: [PATCH] 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. --- docs/guides/flows/first-flow.mdx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/guides/flows/first-flow.mdx b/docs/guides/flows/first-flow.mdx index ab03693b9..cb10de275 100644 --- a/docs/guides/flows/first-flow.mdx +++ b/docs/guides/flows/first-flow.mdx @@ -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)