Skip to content

Conversation

@Reion19
Copy link

@Reion19 Reion19 commented Jun 30, 2025

[ ✅ ] Have you followed the guidelines in our Contributing document?
[ ✅ ] Have you checked to ensure there aren't other open Pull Requests for the same update/change?
[ ✅ ] Have you added an explanation of what your changes do and why you'd like us to include them?


Summary:

  • Fixed critical bugs in the configuration that were affecting the correct behavior of the gem.
  • Rewrote the specs to match the current configuration logic.

Notes:

  • All specs are now passing.
  • Changes are mostly backward-compatible with the current version of the gem.

@Reion19 Reion19 changed the title fixed critical but in configuration and add specs fixed critical bug in configuration and add specs Jul 1, 2025
attr_accessor :openai,
:anthropic,
:gemini,
# default api config accessors
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not add comments inside the params

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, roger that, that comment will be removed

:temperature,
:provider

PROVIDERS = {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add providers in the top

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll move the providers to the top of the file for better organization.

module Provider
PROVIDERS = {
"openai" => RubyAI::Providers::OpenAI,
# doesn't tested yet because i don't have an anthropic api key
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not add comments like this inside code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, I'll remove all comments like this. Thanks!

@@ -0,0 +1,55 @@
module RubyAI
module Providers
# doesn't tested yet because i don't have an anthropic api key
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not add comments like this inside code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, I’ll remove the comment from the code. Thanks!


attr_accessor :api, :messages, :temperature, :max_tokens, :model

# TODO: make an initialization for separate instances for using multiple of them
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not add any To-do in comments!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can open a new ticket/issue

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood! I’ll remove the TODO comment and create an issue/ticket. Thanks!

require_relative "rubyai/providers/openai"
require_relative "rubyai/providers/anthropic"
require_relative "rubyai/providers/gemini"
require_relative "rubyai/provider"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this also?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, could you please specify what part you mean? I’m not sure what you're referring to.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need require require_relative "rubyai/provider"
if we have required all of them directly?

:temperature,
:provider

PROVIDERS = {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we can use the module Provider.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I agree.

i will update it

def self.configuration
@configuration ||= Configuration.new
end
def initialize(config = nil)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many variables inside the initialize. Should be <5

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I’ll refactor the initialize method.

@a1xsh
Copy link

a1xsh commented Jul 4, 2025

As well

Screenshot 2025-07-04 at 15 20 27
 lib/rubyai.rb

    Entry point. Requires all other files.

require "rubyai/version"
require "rubyai/configuration"
require "rubyai/client"
require "rubyai/chat"
require "rubyai/http"
require "rubyai/provider"
require "rubyai/providers/base"
require "rubyai/providers/openai"
require "rubyai/providers/anthropic"
require "rubyai/providers/gemini"

Configuration

All global configuration, e.g. API keys, default provider, timeouts.
  • provider.rb is the abstract base class or module for all providers.
  • providers/base.rb is optional, but some like a clean separation for all common logic.
  • Each provider lives in its own file in providers/.
  • The main client can dynamically select a provider based on user config.
# lib/rubyai/providers/base.rb
module RubyAI
  module Providers
    class Base
      def initialize(options = {})
        # set up keys, etc.
      end

      def chat(messages:, **opts)
        raise NotImplementedError
      end

      # Optionally define common helper methods
    end
  end
end
# lib/rubyai/providers/openai.rb
module RubyAI
  module Providers
    class OpenAI < Base
      def chat(messages:, **opts)
        # OpenAI-specific logic
      end
    end
  end
end

client.rb acts as the main user entry point, initializes the provider, delegates requests.

module RubyAI
  class Client
    def initialize(provider: :openai, **opts)
      @provider = build_provider(provider, opts)
    end

    def chat(messages:, **opts)
      @provider.chat(messages: messages, **opts)
    end

    private

    def build_provider(provider, opts)
      case provider.to_sym
      when :openai then Providers::OpenAI.new(opts)
      when :anthropic then Providers::Anthropic.new(opts)
      when :gemini then Providers::Gemini.new(opts)
      # Add more as needed
      else
        raise ArgumentError, "Unknown provider: #{provider}"
      end
    end
  end
end

Configuration


RubyAI.configure do |config|
  config.api_key = ENV["OPENAI_API_KEY"]
  config.default_provider = :openai
  # etc.
end

@Reion19
Copy link
Author

Reion19 commented Jul 8, 2025

I have a few questions:

  1. Which logic should be placed inside the chat.rb file?

  2. Currently, we can chat with different providers via RubyAI::Client or RubyAI::Chat.
    Do we need to move the chat logic into the providers' logic, or is it better to keep it as it is now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants