# IPython ChatGPT extension
[![Black badge](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![prettier badge](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?logo=prettier&logoColor=white)](https://github.com/prettier/prettier)
[![pre-commit](https://img.shields.io/badge/pre--commit-active-yellow?logo=pre-commit&logoColor=white)](https://pre-commit.com/)
[![test](https://img.shields.io/github/actions/workflow/status/santiagobasulto/ipython-gpt/test.yaml?logo=github&logoColor=white)](https://github.com/santiagobasulto/ipython-gpt/actions/workflows/test.yaml)
This (standalone, no external dependencies required) extension allows you to use ChatGPT directly from your Jupyter Notebook or IPython Shell ([Demo](https://github.com/santiagobasulto/ipython-gpt/blob/master/Demo.ipynb)).
<img width="900" alt="IPython GPT, a Jupyter/IPython interface for Chat GPT" src="https://user-images.githubusercontent.com/872296/232230454-44529ea4-920e-4294-9d61-550771a4a95e.png">
<img width="900" alt="IPython GPT, a Jupyter/IPython interface for Chat GPT" src="https://user-images.githubusercontent.com/872296/232230492-9bc50342-9d78-4adb-8168-2f94fcbc3b73.png">
**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](https://github.com/santiagobasulto/ipython-gpt/issues/4) for a rough "roadmap".
## Installation
```python
!pip install ipython-gpt
```
Then in your notebook or ipython shell:
```ipython
%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:
```bash
$ 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:
```python
%%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`.
```python
%%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`:
```ipython
%%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:
```ipython
%%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:
```ipython
%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:
```python
%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:
```bash
%chat_models [--all-models]
```
```python
%chat_models
```
##### Available models:
- gpt-3.5-turbo-0301
- gpt-3.5-turbo
#### Display usage and accepted parameters
```python
%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`.
Raw data
{
"_id": null,
"home_page": "https://github.com/santiagobasulto/ipython-gpt",
"name": "ipython-gpt",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "ipython,jupyter,chatgpt,openai",
"author": "Santiago Basulto",
"author_email": "santiago.basulto@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/67/55/fd99490401aa8dd41083f3474944c414eedb1f6b5173cca78fb87c0288a6/ipython_gpt-0.0.6.tar.gz",
"platform": null,
"description": "# IPython ChatGPT extension\n\n[![Black badge](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![prettier badge](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?logo=prettier&logoColor=white)](https://github.com/prettier/prettier)\n[![pre-commit](https://img.shields.io/badge/pre--commit-active-yellow?logo=pre-commit&logoColor=white)](https://pre-commit.com/)\n[![test](https://img.shields.io/github/actions/workflow/status/santiagobasulto/ipython-gpt/test.yaml?logo=github&logoColor=white)](https://github.com/santiagobasulto/ipython-gpt/actions/workflows/test.yaml)\n\nThis (standalone, no external dependencies required) extension allows you to use ChatGPT directly from your Jupyter Notebook or IPython Shell ([Demo](https://github.com/santiagobasulto/ipython-gpt/blob/master/Demo.ipynb)).\n\n<img width=\"900\" alt=\"IPython GPT, a Jupyter/IPython interface for Chat GPT\" src=\"https://user-images.githubusercontent.com/872296/232230454-44529ea4-920e-4294-9d61-550771a4a95e.png\">\n\n<img width=\"900\" alt=\"IPython GPT, a Jupyter/IPython interface for Chat GPT\" src=\"https://user-images.githubusercontent.com/872296/232230492-9bc50342-9d78-4adb-8168-2f94fcbc3b73.png\">\n\n**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](https://github.com/santiagobasulto/ipython-gpt/issues/4) for a rough \"roadmap\".\n\n## Installation\n\n```python\n!pip install ipython-gpt\n```\n\nThen in your notebook or ipython shell:\n\n```ipython\n%load_ext ipython_gpt\n```\n\n## Setup\n\nYou 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:\n\n```bash\n$ OPENAI_API_KEY=[YOUR-KEY] jupyter lab\n# ...\n$ OPENAI_API_KEY=[YOUR-KEY] ipython\n```\n\nThere are a few other ways to set the API KEY, but the envvar is the recommended one.\n\n## ChatGPT API\n\nThe command `%%chat` interfaces with ChatGPT. It accepts multiple parameters (see Usage). Here's an example:\n\n```python\n%%chat --max-tokens=25\n\nWhat's the purpose of life?\n...\n\n>>> CHAT RESPONSE\n```\n\n**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`.\n\n```python\n%%chat --reset-conversation\n\nHow can I avoid pandas using scientific notation in outputs, and do it globally?\n...\n...\n>>> CHAT RESPONSE\n```\n\n## Agent's role (system message) and other chat parameters\n\nBy 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`:\n\n```ipython\n%%chat --system-message=\"You're a R Data Science assistant\"\n\nYour message...\n```\n\nOnce the conversation has started, you can't change the original message, as the context is preserved. To do so, you must reset the conversation:\n\n```ipython\n%%chat --system-message=\"You're a R Data Science assistant\" --reset-conversation\n\nYour message...\n```\n\n## Setting global config\n\nYou can change the defaults using the `%chat_config` line magic:\n\n```ipython\n%chat_config --system-message=\"You're an R data scientist coding assistant specialized in visualizations\" --model \"other model\" --reset-conversation\n```\n\nInvoke it without parameters to see the defaults set:\n\n```python\n%chat_config\n...\n\n>>>\n##### Conf set:\n\n* **Default model**: gpt-3.5-turbo\n* **Default system message**: You're a python data science coding assistant\n* **Chat history length**: 0\n```\n\n## Other methods\n\n#### Display available models\n\nUsage:\n\n```bash\n%chat_models [--all-models]\n```\n\n```python\n%chat_models\n```\n\n##### Available models:\n\n - gpt-3.5-turbo-0301\n - gpt-3.5-turbo\n\n#### Display usage and accepted parameters\n\n```python\n%reload_ext ipython_gpt\n%chat_help\n...\n\n\n usage: ipykernel_launcher.py [-h] [--openai-api-key OPENAI_API_KEY]\n [--reset-conversation]\n [--system-message SYSTEM_MESSAGE]\n [--no-system-message] [--model MODEL]\n [--temperature TEMPERATURE]\n [--max-tokens MAX_TOKENS] [--all-models]\n\n```\n\n## Alternative authentication\n\nAside 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`.\n\nThese alternative methods are NOT recommended, as you might leak your API Key in the notebooks' history, stored in `.ipynb_checkpoints`.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Jupyter/IPython extension to use ChatGPT",
"version": "0.0.6",
"split_keywords": [
"ipython",
"jupyter",
"chatgpt",
"openai"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7e6cf8920abc7bf3ce4e74740d2378432e5c71826221fb74cd93875e280b4499",
"md5": "90868adf8da7b61743b8cafb531bf239",
"sha256": "3539fece8db9643fe300aa55f923dfd2d6dfeea37ee00ef1162a6610d46acd45"
},
"downloads": -1,
"filename": "ipython_gpt-0.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "90868adf8da7b61743b8cafb531bf239",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 7752,
"upload_time": "2023-04-26T08:42:14",
"upload_time_iso_8601": "2023-04-26T08:42:14.727623Z",
"url": "https://files.pythonhosted.org/packages/7e/6c/f8920abc7bf3ce4e74740d2378432e5c71826221fb74cd93875e280b4499/ipython_gpt-0.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6755fd99490401aa8dd41083f3474944c414eedb1f6b5173cca78fb87c0288a6",
"md5": "caab46771cf5637a7173418d8040de97",
"sha256": "3558b87704c25190418f7ff8811fcf25939046c0dc307420f72942f8fee0e7b8"
},
"downloads": -1,
"filename": "ipython_gpt-0.0.6.tar.gz",
"has_sig": false,
"md5_digest": "caab46771cf5637a7173418d8040de97",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 6657,
"upload_time": "2023-04-26T08:42:16",
"upload_time_iso_8601": "2023-04-26T08:42:16.917210Z",
"url": "https://files.pythonhosted.org/packages/67/55/fd99490401aa8dd41083f3474944c414eedb1f6b5173cca78fb87c0288a6/ipython_gpt-0.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-26 08:42:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "santiagobasulto",
"github_project": "ipython-gpt",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "ipython-gpt"
}