Class: AmstradGpt::ChatGpt

Inherits:
Object
  • Object
show all
Defined in:
lib/amstrad_gpt/chat_gpt.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, prompt:) ⇒ ChatGpt

Returns a new instance of ChatGpt.



6
7
8
9
# File 'lib/amstrad_gpt/chat_gpt.rb', line 6

def initialize(api_key:, prompt:)
  @api_key = api_key
  @prompt = prompt
end

Instance Method Details

#messagesObject



18
19
20
# File 'lib/amstrad_gpt/chat_gpt.rb', line 18

def messages
  @messages ||= []
end

#send_message(content) ⇒ Object



11
12
13
14
15
16
# File 'lib/amstrad_gpt/chat_gpt.rb', line 11

def send_message(content)
  append({ role: 'user', content: })

  response = post
  parse_response(response.body)
end