mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-04 21:32:38 +02:00
update: 添加nb支持
This commit is contained in:
parent
35c9d744a4
commit
a4cef261e0
4 changed files with 32 additions and 1 deletions
|
|
@ -5,6 +5,8 @@
|
|||
import os
|
||||
import json
|
||||
|
||||
import nbformat
|
||||
|
||||
from metagpt.const import DATA_PATH
|
||||
|
||||
def save_code_file(name: str, code_context: str, file_format: str = "py") -> None:
|
||||
|
|
@ -32,6 +34,8 @@ def save_code_file(name: str, code_context: str, file_format: str = "py") -> Non
|
|||
data = {"code": code_context}
|
||||
with open(file_path, "w", encoding="utf-8") as fp:
|
||||
json.dump(data, fp, indent=2)
|
||||
elif file_format == "ipynb":
|
||||
nbformat.write(code_context, file_path)
|
||||
else:
|
||||
raise ValueError("Unsupported file format. Please choose 'py' or 'json'.")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue