See “Using OpenAI’s Assistants API” for Part 1 of the series.

The full Jupyter Notebook is available at my GitHub repository, and shows the step-by-step Python API calls that are required to add an image to an Assistant’s tool resources and then used it in a conversational thread with GPT to solve a problem that wouldn’t be possible using a text-only prompt.

The core is summarized here as:

name = "FrontEnd Dev"

instructions = """You are a dedicated frontend developer,
...
"""

# 0. We need an assistant
new_assistant(name, instructions)
ts_dev = get_asst_by_name(name=name)

#1. Add the uploaded file to its "resources"
client.beta.assistants.update(ts_dev.id,
    tool_resources={
        "code_interpreter": {
            "file_ids":[ui_file.id]
    }},
)

ts_dev = get_asst_by_name(name)
print(f"Assistant {ts_dev.name} is now ready, with files {ts_dev.tool_resources.code_interpreter.file_ids}")

the rest of the code is the same as before:

content = """Start creating the base project structure
and main files to implement a UI similar to the one
in the provided `replit-UI.png` screenshot.
"""

# 2. Get a Thread, and append a message to it
thread = new_thread()
add_msg_to_thread(thread, content)

# 4. Get a new Run, and associate it with our Thread
#    We will use the Assistant we just created.
run = new_run(thread=thread, asst_name=name)

# 5. We then ask GPT for advice
if wait_on_run(run, thread, timeout=360):
    response = get_response(thread)
    print(f"{name} says:\n{response}")
else:
    print(f"We failed! Status: {run.status} - details: {run.incomplete_details}") 

Please see the full Notebook for the complete listing of all the functions.

The full API documentation is here, where there is also a Playground to test with different assistants’ configurations.


Please feel free to reach out if you have an interesting LLM project (OpenAI-related or otherwise) and would like some help in getting it off the ground: my LinkedIn profile is here.

One response to “Using OpenAI’s Assistants API – Part 2”

  1. […] Part 1 and Part 2 of this series we explored how to use the new OpenaAI’s Threads API using Python; in this […]

Leave a comment

Trending