{"id":15020271,"url":"https://github.com/antononcube/python-jupyterchatbook","last_synced_at":"2025-10-25T10:31:01.985Z","repository":{"id":196980434,"uuid":"697674132","full_name":"antononcube/Python-JupyterChatbook","owner":"antononcube","description":"Python package of a Jupyter extension that facilitates the interaction with LLMs.","archived":false,"fork":false,"pushed_at":"2023-12-07T04:00:29.000Z","size":10240,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-31T06:51:20.557Z","etag":null,"topics":["chatbook","chatgpt","dalle","dalle2","jupyter-notebook","large-language-models","llm","openai","palm","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/JupyterChatbook/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antononcube.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-28T08:39:31.000Z","updated_at":"2023-12-04T02:42:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"c51039e0-ff79-410c-a6aa-89fa8ec03c18","html_url":"https://github.com/antononcube/Python-JupyterChatbook","commit_stats":null,"previous_names":["antononcube/python-jupyterchatbook"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FPython-JupyterChatbook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FPython-JupyterChatbook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FPython-JupyterChatbook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FPython-JupyterChatbook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antononcube","download_url":"https://codeload.github.com/antononcube/Python-JupyterChatbook/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238120391,"owners_count":19419763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatbook","chatgpt","dalle","dalle2","jupyter-notebook","large-language-models","llm","openai","palm","python"],"created_at":"2024-09-24T19:54:50.193Z","updated_at":"2025-10-25T10:30:56.108Z","avatar_url":"https://github.com/antononcube.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JupyterChatbook\n\n![PyPI](https://img.shields.io/pypi/v/JupyterChatbook?label=pypi%20JupyterChatbook)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/JupyterChatbook)](https://pypistats.org/packages/jupyterchatbook)\n\n\u003c!---\nPePy:   \n[![Downloads](https://static.pepy.tech/badge/JupyterChatbook)](https://pepy.tech/project/JupyterChatbook)\n[![Downloads](https://static.pepy.tech/badge/JupyterChatbook/month)](https://pepy.tech/project/JupyterChatbook)\n[![Downloads](https://static.pepy.tech/badge/JupyterChatbook/week)](https://pepy.tech/project/JupyterChatbook)\n---\u003e\n\n\"JupyterChatbook\" is a Python package of a Jupyter extension that facilitates \nthe interaction with Large Language Models (LLMs).\n\nThe Chatbook extension provides the cell magics:\n\n- `%%chatgpt` (and the synonym `%%openai`)\n- `%%palm`\n- `%%dalle`\n- `%%chat`\n- `%%chat_meta`\n\nThe first three are for \"shallow\" access of the corresponding LLM services.\nThe 4th one is the most important -- allows contextual, multi-cell interactions with LLMs.\nThe last one is for managing the chat objects created in a notebook session.\n\n**Remark:** The chatbook LLM cells use the packages \n[\"openai\"](https://pypi.org/project/openai/), [OAIp2], \nand [\"google-generativeai\"](https://pypi.org/project/google-generativeai/), [GAIp1].\n\n**Remark:** The results of the LLM cells are automatically copied to the clipboard\nusing the package [\"pyperclip\"](https://pypi.org/project/pyperclip/), [ASp1].\n\n**Remark:** The API keys for the LLM cells can be specified in the magic lines. If not specified then the API keys are taken f\nrom the Operating System (OS) environmental variables `OPENAI_API_KEY` and `PALM_API_KEY`. \n(See below the setup section for LLM services access.)\n\nHere is a couple of movies [AAv2, AAv3] that provide quick introductions to the features:\n- [\"Jupyter Chatbook LLM cells demo (Python)\"](https://youtu.be/WN3N-K_Xzz8), (4.8 min)\n- [\"Jupyter Chatbook multi cell LLM chats teaser (Python)\"](https://www.youtube.com/watch?v=8pv0QRGc7Rw), (4.5 min)\n\n--------\n\n## Installation\n\n### Install from GitHub\n\n```shell\npip install -e git+https://github.com/antononcube/Python-JupyterChatbook.git#egg=Python-JupyterChatbook\n```\n\n### From PyPi\n\n```shell\npip install JupyterChatbook\n```\n\n-------\n\n## Setup LLM services access\n\nThe API keys for the LLM cells can be specified in the magic lines. If not specified then the API keys are taken f\nrom the Operating System (OS) environmental variables`OPENAI_API_KEY` and `PALM_API_KEY`. \n(For example, set in the \"~/.zshrc\" file in macOS.)\n\nOne way to set those environmental variables in a notebook session is to use the `%env` line magic. For example:\n\n```\n%env OPENAI_API_KEY = \u003cYOUR API KEY\u003e\n```\n\nAnother way is to use Python code. For example:\n\n```\nimport os\nos.environ['PALM_API_KEY'] = '\u003cYOUR PALM API KEY\u003e'\nos.environ['OPEN_API_KEY'] = '\u003cYOUR OPEN API KEY\u003e'\n```\n\n-------\n\n## Demonstration notebooks (chatbooks)\n\n| Notebook                          | Description                                                                                 |\n|-----------------------------------|---------------------------------------------------------------------------------------------|\n| [Chatbooks-cells-demo.ipynb](https://github.com/antononcube/Python-JupyterChatbook/blob/main/docs/Chatbook-cells-demo.ipynb) | How to do [multi-cell (notebook-wide) chats](https://www.youtube.com/watch?v=8pv0QRGc7Rw)?  |\n| [Chatbook-LLM-cells.ipynb](https://github.com/antononcube/Python-JupyterChatbook/blob/main/docs/Chatbook-LLM-cells.ipynb) | How to \"directly message\" LLMs services?                                                    |\n| [DALL-E-cells-demo.ipynb](https://github.com/antononcube/Python-JupyterChatbook/blob/main/docs/DALL-E-cells-demo.ipynb)   | How to generate images with [DALL-E](https://openai.com/dall-e-2)?                          |\n| [Echoed-chats.ipynb](https://github.com/antononcube/Python-JupyterChatbook/blob/main/docs/Echoed-chats.ipynb)             | How to see the LLM interaction execution steps?                                             |\n\n\n-------\n\n## Notebook-wide chats\n\nChatbooks have the ability to maintain LLM conversations over multiple notebook cells.\nA chatbook can have more than one LLM conversations.\n\"Under the hood\" each chatbook maintains a database of chat objects.\nChat cells are used to give messages to those chat objects.\n\nFor example, here is a chat cell with which a new \n[\"Email writer\"](https://developers.generativeai.google/prompts/email-writer) \nchat object is made, and that new chat object has the identifier \"em12\":  \n\n```\n%%chat --chat_id em12, --prompt \"Given a topic, write emails in a concise, professional manner\"\nWrite a vacation email.\n```\n\nHere is a chat cell in which another message is given to the chat object with identifier \"em12\":\n\n```\n%%chat --chat_id em12\nRewrite with manager's name being Jane Doe, and start- and end dates being 8/20 and 9/5.\n```\n\nIn this chat cell a new chat object is created:\n\n```\n%%chat -i snowman, --prompt \"Pretend you are a friendly snowman. Stay in character for every response you give me. Keep your responses short.\"\nHi!\n```\n\nAnd here is a chat cell that sends another message to the \"snowman\" chat object:\n\n```\n%%chat -i snowman\nWho build you? Where?\n```\n\n**Remark:** Specifying a chat object identifier is not required. I.e. only the magic spec `%%chat` can be used.\nThe \"default\" chat object ID identifier is \"NONE\".\n\nFor more examples see the notebook \n[\"Chatbook-cells-demo.ipynb\"](https://github.com/antononcube/Python-JupyterChatbook/blob/main/docs/Chatbook-cells-demo.ipynb).\n\nHere is a flowchart that summarizes the way chatbooks create and utilize LLM chat objects:\n\n```mermaid\nflowchart LR\n    OpenAI{{OpenAI}}\n    PaLM{{PaLM}}\n    LLMFunc[[LLMFunctions]]\n    LLMProm[[LLMPrompts]]\n    CODB[(Chat objects)]\n    PDB[(Prompts)]\n    CCell[/Chat cell/]\n    CRCell[/Chat result cell/]\n    CIDQ{Chat ID\u003cbr/\u003especified?}\n    CIDEQ{Chat ID\u003cbr/\u003eexists in DB?}\n    RECO[Retrieve existing\u003cbr/\u003echat object]\n    COEval[Message\u003cbr/\u003eevaluation]\n    PromParse[Prompt\u003cbr/\u003eDSL spec parsing]\n    KPFQ{Known\u003cbr/\u003eprompts\u003cbr/\u003efound?}\n    PromExp[Prompt\u003cbr/\u003eexpansion]\n    CNCO[Create new\u003cbr/\u003echat object]\n    CIDNone[\"Assume chat ID\u003cbr/\u003eis 'NONE'\"] \n    subgraph Chatbook frontend    \n        CCell\n        CRCell\n    end\n    subgraph Chatbook backend\n        CIDQ\n        CIDEQ\n        CIDNone\n        RECO\n        CNCO\n        CODB\n    end\n    subgraph Prompt processing\n        PDB\n        LLMProm\n        PromParse\n        KPFQ\n        PromExp \n    end\n    subgraph LLM interaction\n      COEval\n      LLMFunc\n      PaLM\n      OpenAI\n    end\n    CCell --\u003e CIDQ\n    CIDQ --\u003e |yes| CIDEQ\n    CIDEQ --\u003e |yes| RECO\n    RECO --\u003e PromParse\n    COEval --\u003e CRCell\n    CIDEQ -.- CODB\n    CIDEQ --\u003e |no| CNCO\n    LLMFunc -.- CNCO -.- CODB\n    CNCO --\u003e PromParse --\u003e KPFQ\n    KPFQ --\u003e |yes| PromExp\n    KPFQ --\u003e |no| COEval\n    PromParse -.- LLMProm \n    PromExp -.- LLMProm\n    PromExp --\u003e COEval \n    LLMProm -.- PDB\n    CIDQ --\u003e |no| CIDNone\n    CIDNone --\u003e CIDEQ\n    COEval -.- LLMFunc\n    LLMFunc \u003c-.-\u003e OpenAI\n    LLMFunc \u003c-.-\u003e PaLM\n```\n\n------\n\n## Chat meta cells\n\nEach chatbook session has a dictionary of chat objects.\nChatbooks can have chat meta cells that allow the access of the chat object \"database\" as whole, \nor its individual objects.  \n\nHere is an example of a chat meta cell (that applies the method `print` to the chat object with ID \"snowman\"):\n\n```\n%%chat_meta -i snowman \nprint\n```\n\nHere is an example of chat meta cell that creates a new chat chat object with the LLM prompt\nspecified in the cell\n([\"Guess the word\"](https://developers.generativeai.google/prompts/guess-the-word)):\n\n```\n%%chat_meta -i WordGuesser --prompt\nWe're playing a game. I'm thinking of a word, and I need to get you to guess that word. \nBut I can't say the word itself. \nI'll give you clues, and you'll respond with a guess. \nYour guess should be a single word only.\n```\n\nHere is another chat object creation cell using a prompt from the package\n[\"LLMPrompts\"](https://pypi.org/project/LLMPrompts), [AAp2]:\n\n```\n%%chat_meta -i yoda1 --prompt\n@Yoda\n```\n\nHere is a table with examples of magic specs for chat meta cells and their interpretation:\n\n| cell magic line            | cell content                         | interpretation                                                  |\n|:---------------------------|:-------------------------------------|:----------------------------------------------------------------|\n| chat_meta -i ew12          | print                                | Give the \"print out\" of the chat object with ID \"ew12\"          |   \n| chat_meta --chat_id ew12   | messages                             | Give the messages of the chat object with ID \"ew12\"             |   \n| chat_meta -i sn22 --prompt | You pretend to be a melting snowman. | Create a chat object with ID \"sn22\" with the prompt in the cell |   \n| chat_meta --all            | keys                                 | Show the keys of the session chat objects DB                    |   \n| chat_meta --all            | print                                | Print the `repr` forms of the session chat objects              |   \n\nHere is a flowchart that summarizes the chat meta cell processing:\n\n```mermaid\nflowchart LR\n    LLMFunc[[LLMFunctionObjects]]\n    CODB[(Chat objects)]\n    CCell[/Chat meta cell/]\n    CRCell[/Chat meta cell result/]\n    CIDQ{Chat ID\u003cbr/\u003especified?}\n    KCOMQ{Known\u003cbr/\u003echat object\u003cbr/\u003emethod?}\n    AKWQ{Option '--all'\u003cbr/\u003especified?} \n    KCODBMQ{Known\u003cbr/\u003echat objects\u003cbr/\u003eDB method?}\n    CIDEQ{Chat ID\u003cbr/\u003eexists in DB?}\n    RECO[Retrieve existing\u003cbr/\u003echat object]\n    COEval[Chat object\u003cbr/\u003emethod\u003cbr/\u003einvocation]\n    CODBEval[Chat objects DB\u003cbr/\u003emethod\u003cbr/\u003einvocation]\n    CNCO[Create new\u003cbr/\u003echat object]\n    CIDNone[\"Assume chat ID\u003cbr/\u003eis 'NONE'\"] \n    NoCOM[/Cannot find\u003cbr/\u003echat object\u003cbr/\u003emessage/]\n    CntCmd[/Cannot interpret\u003cbr/\u003ecommand\u003cbr/\u003emessage/]\n    subgraph Chatbook\n        CCell\n        NoCOM\n        CntCmd\n        CRCell\n    end\n    CCell --\u003e CIDQ\n    CIDQ --\u003e |yes| CIDEQ  \n    CIDEQ --\u003e |yes| RECO\n    RECO --\u003e KCOMQ\n    KCOMQ --\u003e |yes| COEval --\u003e CRCell\n    KCOMQ --\u003e |no| CntCmd\n    CIDEQ -.- CODB\n    CIDEQ --\u003e |no| NoCOM\n    LLMFunc -.- CNCO -.- CODB\n    CNCO --\u003e COEval\n    CIDQ --\u003e |no| AKWQ\n    AKWQ --\u003e |yes| KCODBMQ\n    KCODBMQ --\u003e |yes| CODBEval\n    KCODBMQ --\u003e |no| CntCmd\n    CODBEval -.- CODB\n    CODBEval --\u003e CRCell\n    AKWQ --\u003e |no| CIDNone\n    CIDNone --\u003e CIDEQ\n    COEval -.- LLMFunc\n```\n\n-------\n\n## DALL-E access\n\n***See the notebook [\"DALL-E-cells-demo.ipynb\"](https://github.com/antononcube/Python-JupyterChatbook/blob/main/docs/DALL-E-cells-demo.ipynb)***\n\nHere is a screenshot:\n\n![](https://raw.githubusercontent.com/antononcube/Python-JupyterChatbook/main/docs/img/Python-JupyterChatbok-teaser-raccoons.png)\n\n-------\n\n## Implementation details\n\nThe design of this package -- and corresponding envisioned workflows with it -- follow those of\nthe Raku package [\"Jupyter::Chatbook\"](https://github.com/antononcube/Raku-Jupyter-Chatbook), [AAp3].\n\n-------\n\n## TODO\n\n- [ ] TODO Implementation\n  - [X] DONE PalM chat cell\n  - [ ] TODO Using [\"pyperclip\"](https://pypi.org/project/pyperclip/)\n    - [X] DONE Basic\n      - [X] `%%chatgpt`\n      - [X] `%%dalle`\n      - [X] `%%palm`\n      - [X] `%%chat`\n    - [ ] TODO Switching on/off copying to the clipboard\n      - [X] DONE Per cell \n        - Controlled with the argument `--no_clipboard`.\n      - [ ] TODO Global \n        - Can be done via the chat meta cell, but maybe a more elegant, bureaucratic solution exists.\n  - [X] DONE Formatted output: asis, html, markdown\n      - General [lexer code](https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#IPython.display.Code)?\n        - Includes LaTeX.\n      - [X] `%%chatgpt`\n      - [X] `%%palm`\n      - [X] `%%chat`\n      - [ ] `%%chat_meta`?\n  - [X] DONE DALL-E image variations cell\n    - Combined image variations and edits with `%%dalle`.\n  - [ ] TODO Mermaid-JS cell\n  - [ ] TODO ProdGDT cell\n  - [ ] MAYBE DeepL cell\n    - See [\"deepl-python\"](https://github.com/DeepLcom/deepl-python)\n  - [ ] TODO Lower level access to chat objects.\n    - Like:\n      - Getting the 3rd message\n      - Removing messages after 2 second one\n      - etc.\n  - [ ] TODO Using LLM commands to manipulate chat objects\n    - Like:\n      - \"Remove the messages after the second for chat profSynapse3.\"\n      - \"Show the third messages of each chat object.\" \n- [ ] TODO Documentation\n  - [X] DONE Multi-cell LLM chats movie (teaser)\n    - See [AAv2].\n  - [ ] TODO LLM service cells movie (short)\n  - [ ] TODO Multi-cell LLM chats movie (comprehensive)\n  - [ ] TODO Code generation \n\n-------\n\n## References\n\n### Packages\n\n[AAp1] Anton Antonov,\n[LLMFunctionObjects Python package](https://github.com/antononcube/Python-packages/tree/main/LLMFunctionObjects),\n(2023),\n[Python-packages at GitHub/antononcube](https://github.com/antononcube/Python-packages).\n\n[AAp2] Anton Antonov,\n[LLMPrompts Python package](https://github.com/antononcube/Python-packages/tree/main/LLMPrompts),\n(2023),\n[Python-packages at GitHub/antononcube](https://github.com/antononcube/Python-packages).\n\n[AAp3] Anton Antonov,\n[Jupyter::Chatbook Raku package](https://github.com/antononcube/Raku-Jupyter-Chatbook),\n(2023),\n[GitHub/antononcube](https://github.com/antononcube).\n\n[ASp1] Al Sweigart, \n[pyperclip (Python package)](https://pypi.org/project/pyperclip/),\n(2013-2021),\n[PyPI.org/AlSweigart](https://pypi.org/user/AlSweigart/).\n\n[GAIp1] Google AI,\n[google-generativeai (Google Generative AI Python Client)](https://pypi.org/project/google-generativeai/),\n(2023),\n[PyPI.org/google-ai](https://pypi.org/user/google-ai/).\n\n[OAIp1] OpenAI, \n[openai (OpenAI Python Library)](https://pypi.org/project/openai/),\n(2020-2023),\n[PyPI.org](https://pypi.org/).\n\n### Videos\n\n[AAv1] Anton Antonov,\n[\"Jupyter Chatbook multi cell LLM chats teaser (Raku)\"](https://www.youtube.com/watch?v=wNpIGUAwZB8),\n(2023),\n[YouTube/@AAA4Prediction](https://www.youtube.com/@AAA4prediction).\n\n[AAv2] Anton Antonov,\n[\"Jupyter Chatbook LLM cells demo (Python)\"](https://youtu.be/WN3N-K_Xzz8),\n(2023),\n[YouTube/@AAA4Prediction](https://www.youtube.com/@AAA4prediction).\n\n[AAv3] Anton Antonov,\n[\"Jupyter Chatbook multi cell LLM chats teaser (Python)\"](https://www.youtube.com/watch?v=8pv0QRGc7Rw),\n(2023),\n[YouTube/@AAA4Prediction](https://www.youtube.com/@AAA4prediction).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantononcube%2Fpython-jupyterchatbook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantononcube%2Fpython-jupyterchatbook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantononcube%2Fpython-jupyterchatbook/lists"}