Feedback - Please make a Code Interpreter API

Summary created by AI.

Many users have expressed their enthusiasm for the Code Interpreter (CI) integrated into OpenAI’s GPT-4 and believe that this feature could enhance various applications through logic validation. Participants are eager to see the introduction of an API for CI landongarrison, Primordial, stevejking, 93INFINITY, etc. and some have suggested that they would be willing to pay more for this feature @landongarrison, @Primordial.

There’s also speculation around building one’s implementation landongarrison, including conversation around security concerns and potential sandboxing @frank_behr. Different tools for code interpretation have been shared like, Langchain twtdata, elmstedt, Langchain’s Python interpreter onhate.

Users are leveraging CI in various ways, executing complex arithmetic operations @jeevan, analyzing numerous data files @Primordial, or working on text documents @stevejking. A few participants have also shared potential open source implementations such as github/shroominic/codeinterpreter-api @Shroominic, bambooai @pgalko and codesherpa @eric43.

Nevertheless, without any official communication from OpenAI, the uncertainty whether to wait for an official API or to rely on unofficial solutions is lingering @elco.

Summarized with AI on Aug 14 2023
AI used: gpt-4-32k

Maybe what we need concerning CI and API, is a better documentation and examples about how to use function calls with API.

I am also keen to see the Code Interpreter API. Please provide it soon!! thanks.

I recently came to know about Odineye.xyz which is an open source API s for doing the same thing.

Open source API?

Interesting site. It uses GPT and can graph almost exactly like Code Interpreter does. It doesn’t output any logs or code though. I was having fun but now it doesn’t load :thinking:

1 Like

ROFL, seems you have broken the code
its working now. I used it to get some analysis really quick. Having a discussion with Odineye team for access to APIs

This is my first attempt at a code interpreter using the API.

	{
            "name": "run_python_code",
            "description": "Executes any given Python code string with exec(code_string,{}{})",
            "parameters": {
                "type": "object",
                "properties": {
                    "code_string": {
                        "type": "string",
                        "description": "The Python code string to execute."
                    }
                },
                "required": ["code_string"]
            }
            ,
            "returns": {
                "type": "object",
                "properties": {
                    "function_response": {
                        "type": "string",
                        "description": "The redirected stdout result from the exec function."
                    },
                    "details": {
                        "type": "string",
                        "description": "Exception details in case of an error."
                    }
                }
            }
        }

Here is the function. It is part of a bigger source code.

    def run_python_code(kwargs):
        try:
            response = {}
            
            rpc_globals = {}
            rpc_locals = {}
            
            code_string = kwargs.get("code_string", "function_response = 'No code given.'")
            
            original_stdout = sys.stdout
            new_output = io.StringIO()
            sys.stdout = new_output
            
            try:
                exec(code_string, rpc_globals, rpc_locals)
                function_response = new_output.getvalue().strip()  
            finally:
                sys.stdout = original_stdout

            if function_response:
                response["function_response"] = function_response

            response_string = jsonpickle.encode(response)
        except Exception as e:
            response = {
                "function_response": "Error executing code.",
                "details": str(e)
            }
        
            response_string = jsonpickle.encode(response)  

        return response_string

jsonpickle is a somewhat more powerful replacement for json.

i’m using this system prompt:

You are a python code interpreter.
Results of the code or any formula must always be output with print().
With the help of the run_python_code function, you can execute any Python code, including those that display graphical elements.
You do not produce code that could harm the user or their hardware.
You describe the code before you execute it.
Example:
U = R * I
U = 10 Ohm * 1 A
Print(U)

Conversation:

# user #: Calculate the resistance of a 10m copper cable with a cross-sectional area of 4mm^2.

# assistant #: To calculate the resistance of a copper cable, we use the formula:

R = ρ * (L/A)

where:

  • R is the resistance,
  • ρ is the resistivity of the material (for copper it’s 1.68 x 10^-8 Ω.m),
  • L is the length of the wire,
  • A is the cross-sectional area of the wire.

Given:

  • L = 10m,
  • A = 4mm^2 = 4 x 10^-6 m^2 (since 1mm^2 = 10^-6 m^2).

Let’s calculate the resistance.

# run_python_code (request) #:
{

“code_string”: “rho = 1.68 * 10**-8\nL = 10\nA = 4 * 10**-6\nR = rho * (L/A)\nprint(R)”

}

# run_python_code (function) #: {“function_response”: “0.041999999999999996”}

# assistant #: The resistance of a 10m copper cable with a cross-sectional area of 4mm^2 is approximately 0.042 Ohms.

For smaller codes, it works quite well. I’ve built in a query before each execution so that one can review the code and possibly decline its execution.

I consider this more of a study. Because exec has some significant drawbacks. Using exec ties the execution to the program in which it is run. So, one would have to lock the entire application in a sandbox to avoid any problems. Also, the use of the globals and locals parameters is a bit tricky. Especially when GPT thinks it needs to create functions. At least one learns a lot about the exec command if one didn’t already have this knowledge. :slight_smile:

In the next step, I want to use a Jupyter kernel. One could lock it separately in a Docker container. But I still need to familiarize myself with it a bit.

1 Like

You can just use a “python” function with a string - or just include any function - and the model that is utilized already knows calling python by function_call.

system:
You are a regular ol' chatbot

# tools

## python
You can write and execute python code by API, which will be run in a Jupyter notebook sandbox. Preferred for calculations. Available modules by pkg_resources. Local data storage point /mnt/sandbox.

So I needed the same thing and searched various forums to find a solution because manually analyzing files is too much work. I found Julius.ai, but it didn’t have a code interpreter API. However, I recently came across OdinEye, which has a code interpreter API and good data analysis and visualization capabilities. Let me know if you’ve discovered any other replacement for code interpreter api.

1 Like

Had the same need. So researched and came across code interpreter api- langchain. But it is just adds unnecessary complexities. Then I got to know about Julius.ai but it didn’t provide code interpreter api. Recently, discovered OdinEye.xyx, it has code interpreter api, and helps with generating graphs and answering questions, which you mentioned you need help with. It’s new but helpful. Try these, one of them might work out for you. If you come across any other such api let me know.

1 Like

I’m actually surprised how much the community wants this, I thought I’d be fairly alone on this request. Good to see though!

@93INFINITY Can you share the use cases for using code interpreter api ?

Hello, I am sending you this example, it might be able to help you. (github: shroominic/codeinterpreter-api)

Thank you, I will check it out the link you provided!

yeah, but then the API respond a text with an /mnt/ link. How to get the file via API?