Class: Hyrum::Generators::OpenaiGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/hyrum/generators/openai_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ OpenaiGenerator



12
13
14
# File 'lib/hyrum/generators/openai_generator.rb', line 12

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/hyrum/generators/openai_generator.rb', line 10

def options
  @options
end

Instance Method Details

#generateObject



16
17
18
19
20
21
22
23
# File 'lib/hyrum/generators/openai_generator.rb', line 16

def generate
  configure

  response = chat_response
  puts "OpenAI response: #{JSON.pretty_generate(response)}" if options[:verbose]
  content = response.dig('choices', 0, 'message', 'content')
  JSON.parse(content)
end