Skip to content

Conversation

@lemingos
Copy link
Contributor

@lemingos lemingos commented Jun 6, 2025

Convert LangchainRB to a Rails Engine

Description

This PR transforms LangchainRB from a plain Ruby gem into a full-fledged Rails::Engine, enabling tighter Rails integration and better support for Rails applications.

Key Changes

1. Added Rails Engine Structure

  • Created Langchain::Engine class inheriting from Rails::Engine
  • Set up proper autoloading and eager loading paths
  • Isolated the engine namespace to prevent conflicts
  • add Response namespace to classes located in lib/langchain/llm/response directory

2. Rails Integration

  • Added rails as a runtime dependency in gemspec
  • Set up test/dummy Rails application for integration testing

3. Testing Infrastructure

  • Added rspec-rails for Rails-specific testing
  • Added Rails-specific test helpers and configurations

Benefits

  • Namespace isolation all classas are now scoped to Langchain
  • Better Rails Integration: Seamless integration with Rails applications
  • Easier Configuration: Standard Rails initializers and configurations
  • Improved Testing: Better test coverage with Rails integration tests
  • Future Extensibility: Foundation for adding persistance layer

Breaking Changes

  • This change makes Rails a required dependency

Testing

  • All existing tests pass

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Convert the LangchainRB gem into a Rails Engine for tighter Rails integration and namespaced response classes.

  • Introduced a Rails::Engine and ApplicationRecord for engine structure and autoloading.
  • Refactored all LLM adapter response classes under Langchain::LLM::Response namespace.
  • Updated gemspec, Gemfile, Rakefile, and test/setup files for Rails dependency and dummy app testing.

@lemingos lemingos force-pushed the refactor-to-engine branch from 08f8a8d to d96b1d9 Compare June 8, 2025 14:55
@lemingos lemingos force-pushed the refactor-to-engine branch from d96b1d9 to d58dc2a Compare June 8, 2025 15:32
@andreibondarev andreibondarev merged commit e1b9f39 into patterns-ai-core:main Jun 10, 2025
6 checks passed
@mvz
Copy link

mvz commented Jul 2, 2025

This makes langchainrb depend on Rails. Is that intentional and what will the relation be with langchainrb_rails? I'm currently using langchainrb in contexts that do not involve Rails at all.

@ebababi
Copy link

ebababi commented Jul 25, 2025

For what it's worth, we were also using langchainrb in contexts that don't involve Rails at all. As already mentioned, shouldn't this tighter Rails integration be part of langchainrb_rails?

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.

4 participants