Sha256: 6a6c925610b02132b9527b21063521cd3ecf59e1eb2e39cd8ad94af92f6a0be1

Contents?: true

Size: 648 Bytes

Versions: 2

Compression:

Stored size: 648 Bytes

Contents

module RubyAI
  class Client
    attr_reader :configuration

    def initialize(config_hash = {})
      @configuration = Configuration.new(config_hash)
    end

    def call
      response = connection.post do |req|
        req.url Configuration::BASE_URL
        req.headers.merge!(HTTP.build_headers(configuration.api_key))
        req.body = HTTP.build_body(configuration.messages, configuration.model, configuration.temperature).to_json
      end

      JSON.parse(response.body)
    end

    private

    def connection
      @connection ||= Faraday.new do |faraday|
        faraday.adapter Faraday.default_adapter
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubyai-0.5 lib/rubyai/client.rb
rubyai-0.4 lib/rubyai/client.rb