Class: OpenAI::AssistantClient

Inherits:
RestBase
  • Object
show all
Defined in:
lib/openai/assistant_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ AssistantClient

Returns a new instance of AssistantClient.



10
11
12
# File 'lib/openai/assistant_client.rb', line 10

def initialize(api_key)
  @api_key = api_key
end

Instance Method Details

#get_assistant_by_id(assistant_id) ⇒ Object

Get assistant details by assistant_id

Parameters:

  • @required

    assistant_id The ID of the assistant to retrieve.



31
32
33
34
# File 'lib/openai/assistant_client.rb', line 31

def get_assistant_by_id(assistant_id)
  api_response = call_get("/assistants/#{assistant_id}")
  Model::Assistant.new(api_response)
end

#get_list_assistants(limit = 20, order = SortOrder::ASC, after = nil, before = nil) ⇒ Object

Get list assistants

Parameters:

  • limit (defaults to: 20)

    A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.

  • order (defaults to: SortOrder::ASC)

    Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.

  • after (defaults to: nil)

    A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.

  • before (defaults to: nil)

    A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.

Returns:

  • A list of [OpenAIAssistant::Model::Assistant] objects.



21
22
23
24
25
26
# File 'lib/openai/assistant_client.rb', line 21

def get_list_assistants(limit = 20, order = SortOrder::ASC, after = nil, before = nil)
  api_response = call_get('/assistants', {
    'limit' => limit, 'order' => order, 'after' => after, 'before' => before
  }.select { |_,v| !v.nil? })
  Model::ListAssistants.new(api_response)
end

#get_list_messages_by_thread_id(thread_id, limit = 20, order = SortOrder::DESC, after = nil, before = nil, run_id = nil) ⇒ Object

Returns a list of messages for a given thread.

Parameters:

  • @required

    thread_id The ID of the thread the messages belong to.

  • limit (defaults to: 20)

    A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.

  • order (defaults to: SortOrder::DESC)

    Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.

  • after (defaults to: nil)

    A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.

  • before (defaults to: nil)

    A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.

  • run_id (defaults to: nil)

    Filter messages by the run ID that generated them.

Returns:

  • A list of [OpenAIAssistant::Model::Message] objects.



53
54
55
56
57
58
# File 'lib/openai/assistant_client.rb', line 53

def get_list_messages_by_thread_id(thread_id, limit = 20, order = SortOrder::DESC, after = nil, before = nil, run_id = nil)
  api_response = call_get("/threads/#{thread_id}/messages", {
    'limit' => limit, 'order' => order, 'after' => after, 'before' => before, 'run_id' => run_id
  }.select { |_,v| !v.nil? })
  Model::ListMessages.new(api_response)
end

#get_run_status_by_thead_id_and_run_id(thread_id, run_id) ⇒ Object

Retrieves a run status by thread_id and run_id

Parameters:

  • @required

    thread_id The ID of the thread that was run.

  • @required

    run_id The ID of the run to retrieve.



40
41
42
43
# File 'lib/openai/assistant_client.rb', line 40

def get_run_status_by_thead_id_and_run_id(thread_id, run_id)
  api_response = call_get("/threads/#{thread_id}/runs/#{run_id}")
  Model::Run.new(api_response)
end