#Assistants API

1 messages · Page 1 of 1 (latest)

high forum
#

I'm struggle with accessing python code that has been used by caode interpreter. I see it in playground under runs, but couldn't get it using openai library. Any clues for me?

reef bloom
# high forum I'm struggle with accessing python code that has been used by caode interpreter....

In Jupyter Notebook
(in case you need to see only the code and formulas used by the code interpreter, skip to the end of the post)

!pip install openai
import os
%env OPENAI_API_KEY="YOUR_API_KEY"
%env ASSISTANT_ID="YOUR_ASSISTANT_ID"
from openai import OpenAI
client = OpenAI()
empty_thread = client.beta.threads.create()
print(empty_thread)
thread_message = client.beta.threads.messages.create(
  "thread_id",
  role="user",
  content="Calculate 15 times 247.",
)
run = client.beta.threads.runs.create(
    thread_id="thread_id",
    assistant_id=os.environ.get("ASSISTANT_ID")
)
print(run)
run = client.beta.threads.runs.retrieve(
  thread_id="thread_id",
  run_id="run_id"
)
print(run)
thread_messages = client.beta.threads.messages.list("thread_id")
print(thread_messages.data[0].content[0].text.value)
run_steps = client.beta.threads.runs.steps.list(
    thread_id="thread_id",
    run_id="run_id"
)
print(run_steps)
steps = run_steps.data
print(run_steps.data)
for step in steps:
    # Check if step_details.tool_calls is present
    if hasattr(step, 'step_details') and hasattr(step.step_details, 'tool_calls'):
        # Loop through tool_calls array
        for toolCall in step.step_details.tool_calls:
            # Check if code_interpreter is present
            if hasattr(toolCall, 'code_interpreter'):
                # Log the value of code_interpreter
                print(toolCall.code_interpreter)