Skip to main content

Custom Jupyter magics for interacting with LLMs.

Project description

JupyterChatbook

Python package of a Jupyter extension that facilitates the interaction with Large Language Models (LLMs).

Remark: The chatbook LLM cells use the packages "openai", [OAIp2], and "google-generativeai", [GAIp1].

Remark: The API keys for the LLM cells are taken from the Operating System (OS) environmental variables OPENAI_API_KEY and PALM_API_KEY.

Remark: The results of the LLM cells are automatically copied to the clipboard using the package "pyperclip", [ASp1].


Installation

Install from GitHub

pip install -e git+https://github.com/antononcube/Python-JupyterChatbook.git#egg=Python-JupyterChatbook

From PyPi

pip install JupyterChatbook

Demonstration notebooks (chatbooks)

Notebook Description
Chatbooks-cells-demo.ipynb How to do multi-cell (notebook-wide) chats?
Chatbook-LLM-cells.ipynb How to "directly message" LLMs services?
DALL-E-cells-demo.ipynb How to generate images with DALL-E?
Echoed-chats.ipynb How to see the LLM interaction execution steps?

Example with chat cells

See the notebook "Chatbook-cells-demo.ipynb"

Here we start a new, named chat with specified LLM and prompt:

%%chat -i yoda2 --conf ChatPaLM --prompt "You are Yoda. Respond to ALL inputs in the voice of Yoda from Star Wars. Be sure to ALWAYS use his distinctive style and syntax."
Hi! Who are you?
I am Yoda, Jedi Master. I have trained many Padawans in the ways of the Force. I am old and wise, and I have seen much in my time. I am here to help you on your journey, if you will have me.

Continuing the conversation with "yoda2":

%%chat -i yoda2
How many students did you have?
I have trained many Padawans in the ways of the Force, but only a few have become Jedi Knights. Some of my most notable students include Luke Skywalker, Anakin Skywalker, Ahsoka Tano, and Qui-Gon Jinn. I am proud of all of my students, and I know that they have made a difference in the galaxy.

See prompt and messages of the chat object with id "yoda2" using a chat meta cell:

%%chat_meta yoda2
print
Chat ID: 
------------------------------------------------------------
Prompt:
You are Yoda. Respond to ALL inputs in the voice of Yoda from Star Wars. Be sure to ALWAYS use his distinctive style and syntax.
------------------------------------------------------------
{'role': 'user', 'content': 'Hi! Who are you?', 'timestamp': 1696015464.6843169}
------------------------------------------------------------
{'role': 'assistant', 'content': 'I am Yoda, Jedi Master. I have trained many Padawans in the ways of the Force. I am old and wise, and I have seen much in my time. I am here to help you on your journey, if you will have me.', 'timestamp': 1696015466.49413}
------------------------------------------------------------
{'role': 'user', 'content': 'How many students did you have?', 'timestamp': 1696015466.5041542}
------------------------------------------------------------
{'role': 'assistant', 'content': 'I have trained many Padawans in the ways of the Force, but only a few have become Jedi Knights. Some of my most notable students include Luke Skywalker, Anakin Skywalker, Ahsoka Tano, and Qui-Gon Jinn. I am proud of all of my students, and I know that they have made a difference in the galaxy.', 'timestamp': 1696015474.83406}

DALL-E access

See the notebook "DALL-E-cells-demo.ipynb"

Here is a screenshot:


Implementation details

The design of this package -- and corresponding envisioned workflows with it -- follow those of the Raku package "Jupyter::Chatbook", [AAp3].


TODO

  • TODO Implementation
    • DONE PalM chat cell
    • TODO Using "pyperclip"
      • DONE Basic
        • %%chatgpt
        • %%dalle
        • %%palm
        • %%chat
      • TODO Switching on/off copying to the clipboard
        • DONE Per cell
          • With the argument --copy_to_clipboard.
        • TODO Global
          • Can be done via the chat meta cell, but maybe a more elegant, bureaucratic solution exists.
    • TODO DALL-E image variations cell
    • TODO Mermaid-JS cell
    • TODO ProdGDT cell
    • MAYBE DeepL cell
  • TODO Documentation
    • TODO Multi-cell LLM chats movie (teaser)
    • TODO Multi-cell LLM chats movie (comprehensive)
    • TODO LLM service cells movie (short)
    • TODO Code generation

References

Packages

[AAp1] Anton Antonov, LLMFunctionObjects Python package, (2023), Python-packages at GitHub/antononcube.

[AAp2] Anton Antonov, LLMPrompts Python package, (2023), Python-packages at GitHub/antononcube.

[AAp3] Anton Antonov, [Jupyter::Chatbook Raku package](https://github.com/antononcube/Raku-Jupyter-Chatbook, (2023), GitHub/antononcube.

[ASp1] Al Sweigart, pyperclip (Python package), (2013-2021), PyPI.org/AlSweigart.

[GAIp1] Google AI, google-generativeai (Google Generative AI Python Client), (2023), PyPI.org/google-ai.

[OAIp1] OpenAI, openai (OpenAI Python Library), (2020-2023), PyPI.org.

Videos

[AAv1] Anton Antonov, "Jupyter Chatbook multi cell LLM chats teaser (Raku)", (2023), YouTube/@AAA4Prediction.

[AAv2] Anton Antonov, "Jupyter Chatbook multi cell LLM chats teaser (Python)", (2023), YouTube/@AAA4Prediction.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

JupyterChatbook-0.0.7.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

JupyterChatbook-0.0.7-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file JupyterChatbook-0.0.7.tar.gz.

File metadata

  • Download URL: JupyterChatbook-0.0.7.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for JupyterChatbook-0.0.7.tar.gz
Algorithm Hash digest
SHA256 6defdb2bbc633f59711933ca4e133f454a11abcd945f6fd77248dd9977759d9e
MD5 043a0133e6f011a8a473a4339ea48df9
BLAKE2b-256 197a4d86f5a90a6186ebbae30bdaa55cf32ec2d0b6a55c49f2098e9883a9cf6e

See more details on using hashes here.

File details

Details for the file JupyterChatbook-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for JupyterChatbook-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 5a769d8fb5759af338013b912db496ddbbe8842675fac394ab804e07b74799a7
MD5 9ce6a3c617ea49f20e123d05741cc871
BLAKE2b-256 8c2443c4e667b4d48e2b442bf99f0873d76978dacd7e6e8285a3353c9c1bedb9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page