def get_notebook()

in agents/opendevin/start.py [0:0]


def get_notebook(events: Iterable[Event]) -> dict:
    cells = []

    for event in events:
        if event.source != "agent":
            continue

        if isinstance(event, IPythonRunCellAction):
            cells.append(
                {
                    "cell_type": "markdown",
                    "metadata": {},
                    "source": [event.thought],
                }
            )
            cells.append(
                {
                    "cell_type": "code",
                    "metadata": {},
                    "source": event.code.split("\n"),
                    "outputs": [],
                    "execution_count": None,
                }
            )
        elif isinstance(event, IPythonRunCellObservation):
            assert cells
            assert cells[-1]["cell_type"] == "code"

            cells[-1]["outputs"].append(
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": event.content.split("\n"),
                }
            )
        elif isinstance(event, CmdRunAction):
            cells.append(
                {
                    "cell_type": "code",
                    "metadata": {},
                    "source": [f"!{event.command}"],
                    "outputs": [],
                    "execution_count": None,
                }
            )
        elif isinstance(event, CmdOutputObservation):
            assert cells
            assert cells[-1]["cell_type"] == "code"

            cells[-1]["outputs"].append(
                {
                    "name": "stdout",
                    "output_type": "stream",
                    "text": event.content.split("\n"),
                }
            )

    notebook = {
        "cells": cells,
        "metadata": {
            "kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"},
            "language_info": {
                "codemirror_mode": {"name": "ipython", "version": 3},
                "file_extension": ".py",
                "mimetype": "text/x-python",
                "name": "python",
                "nbconvert_exporter": "python",
                "pygments_lexer": "ipython3",
                "version": "3.11.0",
            },
        },
        "nbformat": 4,
        "nbformat_minor": 4,
    }

    return notebook