MCPcopy Create free account
hub / github.com/Mercury7353/PyBench / generate_notebook_one_cell

Function generate_notebook_one_cell

utils/save_notebook.py:17–33  ·  view source on GitHub ↗
(role, text=None, code=None, result=None)

Source from the content-addressed store, hash-verified

15
16
17def generate_notebook_one_cell(role, text=None, code=None, result=None):
18 if text is not None and code is None and result is None:
19 # 仅传入文本内容,生成Markdown单元格
20 cell = {"cell_type": "markdown", "metadata": {}, "source": f"<|{role}|>\n\n{text}"}
21 elif code is not None and result is not None:
22 # 传入文本、代码和执行结果,生成Code单元格
23 cell = {
24 "cell_type": "code",
25 "execution_count": None,
26 "metadata": {},
27 "outputs": [{"name": "stdout", "text": [result], "output_type": "stream"}],
28 "source": [code],
29 }
30 else:
31 raise ValueError("Invalid combination of parameters.")
32
33 return cell
34
35
36def save_as_ipynb(cells, filename):

Callers 1

generate_notebookFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected