Class: ChatgptRuby::Client
- Inherits:
-
Object
- Object
- ChatgptRuby::Client
- Defined in:
- lib/chatgpt/client.rb
Instance Method Summary collapse
-
#generate_response(prompt) ⇒ Object
Methods for accessing the API here.
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
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 |