Class: RubyAI::Client
- Inherits:
-
Object
- Object
- RubyAI::Client
- Defined in:
- lib/rubyai.rb
Constant Summary collapse
- BASE_URL =
URI.parse("https://api.openai.com/v1/chat/completions")
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#model ⇒ Object
Returns the value of attribute model.
-
#temperature ⇒ Object
Returns the value of attribute temperature.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(api_key, messages, temperature: 0.7, model: "gpt-3.5-turbo") ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(api_key, messages, temperature: 0.7, model: "gpt-3.5-turbo") ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 |
# File 'lib/rubyai.rb', line 11 def initialize(api_key, , temperature: 0.7, model: "gpt-3.5-turbo") @api_key = api_key @messages = @model = model @temperature = temperature end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
18 19 20 |
# File 'lib/rubyai.rb', line 18 def api_key @api_key end |
#messages ⇒ Object
Returns the value of attribute messages.
18 19 20 |
# File 'lib/rubyai.rb', line 18 def @messages end |
#model ⇒ Object
Returns the value of attribute model.
18 19 20 |
# File 'lib/rubyai.rb', line 18 def model @model end |
#temperature ⇒ Object
Returns the value of attribute temperature.
18 19 20 |
# File 'lib/rubyai.rb', line 18 def temperature @temperature end |
Instance Method Details
#call ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/rubyai.rb', line 20 def call response = Net::HTTP.start(BASE_URL.host, BASE_URL.port, use_ssl: true) do |http| request = Net::HTTP::Post.new(BASE_URL.request_uri, header) request.body = body.to_json http.request(request) end JSON.parse(response.body) end |