Class: OmniAI::OpenAI::Thread::Messages

Inherits:
Object
  • Object
show all
Defined in:
lib/omniai/openai/thread/messages.rb

Overview

An OpenAI scope for establishing messages.

Instance Method Summary collapse

Constructor Details

#initialize(client:, thread:) ⇒ Messages

Returns a new instance of Messages.

Parameters:



10
11
12
13
# File 'lib/omniai/openai/thread/messages.rb', line 10

def initialize(client:, thread:)
  @client = client
  @thread = thread
end

Instance Method Details

#all(limit: nil) ⇒ Array<OmniAI::Thread::Message>

Parameters:

  • limit (Integer) (defaults to: nil)

    optional

Returns:

  • (Array<OmniAI::Thread::Message>)


17
18
19
# File 'lib/omniai/openai/thread/messages.rb', line 17

def all(limit: nil)
  Message.all(thread_id: @thread.id, limit:, client: @client)
end

#build(role: nil, content: nil, attachments: [], metadata: {}) ⇒ OmniAI::OpenAI::Thread::Message

Parameters:

  • role (String, nil) (defaults to: nil)

    optional

  • content (String, Array, nil) (defaults to: nil)

    optional

  • attachments (Array, nil) (defaults to: [])

    optional

  • metadata (Hash, nil) (defaults to: {})

    optional

Returns:



38
39
40
# File 'lib/omniai/openai/thread/messages.rb', line 38

def build(role: nil, content: nil, attachments: [], metadata: {})
  Message.new(role:, content:, attachments:, metadata:, thread_id: @thread.id, client: @client)
end

#destroy!(id:) ⇒ Hash

Parameters:

  • id (String)

    required

Returns:

  • (Hash)


29
30
31
# File 'lib/omniai/openai/thread/messages.rb', line 29

def destroy!(id:)
  Message.destroy!(id:, thread_id: @thread.id, client: @client)
end

#find(id:) ⇒ OmniAI::OpenAI::Thread::Message

Parameters:

  • id (String)

    required

Returns:



23
24
25
# File 'lib/omniai/openai/thread/messages.rb', line 23

def find(id:)
  Message.find(id:, thread_id: @thread.id, client: @client)
end