mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
Improve _save_file method to handle both dict and str inputs (#1011)
- Add check for dict type input - Use json.dump for dict serialization - Convert non-dict inputs to string - Remove type ignore comments
This commit is contained in:
@@ -360,8 +360,12 @@ class Task(BaseModel):
|
|||||||
if directory and not os.path.exists(directory):
|
if directory and not os.path.exists(directory):
|
||||||
os.makedirs(directory)
|
os.makedirs(directory)
|
||||||
|
|
||||||
with open(self.output_file, "w", encoding="utf-8") as file: # type: ignore # Argument 1 to "open" has incompatible type "str | None"; expected "int | str | bytes | PathLike[str] | PathLike[bytes]"
|
with open(self.output_file, "w", encoding="utf-8") as file:
|
||||||
file.write(result)
|
if isinstance(result, dict):
|
||||||
|
import json
|
||||||
|
json.dump(result, file, ensure_ascii=False, indent=2)
|
||||||
|
else:
|
||||||
|
file.write(str(result))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user