Class: OxAiWorkers::ImageIterator

Inherits:
Object
  • Object
show all
Defined in:
lib/oxaiworkers/image_iterator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worker:, on_inner_monologue: nil, on_outer_voice: nil, on_finish: nil) ⇒ ImageIterator

Returns a new instance of ImageIterator.



7
8
9
10
11
12
# File 'lib/oxaiworkers/image_iterator.rb', line 7

def initialize(worker:, on_inner_monologue: nil, on_outer_voice: nil, on_finish: nil)
  @worker = worker
  @on_inner_monologue = on_inner_monologue
  @on_outer_voice = on_outer_voice
  @on_finish = on_finish
end

Instance Attribute Details

#on_finishObject

Returns the value of attribute on_finish.



5
6
7
# File 'lib/oxaiworkers/image_iterator.rb', line 5

def on_finish
  @on_finish
end

#on_inner_monologueObject

Returns the value of attribute on_inner_monologue.



5
6
7
# File 'lib/oxaiworkers/image_iterator.rb', line 5

def on_inner_monologue
  @on_inner_monologue
end

#on_outer_voiceObject

Returns the value of attribute on_outer_voice.



5
6
7
# File 'lib/oxaiworkers/image_iterator.rb', line 5

def on_outer_voice
  @on_outer_voice
end

#taskObject

Returns the value of attribute task.



5
6
7
# File 'lib/oxaiworkers/image_iterator.rb', line 5

def task
  @task
end

#workerObject

Returns the value of attribute worker.



5
6
7
# File 'lib/oxaiworkers/image_iterator.rb', line 5

def worker
  @worker
end

Instance Method Details

#add_task(task) ⇒ Object



37
38
39
# File 'lib/oxaiworkers/image_iterator.rb', line 37

def add_task(task)
  @task = task
end

#cleanupObject



33
34
35
# File 'lib/oxaiworkers/image_iterator.rb', line 33

def cleanup
  @worker.cleanup
end

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/oxaiworkers/image_iterator.rb', line 14

def execute
  response = @worker.client.images.generate(
    parameters: {
      prompt: @task,
      model: 'dall-e-3',
      size: '1024x1792',
      quality: 'standard'
    }
  )

  url = response.dig('data', 0, 'url')
  puts url
  puts response.inspect
  @on_inner_monologue&.call(text: I18n.t('oxaiworkers.iterator.image_iterator.url', url:))
  @on_outer_voice&.call(text: url)
  @on_finish&.call(result: url)
  response
end