Skip to content

Assistants are broken #522

@ausangshukla

Description

@ausangshukla

Describe the bug
The messages to an assistant do not produce any result.
The assistant gets created properly, however the messages are not sent to the thread, i.e the thread in the UI at https://platform.openai.com/playground/assistants is blank.

To Reproduce

`class AssistantTest
def initialize
@open_ai_client = OpenAI::Client.new(access_token: Rails.application.credentials["OPENAI_API_KEY"], llm_options: { model: "gpt-4o" })
puts "OpenAI client initialized"

    response = @open_ai_client.assistants.create(
    parameters: {
        model: "gpt-4o",
        name: "AssistantTest-#{Time.now}",
        description: nil,
        instructions: "You are a kind and caring assistant, who will try and respond to my requests.",
        tools: [
            { type: "code_interpreter" }
        ],
        tool_resources: {
            code_interpreter: {
                file_ids: []
            }
        },
        metadata: { my_internal_version_id: "1.0.0" }
    }
    )

    assistant_id = response["id"]
    puts "Assistant created with ID: #{assistant_id}"


    # Create thread
    response = @open_ai_client.threads.create # Note: Once you create a thread, there is no way to list it
    # or recover it currently (as of 2023-12-10). So hold onto the `id`
    thread_id = response["id"]
    puts "Thread created with ID: #{thread_id}"

    # Add initial message from user (see https://platform.openai.com/docs/api-reference/messages/createMessage)
    message_id = @open_ai_client.messages.create(
                                        thread_id: thread_id,
                                        parameters: {
                                            role: "user", # Required for manually created messages
                                            content: "Can you help me write an API library to interact with the OpenAI API please?"
                                        })["id"]
    puts "Message created with ID: #{message_id}"
    # Retrieve individual message
    message = @open_ai_client.messages.retrieve(thread_id: thread_id, id: message_id)

    # Review all messages on the thread
    messages = @open_ai_client.messages.list(thread_id: thread_id)
    puts "Messages on thread: #{messages}"

    # Create run (will use instruction/model/tools from Assistant's definition)
    response = @open_ai_client.runs.create(thread_id: thread_id,
    parameters: {
        assistant_id: assistant_id,
        max_prompt_tokens: 256,
        max_completion_tokens: 16
    })
    run_id = response['id']
    puts "Run created with ID: #{run_id}"



    while true do
        response = @open_ai_client.runs.retrieve(id: run_id, thread_id: thread_id)
        status = response['status']
    
        case status
        when 'queued', 'in_progress', 'cancelling'
          puts 'Sleeping'
          sleep 1 # Wait one second and poll again
        when 'completed'
          break # Exit loop and report result to user
        when 'requires_action'
          # Handle tool calls (see below)
        when 'cancelled', 'failed', 'expired'
          puts response['last_error'].inspect
          break # or `exit`
        else
          puts "Unknown status response: #{status}"
        end
    end
end

end
`
Expected behavior

  1. I should get a valid response
  2. https://platform.openai.com/playground/assistants, should have the assistant and the messages sent to it

Additional context
This code snippet is directly from the docs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions