Getting an error trying to use OpenAI and PandasAI with Python

Hello all,

I am trying to instantiate a SmartDatalake using the PandasAI API and OpenAI.

My code looks like this:

import pandas as pd
from pandasai import Agent, SmartDataframe
import os
#from pandasai.llm import OpenAI
from pandasai.llm.openai import OpenAI
from pandasai.smart_datalake import SmartDatalake

# Step 1: Create sample CSV files

# Data for employees
employees_data = {
    "employee_id": [1, 2, 3, 4, 5],
    "name": ["Alice", "Bob", "Charlie", "David", "Eve"],
    "age": [25, 30, 35, 40, 45],
    "salary": [50000, 60000, 65000, 70000, 75000],
    "department_id": [101, 102, 101, 103, 102]
df_employees = pd.DataFrame(employees_data)
df_employees.to_csv("../data/employees.csv", index=False)

# Data for departments
departments_data = {
    "department_id": [101, 102, 103],
    "department_name": ["HR", "Engineering", "Marketing"]
df_departments = pd.DataFrame(departments_data)
df_departments.to_csv("../data/departments.csv", index=False)

# Step 2: Initialize the OpenAI LLM and SmartDataLake
llm = OpenAI(model = 'GPT-4o',OPENAI_API_KEY = "XXXX")

# Step 3: Load data from the SmartDataLake
smart_df_employees = SmartDataframe(pd.read_csv("../data/employees.csv"))
smart_df_departments = SmartDataframe(pd.read_csv("../data/departments.csv"))

# Step 4: Perform natural language queries
data_lake = SmartDatalake([smart_df_employees,smart_df_departments],config={"llm": llm})
response_salary = (' What is the average employee salary')
print("Average salary:", response_salary)

The error I get is: UnsupportedModelError: Unsupported model: The model ‘GPT-4o’ doesn’t exist or is not supported yet.

I’ve set up the api key with no restrictions, so it should support all of the OpenAI current models.

Can anyone point me in the right direction to solve this?


Sounds like a pandas issue.

It could be it’s just not updated yet to allow using the new model. Make sure you’re using the latest version of the module.


IDK most people just use the official library from OpenAI.

Maybe, but I am guessing that PandasAI just uses the OpenAi model directly rather than trying to roll their own openai api code. In other words, I’m guessing that under the covers, it is using the official library

Sounds like a capitalization error in your data value for model name.

Might I suggest:

model = 'GPT-4o'.lower(), OPENAI_API_KEY = "XXXX"

Which will work for all models you might mis-type except for fine tuning model names.