How can I view the Python code that is getting executed by the code interpreter in OpenAI assistants? Seeing the Python codes it generated, I could verify if the generated code/answer is right or wrong.
I am using the following code for Assistants Q&A.
import os
import time
import json
import requests
from openai import AzureOpenAI
client = AzureOpenAI(
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"),
api_key= os.getenv("AZURE_OPENAI_API_KEY"),
api_version="2024-05-01-preview"
)
assistant = client.beta.assistants.create(
model="nbr-ds-gpt4o", # replace with model deployment name.
instructions="Show me the thought process to solve the problem. Also, share the generated Python code along with the answer.",
tools=[{"type":"code_interpreter"}],
tool_resources={"code_interpreter":{"file_ids":[file.id]}}
)
# Create a thread
thread = client.beta.threads.create()
# Add a user question to the thread
message = client.beta.threads.messages.create(
thread_id=thread.id,
role="user",
content="tell me about the data you have" # Replace this with your prompt
)
# Run the thread
run = client.beta.threads.runs.create_and_poll(
thread_id=thread.id,
assistant_id=assistant.id
)
# Looping until the run completes or fails
while run.status in ['queued', 'in_progress', 'cancelling']:
time.sleep(1)
run = client.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id)
if run.status == 'completed':
messages = client.beta.threads.messages.list(thread_id=thread.id)
print(messages)
elif run.status == 'requires_action':
pass
else:
print(run.status)
I see on the Assistant Playground, code interpreter does output some code, but it is not always possible to see the whole code. Is there a way to view the whole output by code_interpreter and access that in the above code?
