Class: OpenAI::Client
- Inherits:
-
Object
- Object
- OpenAI::Client
- Defined in:
- lib/openai_ruby/client.rb
Constant Summary collapse
- BASE_URL =
"https://api.openai.com"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #create_chat_completion(params = {}) ⇒ Object
- #create_completion(params = {}) ⇒ Object
- #create_edit(params = {}) ⇒ Object
- #images ⇒ Object
-
#initialize(api_key, options = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(api_key, options = {}) ⇒ Client
Returns a new instance of Client.
9 10 11 12 |
# File 'lib/openai_ruby/client.rb', line 9 def initialize(api_key, = {}) @api_key = api_key @options = end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/openai_ruby/client.rb', line 7 def api_key @api_key end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/openai_ruby/client.rb', line 7 def @options end |
Instance Method Details
#create_chat_completion(params = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/openai_ruby/client.rb', line 22 def create_chat_completion(params = {}) params.deep_stringify_keys! if params["stream"] connection.post("/v1/chat/completions") do |req| req.body = params.to_json req..on_data = proc do |chunk, overall_received_bytes, env| yield(chunk, overall_received_bytes, env) if block_given? end end else connection.post("/v1/chat/completions", params.to_json) end end |
#create_completion(params = {}) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/openai_ruby/client.rb', line 14 def create_completion(params = {}) Faraday.post( "#{BASE_URL}/v1/completions", params.to_json, headers ) end |
#create_edit(params = {}) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/openai_ruby/client.rb', line 36 def create_edit(params = {}) Faraday.post( "#{BASE_URL}/v1/edits", params.to_json, headers ) end |