Class: OmniAI::OpenAI::Thread::Content

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

Overview

An OpenAI content w/ annotations.

Defined Under Namespace

Modules: Type

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:, client:) ⇒ Content

Returns a new instance of Content.

Parameters:

  • data (Hash)


27
28
29
30
# File 'lib/omniai/openai/thread/content.rb', line 27

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

Instance Attribute Details

#dataHash?

Returns:

  • (Hash, nil)


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

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/content.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

#textOmniAI::OpenAI::Thread::Text



43
44
45
# File 'lib/omniai/openai/thread/content.rb', line 43

def text
  @text ||= Text.new(data: @data['text'], client: @client) if @data['text']
end

#text?Boolean

Returns:

  • (Boolean)


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

def text?
  type.eql?(Type::TEXT)
end

#typeString

Returns e.g. “text”.

Returns:

  • (String)

    e.g. “text”



33
34
35
# File 'lib/omniai/openai/thread/content.rb', line 33

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