I was unsure how to retrieve the assistant once it was created and I ended up creating a whole lot of the same.
I received an answer that solved the problem:
def list_assistants():
assistant_object = client.beta.assistants.list()
return assistant_object
def delete_assistant(assistant_id):
"""Delete an assistant by ID."""
delete_url = f"{BASE_URL}/{assistant_id}"
response = requests.delete(delete_url, headers=HEADERS)
if response.status_code == 200:
print(f"Deleted assistant with ID: {assistant_id}")
else:
print(f"Failed to delete assistant with ID: {assistant_id}. Status Code: {response.status_code}")
def delete_all_assistants():
"""Delete all assistants."""
a_list = list_assistants()
assitant_obj_list = a_list.data
for i in range(len(assitant_obj_list)):
delete_assistant(assitant_obj_list[i].id)
def select_assistant(assistant_id):
# Use the 'beta.assistants' attribute, not 'Assistant'
assistant = client.beta.assistants.retrieve(assistant_id)
return assistant.id
def create_assistant(name, instructions, tools, model):
assistant = client.beta.assistants.create(
name=name,
instructions=instructions,
tools=tools,
model=model
)
return assistant.id # Return the assistant ID
def get_assistant_by_id(assistant_id):
assistant = client.beta.assistants.retrieve(assistant_id)
return assistant.id
def create_thread():
thread = client.beta.threads.create()
return thread
def select_assistant(assistant_id):
return get_assistant_by_id(assistant_id)
This, or the method behind the code could be integrated into the documentation /Assistant after the /managing-threads section.