Aize Platform LogoAize Platform Docs

Assistants

Build AI assistants with memory and tools

Assistants (Beta)

The Assistants API allows you to build AI assistants within your own applications. An Assistant has instructions and can leverage models, tools, and knowledge to respond to user queries.

The Assistants API supports persistent threads, so you don't need to manage message history yourself.

Overview

  1. Create an Assistant: Define its custom instructions and pick a model.
  2. Create a Thread: A conversation session between a user and the assistant.
  3. Add Messages: User questions added to the thread.
  4. Run the Assistant: Trigger the assistant to process the thread and generate a response.

1. Create an Assistant

python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.aize.dev/v1"
)

assistant = client.beta.assistants.create(
    name="Math Tutor",
    instructions="You are a personal math tutor. Write and run code to answer math questions.",
    tools=[{"type": "code_interpreter"}],
    model="gpt-4-turbo"
)

2. Create a Thread

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

3. Add a Message

Add the user's question to the thread.

python
message = client.beta.threads.messages.create(
    thread_id=thread.id,
    role="user",
    content="I need to solve the equation `3x + 11 = 14`. Can you help me?"
)

4. Run the Assistant

Run the assistant on the thread to generate a response.

python
run = client.beta.threads.runs.create_and_poll(
    thread_id=thread.id,
    assistant_id=assistant.id,
    instructions="Please address the user as Jane Doe. The user has a premium account."
)

if run.status == 'completed':
    messages = client.beta.threads.messages.list(
        thread_id=thread.id
    )
    print(messages)
else:
    print(run.status)

Supported Tools

  • Code Interpreter: Write and run Python code.
  • File Search: Search for information in uploaded files.
  • Function Calling: Call your own custom functions.

Endpoints

MethodEndpointDescription
GET/v1/assistantsList assistants
POST/v1/assistantsCreate an assistant
GET/v1/threads/{thread_id}Retrieve a thread
POST/v1/threads/{thread_id}/messagesAdd a message
POST/v1/threads/{thread_id}/runsCreate a run

On this page