A Guide to Writing Python with AI | Mito

A Guide to Writing Python with AI

Ready to write Python code 4x faster?

This will be an overview of the tools you can use to write Python automatically with AI.

OpenAI Codex

This is the most widely used code generation tool. It relies on Chat GPT-3 to generate code that the user prompts with written words. For example, as the website’s documentation says, prompting “Make a red ball bounce around the screen” will generate the code on the right of the image below.

As you can imagine, this is a simple Java example and more elaborate prompts will have less reliable results.

https://platform.openai.com/docs/guides/code

This guide has alot of Python use cases as well.

Mito

Mito has a new AI feature that allows the user to access ChatGPT within the Mitosheet. Previously, Mito only allowed you to generate Python by editing it's spreadsheet interface. Now users can open an AI window and use written prompts to edit their data and generate the equivalent code.

Tabnine

Tabnine is not a prompt based code generator, but a well established code autocomplete tool. One powerful feature is the ability to train Tabnine on your own repositories. This allows users to get code completions specific to their own style of coding.

OpenAI API client library

Another option is to simply install the openAI API interface into your Python environment. This will allow you to access OpenAI models within your environment. All you need to do is install and import the package.

$ pip install openai
import openai

Then you need to set up the model:


# Set up the OpenAI API client
openai.api_key = "YOUR_API_KEY"

# Set up the model and prompt
model_engine = "text-davinci-003"
prompt = "Hello, how are you today?"

# Generate a response
completion = openai.Completion.create(
    engine=model_engine,
    prompt=prompt,
    max_tokens=1024,
    n=1,
    stop=None,
    temperature=0.5,
)

response = completion.choices[0].text
print(response)

Open source ChatGPT interfaces for Jupyter

Since the explosion of ChatGPT, many repos have popped up on Github of how to access ChatGPT inside a Jupyter Notebook (or JupyterLab/JupyterHub). This is an obvious, yet very useful application for ChatGPT. I will be interesting to see how these integrations begin to evolve and differentiate from each other.

GitHub - jflam/chat-gpt-jupyter-extension: A browser extension that lets you chat with ChatGPT from any local Jupyter notebook.
A browser extension that lets you chat with ChatGPT from any local Jupyter notebook. - GitHub - jflam/chat-gpt-jupyter-extension: A browser extension that lets you chat with ChatGPT from any local…

Ready to write Python code 4x faster?