跳到主要内容

Code Interpreter

The Code Interpreter in Flappy serves as an equivalent replacement for ChatGPT Code Interpreter, enabling the language model to fulfill complex user requirements through Python code. What sets Flappy's Code Interpreter apart from other open-source implementations in the market is its sandboxed safety feature. This ensures that it meets the stringent security needs necessary for deployment in a production environment.

How it works

Flappy's Code Interpreter is built with Rust, featuring a WebAssembly runtime environment that complies with the WASIX specifications. Unlike standard WebAssembly runtimes, this environment hosts a Python interpreter and supports nearly all POSIX interfaces, including socket, net, and filesystem IO operations. This means that even though the Python interpreter operates within a wasm sandbox, all functionalities remain fully intact.

The current version of the Python interpreter used in this environment is Python 3.12. All standard libraries (stdlib) work as expected. We are also in the process of adding support for the pip package manager, which will allow for further extension of capabilities.

Security-First Design

Our core design principle is "safety first". By default, access to the external network is off to ensure a secure environment. Similarly, environment variables are sandbox-isolated. However, if required, these settings can be overridden using custom configurations.

Usage

import { createFlappyAgent, ChatGPT, createCodeInterpreter } from '@pleisto/node-flappy'
import OpenAI from 'openai'

const gpt35 = new ChatGPT(
new OpenAI({
apiKey: process.env.OPENAI_API_KEY!,
baseURL: process.env.OPENAI_API_BASE!
})
)

const agent = createFlappyAgent({
llm: gpt35,
features: [createCodeInterpreter({}, { enableNetwork: false })]
})

void agent.executePlan(
'There are some rabbits and chickens in a barn. What is the number of chickens if there are 396 legs and 150 heads in the barn?'
)