Skip to main content

A Jupyter/IPython extension to use ChatGPT

Project description

IPython ChatGPT extension

This extension allows you to use ChatGPT directly from your Jupyter Notebook or IPython Shell.

IPython GPT, a Jupyter/IPython interface for Chat GPT IPython GPT, a Jupyter/IPython interface for Chat GPT

Important! This is a very early and raw version, I have a lot of things to improve regarding code quality and missing functionality.

Installation

!pip install ipython-gpt

Then in your notebook or ipython shell:

%load_ext ipython_gpt

Setup

You must first generate an API key at OpenAI (https://platform.openai.com/account/api-keys) and set is an environment variable OPENAI_API_KEY. You can do it by modifying your .bashrc/.zshrc or starting jupyter with it:

$ OPENAI_API_KEY=[YOUR-KEY] jupyter lab
# ...
$ OPENAI_API_KEY=[YOUR-KEY] ipython

There are a few other ways to set the API KEY, but the envvar is the recommended one.

ChatGPT API

The command %%chat interfaces with ChatGPT. It accepts multiple parameters (see Usage). Here's an example:

%%chat --max-tokens=25

What's the purpose of life?
...

>>> CHAT RESPONSE

Important by default, the %%chat command preserves the conversation to give the Agent some context, in the same way that ChatGPT works. You can "reset" its status passing the flag --reset-conversation.

%%chat --reset-conversation

How can I avoid pandas using scientific notation in outputs, and do it globally?
...
...
>>> CHAT RESPONSE

Agent's role (system message) and other chat parameters

By default, the Chat is started with the role: "You're a python data science coding assistant". You can change that by passing something different in your first %%chat:

%%chat --system-message="You're a R Data Science assistant"

Your message...

Once the conversation has started, you can't change the original message, as the context is preserved. To do so, you must reset the conversation:

%%chat --system-message="You're a R Data Science assistant" --reset-conversation

Your message...

Setting global config

You can change the defaults using the %chat_config line magic:

%chat_config --system-message="You're an R data scientist coding assistant specialized in visualizations" --model "other model" --reset-conversation

Invoke it without parameters to see the defaults set:

%chat_config
...

>>>
##### Conf set:

* **Default model**: gpt-3.5-turbo
* **Default system message**: You're a python data science coding assistant
* **Chat history length**: 0

Other methods

Display available models

Usage:

%chat_models [--all-models]
%chat_models
Available models:
- gpt-3.5-turbo-0301
- gpt-3.5-turbo

Display usage and accepted parameters

%reload_ext ipython_gpt
%chat_help
...


    usage: ipykernel_launcher.py [-h] [--openai-api-key OPENAI_API_KEY]
                                 [--reset-conversation]
                                 [--system-message SYSTEM_MESSAGE]
                                 [--no-system-message] [--model MODEL]
                                 [--temperature TEMPERATURE]
                                 [--max-tokens MAX_TOKENS] [--all-models]

Alternative authentication

Aside from setting the environment variable, you can also set OPENAI_API_KEY as a global variable in your notebook, or pass it directly as a parameter in any method ``--openai-api-key=YOUR-KEY`.

These alternative methods are NOT recommended, as you might leak your API Key in the notebooks' history, stored in .ipynb_checkpoints.

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

ipython-gpt-0.0.4.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

ipython_gpt-0.0.4-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file ipython-gpt-0.0.4.tar.gz.

File metadata

  • Download URL: ipython-gpt-0.0.4.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.0b8 CPython/3.8.0 Darwin/21.6.0

File hashes

Hashes for ipython-gpt-0.0.4.tar.gz
Algorithm Hash digest
SHA256 fd3cdbfb31e3762c951c2ec4dd8e53e4141aa4f0da27b3413d2c2f4f9d988c66
MD5 911f621e0734e0616016f0e5c98bf8ee
BLAKE2b-256 3513d0c0e0bee119c3c75862b328619c0840607f76c1ff83293ac6f15776742c

See more details on using hashes here.

File details

Details for the file ipython_gpt-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: ipython_gpt-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.0b8 CPython/3.8.0 Darwin/21.6.0

File hashes

Hashes for ipython_gpt-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f99c17b5917ec186804a76361a8d0660557b2081814eb4c1bab297dd02f2c309
MD5 27f705d056beda6f146094c0e285de0b
BLAKE2b-256 e78d05886827c62868ece91728202e5088010e801f4c1aa122b72f07224df418

See more details on using hashes here.

Supported by

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