Class: LangchainrbRails::Generators::ChromaGenerator
- Inherits:
-
BaseGenerator
- Object
- Rails::Generators::Base
- BaseGenerator
- LangchainrbRails::Generators::ChromaGenerator
- Defined in:
- lib/langchainrb_rails/generators/langchainrb_rails/chroma_generator.rb
Overview
ChromaGenerator does the following:
-
Creates the ‘langchainrb_rails.rb` initializer file
-
Adds necessary code to the ActiveRecord model to enable vectorsearch
-
Adds ‘chroma-db` gem to the Gemfile
Usage:
rails generate langchainrb_rails:chrome --model=Product --llm=openai
Constant Summary
Constants inherited from BaseGenerator
Instance Method Summary collapse
-
#add_to_gemfile ⇒ Object
Adds ‘chroma-db` gem to the Gemfile.
-
#add_to_model ⇒ Object
Adds ‘vectorsearch` class method to the model and `after_save` callback that calls `upsert_to_vectorsearch()`.
-
#create_initializer_file ⇒ Object
Creates the ‘langchainrb_rails.rb` initializer file.
Methods inherited from BaseGenerator
#after_generate, #post_install_message
Instance Method Details
#add_to_gemfile ⇒ Object
Adds ‘chroma-db` gem to the Gemfile
31 32 33 |
# File 'lib/langchainrb_rails/generators/langchainrb_rails/chroma_generator.rb', line 31 def add_to_gemfile gem "chroma-db" end |
#add_to_model ⇒ Object
Adds ‘vectorsearch` class method to the model and `after_save` callback that calls `upsert_to_vectorsearch()`
24 25 26 27 28 |
# File 'lib/langchainrb_rails/generators/langchainrb_rails/chroma_generator.rb', line 24 def add_to_model inject_into_class "app/models/#{model_name.downcase}.rb", model_name do " vectorsearch\n\n after_save :upsert_to_vectorsearch\n\n" end end |
#create_initializer_file ⇒ Object
Creates the ‘langchainrb_rails.rb` initializer file
19 20 21 |
# File 'lib/langchainrb_rails/generators/langchainrb_rails/chroma_generator.rb', line 19 def create_initializer_file template "chroma_initializer.rb", "config/initializers/langchainrb_rails.rb" end |