Class: OmniAI::OpenAI::Thread::Text

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

Overview

An OpenAI text w/ annotations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:, client:) ⇒ Text

Returns a new instance of Text.

Parameters:



14
15
16
17
# File 'lib/omniai/openai/thread/text.rb', line 14

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

Instance Attribute Details

#dataHash?

Returns:

  • (Hash, nil)


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

def data
  @data
end

Instance Method Details

#annotate!String

Returns:

  • (String)


20
21
22
23
24
25
26
27
28
29
# File 'lib/omniai/openai/thread/text.rb', line 20

def annotate!
  text = value

  annotations.each do |annotation|
    file = annotation.file!
    text = text.gsub(annotation.text, "[#{file.filename}:#{annotation.range}]")
  end

  text
end

#annotationsArray<OmniAI::OpenAI::Thread::Annotation>



42
43
44
# File 'lib/omniai/openai/thread/text.rb', line 42

def annotations
  @annotations ||= @data['annotations'].map { |data| Annotation.new(data:, client: @client) }
end

#typeString

Returns e.g. “text”.

Returns:

  • (String)

    e.g. “text”



32
33
34
# File 'lib/omniai/openai/thread/text.rb', line 32

def type
  @data['type']
end

#valueString

Returns:

  • (String)


37
38
39
# File 'lib/omniai/openai/thread/text.rb', line 37

def value
  @data['value']
end