IPython + GPT-4
A quick implementation of a random idea: what if ipython had a magic function that sent the current session to
gpt-4 along with a prompt, and automatically evaluated the result in the current session?
Installation
pip install ipython_openai
Then, you can either load the extension during an ipython session with %load_ext ipython_openai or add the following
to your ipython config.
c.InteractiveShellApp.extensions = ['ipython_openai']
Configuration
Your OpenAI API key should be available in the OPENAI_API_KEY env var. You can configure the model used by adding an
entry to your ipython config: c.GPT.model_name = 'gpt-4-turbo-preview'.
Usage
This extension adds two new "magic" functions documented below. Each one captures the current history of the ipython session and sends it to the OpenAI API along with the prompt given after the command. The result is streamed back to the session. Each invocation of the magic functions can also see the output from previous ones.
gen
In [1]: gen a 5 line greeter function with randomness
import random
def greet():
names = ["Alice", "Bob", "Charlie", "Diana", "Edward"]
greeting = ["Hello", "Hi", "Hey", "Greetings", "What's up"]
print(f"{random.choice(greeting)}, {random.choice(names)}!")
Run it? (y/n) y
In [2]: greet()
Hello, Bob!
ask
In [3]: ask what happened
When the `greet()` function was called, the following occurred:
1. The function selected a random name from the list `names`, which contains five different names: "Alice", "Bob", "Charlie", "Diana", and "Edward".
2. It also selected a random greeting from the list `greeting`, which includes five different greetings: "Hello", "Hi", "Hey", "Greetings", and "What's up".
3. It combined the selected greeting and name with a formatted string to create a message.
4. Finally, the function printed this message to the console.
Since the selections are random, the exact output can vary with each call to `greet()`, displaying a greeting and a name randomly chosen from the lists provided.
Metadata
Release files for ipython-openai 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ipython_openai-0.0.5.tar.gz | 4.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ipython_openai-0.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.9 kB
Release files / ipython_openai-0.0.5.tar.gz
| Download URL | ipython_openai-0.0.5.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c083117f2954360da54a66e8d6e787aa84bb92d138e6f1b354c3f3f80a7e5514
|
|
BLAKE2b-256 checksum How to use checksums |
31ca12ba3ed55a6c9881f6936e97d8a8251d9f6c4f823b9d29892581a253c22c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.14
|
Release files / ipython_openai-0.0.5-py3-none-any.whl
| Download URL | ipython_openai-0.0.5-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
be521641ceb578449cc0c73b642c4e4be9fb29c54ae0862ae185c7ab285959b0
|
|
BLAKE2b-256 checksum How to use checksums |
253a22ae2cd1c169c8399c1668af7cb04d1a6138827561eeca9eebdf63e19006
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.14
|