alexshapalov/rubyai

Add configuration class

Closed this issue · 2 comments

Add and extract the configuration class where we add all setups.

We can see as an example lib/open.rb, we need to add on y main attributes like:

  class Configuration
    attr_writer :access_token

    attr_accessor :api_type, :api_version, :organization_id, :uri_base, :request_timeout

...

We can put this file in lib/configuration.rb and use it in the main class.

require_relative "configuration"

# conf = Configuration.new("api_key")

# p conf.model

module RubyAI
  # class << self
  #   attr_writer :configuration
  # end

  def self.configuration
    @configuration ||= Configuration.new("api_key")
  end

  def self.call
    @configuration
  end

  def self.configure
    yield(configuration)
  end
end


p RubyAI.configuration

# Configure RubyAI

# p RubyAI::Configuration.new("api_key")

RubyAI.configure do |config|
  p config.api_key = 'new value for api_key 1'
  p config.model = 'new value for model 2'
end

p RubyAI::Client.new("api_key")
class Configuration
  # attr_reader :api_key

  attr_accessor :model, :messages, :temperature, :api_version, :api_key

  BASE_URL = "https://api.openai.com/v1/chat/completions"

  DEFAULT_API_VERSION = "v1"

  MODELS = {
    "gpt-4" => "gpt-4",
    "gpt-4-0314" => "gpt-4-0314",
    "gpt-4-32k" => "gpt-4-32k",
    "gpt-3.5-turbo" => "gpt-3.5-turbo",
    "gpt-3.5-turbo-0301" => "gpt-3.5-turbo-0301",
    "text-davinci-003" => "text-davinci-003"
  }

  DEFAULT_MODEL = "gpt-3.5-turbo"

  def initialize(api_key, model = DEFAULT_MODEL)
    @api_key = nil
    @model = model
    @api_version = DEFAULT_API_VERSION
  end
end

conf = Configuration.new("api_key")

p conf.model