Class: ChatgptRuby::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Client

Returns a new instance of Client.



7
8
9
10
# File 'lib/chatgpt/client.rb', line 7

def initialize(api_key)
  @api_key = api_key
  @endpoint = 'https://api.chatgpt.com'
end

Instance Method Details

#generate_response(prompt) ⇒ Object

Methods for accessing the API here



13
14
15
16
17
18
19
20
21
# File 'lib/chatgpt/client.rb', line 13

def generate_response(prompt)
  url = "#{@endpoint}/generate"
  params = {
    prompt: prompt,
    api_key: @api_key
  }
  response = RestClient.get(url, params: params)
  JSON.parse(response.body)
end