Giter Site home page Giter Site logo

ipython-gpt's Introduction

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.

ipython-gpt's People

Contributors

12rambau avatar kxxt avatar santiagobasulto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ipython-gpt's Issues

free API key not working?

Dear Santiago,

I am trying to set this up, using a free API token. I haven't used any of API free grant. Still I don't seem to get it work.
Neither with setting an environmental variable, nor with the openai-api-key option.

Is there anything wrong in using the free API key? Or what could be the reason?

That's the error I am getting:
APIResponseException: Failed API Request 'POST /v1/chat/completions'

Thanks,
Andreas

Can it work on Google Colab? Also, OpenAI Key is not working

Hi,

Thank you for this great work

I'm trying to use ipython-gpt with Google Colab

I got this message when running the example chat: AssertionError: OPENAI_API_KEY missing

I'm not sure whether I did not integrate my OpenAI key properly or that it's not compatible with Colab

Assume this is my key (which I deleted BTW): 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

How can I integrate it with ipython-gpt?

replace jupyter notebook to excalidraw canvas

the notebook only allows to scroll up and down, but on the canvas you can scroll left and right, and also zoom in and out, which makes it easier to follow up through different variations and branches of my notes

Improvements planned/needed

Code design and architecture

  • Authentication: I can probably subclassrequests.Session while keeping the OpenAI API Key in some context to avoid the repetition
  • Subcommand architecture: some methods in the IPythonGPT class are subcommands, while others are utility methods, but not all subcommands are behaving equally.
  • Parameter parsing: Related to subcommands; there's a global argument parser shared by all the subcommands. Each command should define its own parser while extending the base parameters. I'm not sure if argparse is the correct alternative.
  • Displaying and formatting: I need to improve the way the results are displayed for different types of interfaces (notebook, shell, etc)

Code quality

  • Testing: Some testing wouldn't be bad ๐Ÿคก
  • Create its own package: Move ipython_gpt.py from module to a package
  • Code formatting: Should incorporate black
  • CI/CD Pipeline: A minimum pipeline to check formatting and test coverage

Feature improvements

  • Streaming: Test support for stream=True.
  • Debug mode: some way to see/debug what the client is doing behind the scenes.

No issues, just playing around

Great idea!
I have tested it in Emacs vterm and eshell.
It plays ok in vterm, but eshell.
In eshell it jumps one space all the time, e.g.,
if I write "%%chat", it does "%% chat", then I have to delete the space between "%% and chat"

Error accessing the openai interface: TimeoutError

Hi,

I am trying to use iPhone GPT with Jupyterab, which is launched locally.

I got this message when running the example chat: TimeoutError: [WinError 10060]

But I have no problem directly executing the same request using a Python program.

How to handle this situation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.