Receiving a An error occurred: The model `asst_EXAMPLE` does not exist or you do not have access to it

Hi all,

I am referencing an asst_ ID in my code, which extracts data from an Excel sheet, passes it into my Assistant, and returns the response to write into a new column in the spreadsheet.

Whenever referencing my asst_ in my python code I get an error: An error occurred: The model asst_EXAMPLE does not exist or you do not have access to it.

When referencing the same asst_ in a test call to GET /v1/assistants/listassistants I am able to see the asst_ in the response.

Here is my code(with keys and references removed):

import pandas as pd
import openai

openai.api_key = 'xxx'  

def query_openai_assistant(description):
    try:
        response = openai.ChatCompletion.create(
            model='asst_EXAMPLE',  
            messages=[
                {"role": "user", "content": description}
            ]
        )
        
generated text
        if response.choices:
            return response.choices[0].message['content'].strip()
        else:
            return "No response generated."
    except Exception as e:
        print(f"An error occurred: {e}")
        return ""

file_path = r'C:\Users\...'  
sheet_name = 'Sheet1'  

df = pd.read_excel(file_path, sheet_name=sheet_name)
if "Website Description and Bullets" not in df.columns:
    raise ValueError("The specified column does not exist in the spreadsheet.")

df['Assistant Response'] = df['Website Description and Bullets'].apply(query_openai_assistant)

with pd.ExcelWriter(file_path, engine='openpyxl', mode='a', if_sheet_exists='replace') as writer:
    df.to_excel(writer, sheet_name=sheet_name + ' Updated', index=False)

print("The spreadsheet has been updated with Assistant responses in a new sheet.")

Any ideas?

I am guessing asst_EXAMPLE is your Assistants API id and you are using it as the model in Chat completions API. You cannot do that.

2 Likes

You can find a list of acceptable model parameters here:
https://platform.openai.com/docs/models/overview

Since I can’t know if all models are available via your account you can also request your personal list via the API.

1 Like

Do you have any tips on where I need to update my code to fix this?

I see. If that’s the case, how do I use my prompt to generate the new data?

It looks like your code is from the old version but the main problem is you are using Chat completions. Here is a sample code using Assistants API:

from openai import OpenAI
import os
import time

client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY", "xxx"))

# create thread
thread = client.beta.threads.create()

# add user message
message = client.beta.threads.messages.create(
    thread_id=thread.id,
    role="user",
    content=description,
)

# call run
run = client.beta.threads.runs.create(
    thread_id=thread.id,
    assistant_id='asst_EXAMPLE',
)

# do polling
while run.status == "queued" or run.status == "in_progress":
        run = client.beta.threads.runs.retrieve(
            thread_id=thread.id,
            run_id=run.id,
        )
        time.sleep(0.5)

# get reply
messages = client.beta.threads.messages.list(thread_id=thread.id)

You should check the Assistants overview from the cookbook for detailed explanation.

1 Like