Photo by Ben Griffiths on Unsplash

Using the New ChatGPT O1-preview Model from OpenAI to Improve my Python Code

From Script to Supercharged: How OpenAI’s o1-Preview Improved My Python Code

Lucas Soares
8 min readSep 14, 2024

--

I’ve been testing the recently released o1 model from OpenAI on a set of different tasks and I’ve been learning a lot about its reasoning capabilities.

In this article I discuss how I used the new o1-preview model from OpenAI to enhance a Python script I wrote. Spoiler alert: the results were pretty awesome.

The Genesis: A Script and a Challenge

Let’s set the scene. I had a Python script that interfaced with the Todoist API — a popular task management app. The script was designed to perform common actions like creating, editing, deleting, and listing tasks. It also had a nifty feature that allowed me to generate tasks in bulk using natural language descriptions, leveraging OpenAI’s gpt-4o-mini model + Pydantic for structured outputs.

Here’s the original script:


import sys
import argparse
from todoist_api_python.api import TodoistAPI
from llm_tools import generate_tasks_bulk
import os

# Replace 'YOUR_API_TOKEN' with your actual Todoist API token
API_TOKEN = os.environ["TODOIST_API_KEY"]

# Initialize the Todoist API client
api =…

--

--

Lucas Soares
Lucas Soares

Written by Lucas Soares

AI Engineer. I write about AI | Tools| Data Science | Productivity. Subscribe to my Youtube channel: https://www.youtube.com/@automatalearninglab/videos