mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-28 09:38:17 +00:00
* Fix #3149: Add missing create_directory parameter to Task class - Add create_directory field with default value True for backward compatibility - Update _save_file method to respect create_directory parameter - Add comprehensive tests covering all scenarios - Maintain existing behavior when create_directory=True (default) The create_directory parameter was documented but missing from implementation. Users can now control directory creation behavior: - create_directory=True (default): Creates directories if they don't exist - create_directory=False: Raises RuntimeError if directory doesn't exist Fixes issue where users got TypeError when trying to use the documented create_directory parameter. Co-Authored-By: Jo\u00E3o <joao@crewai.com> * Fix lint: Remove unused import os from test_create_directory_true - Removes F401 lint error: 'os' imported but unused - All lint checks should now pass Co-Authored-By: Jo\u00E3o <joao@crewai.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Jo\u00E3o <joao@crewai.com>
This commit is contained in:
committed by
GitHub
parent
e7a5747c6b
commit
3ada4053bd
@@ -67,6 +67,7 @@ class Task(BaseModel):
|
||||
description: Descriptive text detailing task's purpose and execution.
|
||||
expected_output: Clear definition of expected task outcome.
|
||||
output_file: File path for storing task output.
|
||||
create_directory: Whether to create the directory for output_file if it doesn't exist.
|
||||
output_json: Pydantic model for structuring JSON output.
|
||||
output_pydantic: Pydantic model for task output.
|
||||
security_config: Security configuration including fingerprinting.
|
||||
@@ -115,6 +116,10 @@ class Task(BaseModel):
|
||||
description="A file path to be used to create a file output.",
|
||||
default=None,
|
||||
)
|
||||
create_directory: Optional[bool] = Field(
|
||||
description="Whether to create the directory for output_file if it doesn't exist.",
|
||||
default=True,
|
||||
)
|
||||
output: Optional[TaskOutput] = Field(
|
||||
description="Task output, it's final result after being executed", default=None
|
||||
)
|
||||
@@ -753,8 +758,10 @@ Follow these guidelines:
|
||||
resolved_path = Path(self.output_file).expanduser().resolve()
|
||||
directory = resolved_path.parent
|
||||
|
||||
if not directory.exists():
|
||||
if self.create_directory and not directory.exists():
|
||||
directory.mkdir(parents=True, exist_ok=True)
|
||||
elif not self.create_directory and not directory.exists():
|
||||
raise RuntimeError(f"Directory {directory} does not exist and create_directory is False")
|
||||
|
||||
with resolved_path.open("w", encoding="utf-8") as file:
|
||||
if isinstance(result, dict):
|
||||
|
||||
Reference in New Issue
Block a user