A library for interacting with Replit's code-exec API
Project description
replit-code-exec
An interface to interact with Replit's code-exec API.
This is an interface for the simpler use cases of https://replit.com/@luisreplit/eval-python, which is a stateless API that is optimized to be called from AI Agents so that they can perform numerical reasoning through the evaluation of generated Python code. In general, this allows the execution of an untrusted snippet of Python code and returns whatever is printed to standard output / standard error as the result. The execution is done inside an ephemeral unprivileged container created on the fly running in Replit Deployments using https://github.com/omegaup/omegajail as code sandbox.
To set up your own copy of the API server, you need to follow these easy 2-3 steps (the second is optional):
- Open the https://replit.com/@luisreplit/eval-python in your browser and Fork it to your account.
- (Optional): if you want to change the Docker container, run
evalctl image ${DOCKER_IMAGE}
(e.g.evalctl image python:3
orevalctl image replco/python-kitchen-sink:latest
).- Open
.replit
and change theEVAL_FILENAME
,EVAL_RUN_COMMAND
,EVAL_ENV
to suite the new container, if needed.
- Open
- Deploy the Repl! (just pressing
Run
is not enough)- This is only compatible with the Autoscale Deployments.
- Make sure you set the
EVAL_TOKEN_AUTH
Deployments secrets when doing so for authentication.
Sample usage
Here is a small example of this library being used as a small math solver using OpenAI API:
import openai
import replit_code_exec
code_exec = replit_code_exec.build_code_exec(...)
def solve_math(prompt: str, model: str = 'gpt-3.5-turbo-0613') -> str:
completion = openai.ChatCompletion.create(
model=model,
temperature=0.7,
functions=[code_exec.openai_schema],
function_call={"name": "code_exec"},
messages=[
{
"role": "system",
"content": ("You are an assistant that knows how to solve math " +
"problems by converting them into Python programs."),
},
{
"role": "user",
"content": ("Please solve the following problem by creating a Python " +
"program that prints the solution to standard output using " +
"`print()`: " + prompt),
},
],
)
return code_exec.from_response(completion)
Project details
Release history Release notifications | RSS feed
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 replit_code_exec-0.0.1.tar.gz
.
File metadata
- Download URL: replit_code_exec-0.0.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.19.0-1030-gcp
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e27d549609ffe07711be7fbe547d88ed58df73992f5bf048de25433179d5c1a6 |
|
MD5 | bff47cd6839219eec6f7b5de2f954fda |
|
BLAKE2b-256 | ec61b9aa903da3ff72f24a9bf327c9adfd630818bcba4e454f4a328b17aac937 |
File details
Details for the file replit_code_exec-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: replit_code_exec-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.19.0-1030-gcp
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e5bc7de88a65ac2d42ece5549d1a1744db430bc2b2e2489dce80254f7a4fb3d |
|
MD5 | ceed137fdfbbe8ef9e6e1e129703ecfe |
|
BLAKE2b-256 | 1df614206db1d797c915b948b400922cb55682f612e24e82f85c56f563e8fe90 |