Class: Mj::ChatGpt::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/mj/chatgpt/request.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Request

Returns a new instance of Request.



6
7
8
# File 'lib/mj/chatgpt/request.rb', line 6

def initialize(data = {})
  @data = HashUtils.new.deep_symbolize_keys(data)
end

Class Method Details

.from_config_file(file) ⇒ Object



25
26
27
28
# File 'lib/mj/chatgpt/request.rb', line 25

def self.from_config_file(file)
  data = YAML.load_file(file)
  new(data.fetch("request"))
end

Instance Method Details

#asking(question) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/mj/chatgpt/request.rb', line 10

def asking(question)
  data = @data.dup
  data[:parameters] ||= {}
  data[:parameters][:messages] ||= []
  data[:parameters][:messages] << {
    role: :user,
    content: question
  }
  self.class.new(data)
end

#to_hObject



21
22
23
# File 'lib/mj/chatgpt/request.rb', line 21

def to_h
  @data
end