• Stars
    star
    595
  • Rank 75,217 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created over 1 year ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An ChatGPT integration for Jupyter Notebooks and the IPython Shell

IPython ChatGPT extension

Black badge prettier badge pre-commit test

This (standalone, no external dependencies required) extension allows you to use ChatGPT directly from your Jupyter Notebook or IPython Shell (Demo).

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. Check this issue for a rough "roadmap".

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

If you're working on Google Colab, you can use the %env magic method (keep in mind that if you don't delete the cell, your key will be visible):

%env OPENAI_API_KEY=sk-W8b0... your key ...

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.

More Repositories

1

smartcsv

CSVs are awesome, yet they're pretty dumb. Let's get them smarter!
Python
371
star
2

pycon-concurrency-tutorial-2020

Main repo of PyCon 2020 Tutorial
Jupyter Notebook
137
star
3

debug-inspector-panel

A django-debug-toolbar panel to get information about certain variables.
Python
71
star
4

party-parrot

Bring the party to your terminal
Python
30
star
5

python-hacker-news

A library wrapper for Hacker News Search API (Powered by Algolia)
Jupyter Notebook
29
star
6

parallel

Effortless parallelization library for Python
Python
25
star
7

slack.py

A simple command line tool to interact with Slack
Python
22
star
8

hyper-inspector

Python
19
star
9

tpb-download

A python utility to download torrent files from The Pirate Bay. Repo for learning purposes.
Python
9
star
10

fuzzy-match-strings-using-pandas

Fuzzy string matching between different files using Pandas and Fuzzywuzzy.
Jupyter Notebook
8
star
11

Machine-Learning-for-Business

Jupyter Notebook
7
star
12

sargon

Python
5
star
13

django-tastypie-example

Example of a tastypie project.
Python
4
star
14

djangoday.com.ar

Official website for djangoday Argentina 2012
Python
3
star
15

mult.be

Multiple URL Shortener
Python
3
star
16

django-comments-utils

Util lib for making Django Comments framework development easier
Python
3
star
17

datawars-llm-challenges

2
star
18

flask-rest-toolkit

A set of tools to create simple Flask REST web services and APIs
Python
2
star
19

dotfiles

dotfiles
Shell
2
star
20

santiagobasulto.github.com

Personal blog/website
CSS
2
star
21

huikau

Micro ad-server for AppEngine
Python
2
star
22

python-for-experienced-programmers

Python
2
star
23

gdd-frlp

Source Code for FRLP Gestiรณn de Datos exercises.
Python
1
star
24

zappa-pydata-miami

HTML
1
star
25

pylatam-2019

Jupyter Notebook
1
star
26

hn-summary

Jupyter Notebook
1
star
27

data-analysis-archive

This repo contains a collection of different analysis I do whenever a question sparks my curiosity
Jupyter Notebook
1
star
28

santiagobasulto.com.ar

HTML
1
star
29

react-native-calculator

React Native Calculator
JavaScript
1
star
30

django-demo-project

Python
1
star
31

test_new_name

Makefile
1
star
32

react-basics

Basic examples to use React (see tags/releases)
HTML
1
star
33

django-orm-test

Django ORM Tests, for education purposes
Python
1
star
34

async-iterators

Async iterators experiments in javascript and node.js
JavaScript
1
star
35

google-image-search

A set of widgets and modules to construct a Google image search wiget in your site.
JavaScript
1
star
36

scala-concurrency-tests

Scala
1
star
37

django-model-utils

A set of models, fields and mixins to test some advanced Django models use cases.
Python
1
star
38

sherlock-debugger

Sherlock is a python debugger to provide more information about what you want to debug in real time.
Python
1
star