Class: OmniAI::OpenAI::Thread::Attachment

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

Overview

An OpenAI attachment.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:, client: Client.new) ⇒ Attachment

Returns a new instance of Attachment.

Parameters:



24
25
26
27
# File 'lib/omniai/openai/thread/attachment.rb', line 24

def initialize(data:, client: Client.new)
  @data = data
  @client = client
end

Instance Attribute Details

#dataHash?

Returns:

  • (Hash, nil)


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

def data
  @data
end

Class Method Details

.for(data:, client: Client.new) ⇒ Array<OmniAI::OpenAI::Thread::Content>, ...

Parameters:

Returns:



16
17
18
19
20
# File 'lib/omniai/openai/thread/attachment.rb', line 16

def self.for(data:, client: Client.new)
  return data unless data.is_a?(Enumerable)

  data.map { |attachment| new(data: attachment, client:) }
end

Instance Method Details

#file!OmniAI::OpenAI::File



40
41
42
# File 'lib/omniai/openai/thread/attachment.rb', line 40

def file!
  @file ||= @client.files.find(id: file_id)
end

#file_idString

Returns e.g. “text”.

Returns:

  • (String)

    e.g. “text”



30
31
32
# File 'lib/omniai/openai/thread/attachment.rb', line 30

def file_id
  @file_id ||= @data['file_id']
end

#toolsArray<Hash>

Returns:

  • (Array<Hash>)


35
36
37
# File 'lib/omniai/openai/thread/attachment.rb', line 35

def tools
  @tools ||= @data['tools']
end