An IPython extension for interacting with OpenAI's models
Project description
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.
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
Built Distribution
File details
Details for the file ipython_openai-0.0.5.tar.gz
.
File metadata
- Download URL: ipython_openai-0.0.5.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c083117f2954360da54a66e8d6e787aa84bb92d138e6f1b354c3f3f80a7e5514 |
|
MD5 | a25f738c12053655882c99606da276fe |
|
BLAKE2b-256 | 31ca12ba3ed55a6c9881f6936e97d8a8251d9f6c4f823b9d29892581a253c22c |
Provenance
File details
Details for the file ipython_openai-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: ipython_openai-0.0.5-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be521641ceb578449cc0c73b642c4e4be9fb29c54ae0862ae185c7ab285959b0 |
|
MD5 | d16dd513efa5307dad50c52f106baa8b |
|
BLAKE2b-256 | 253a22ae2cd1c169c8399c1668af7cb04d1a6138827561eeca9eebdf63e19006 |