Skip to main content

pai: A Python REPL with a built in AI agent.

It's like OpenAI's Code Interpreter running in your Python REPL.

A fully functional Python REPL with a built in AI agent that can generate and run code using the history as context.

PyPI - Version PyPI - Python Version

Features

  • Full Python REPL
  • Built-in AI agent that can generate and run code in the REPL
  • REPL history is used for LLM context.
  • Edit and approve all generated code before it is executed
  • Runs locally on your machine, so it has full system and internet access
  • Supports OpenAI and llama.cpp

Demo

Installation

pip install pai-repl

Usage

OpenAI models

The default model is OpenAI GPT-4. You will need to set your OpenAI API key.

$ export OPENAI_API_KEY=<your key>
$ pai

Specify OpenAI model

$ pai --openai gpt-3.5-turbo

llama.cpp compatible models

llama-cpp-python is an optional dependency because it requires native libraries to be installed so it must be installed using the llama extra.

$ pip install pai-repl[llama]
$ pai --llama <path to model>

Starting the REPL

When you invoke pai, it will start an interactive Python REPL.

$ pai
INP> print('howdy')
OUT> howdy

Start the agent

Start the agent with pai: <prompt>.

This will generate code using the prompt and REPL history. You can accept, edit or cancel the code. Immediately after the generated code is run, the LLM is called again with the new REPL history. This loop continues until the task is complete or you cancel the agent with Ctrl+C.

INP> pai: list files in the current directory
LLM>
import os
os.listdir()

OK?> import os
    ...> os.listdir()

One off code generation

Generate code with gen: <prompt>.

The generated code will be displayed and you can accept, edit or cancel it. Unlike the pai command, the LLM is not called again after the code is run.

INP> nums = [1,2,3]
INP> gen: average nums
LLM>
# to find the average of the numbers, we sum all the elements and then divide by the number of elements

average_nums = sum(nums) / len(nums)
average_nums

OK?> # to find the average of the numbers, we sum all the elements and then
    ...> divide by the number of elements
    ...>
    ...> average_nums = sum(nums) / len(nums)
    ...> average_nums
OUT> 2.0
INP>

REPL features

reset() will reset the REPL state and history. This is useful if you want to start a new task or want to start over. No previous history will be used for LLM context.

INP> a = 1
INP> reset()
INP> a
OUT> Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'a' is not defined
INP>

Run shell commands with !

INP> !ls
OUT> README.md
     assets
     setup.py
     ...

Quickstart from the command line

You can prompt pai from the command line

$ pai "find the largest file in the current directory"

Metadata

Release files for pai-repl 0.1.19

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pai-repl 0.1.19
File Size Uploaded
pai_repl-0.1.19.tar.gz 13.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pai-repl 0.1.19
File Interpreter ABI Platform
pai_repl-0.1.19-py3-none-any.whl Python 3 none any Details

Total release size: 28.4 kB

Release files / pai_repl-0.1.19.tar.gz

Download URL pai_repl-0.1.19.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
fa4dc7170dcd1b778b9463effc016e126ffaf5aea0dc6f863a0ec53f2fcf637f
BLAKE2b-256 checksum
How to use checksums
c1736393e3993256cda6341221046cbdd091938842ca48bd1047dce297199063
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.5 Darwin/22.1.0

Release files / pai_repl-0.1.19-py3-none-any.whl

Download URL pai_repl-0.1.19-py3-none-any.whl
Size 15.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2e0f11744ed0d47f420a40d49fae52651bf04a1e91b08d868dcd210d328dc327
BLAKE2b-256 checksum
How to use checksums
f0dd70bd249b42965f6c34cce997324e65feb5506699f615a3cd0b178f6c4dfa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.5 Darwin/22.1.0

Release history Release notifications | RSS feed

This release

0.1.19 This release

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page