Class: LangchainrbRails::Generators::BaseGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
ActiveRecord::Generators::Migration
Defined in:
lib/langchainrb_rails/generators/langchainrb_rails/base_generator.rb

Constant Summary collapse

LLMS =

Available LLM providers to be passed in as –llm option

{
  "anthropic" => "Langchain::LLM::Anthropic",
  "cohere" => "Langchain::LLM::Cohere",
  "google_palm" => "Langchain::LLM::GooglePalm",
  "google_gemini" => "Langchain::LLM::GoogleGemini",
  "google_vertex_ai" => "Langchain::LLM::GoogleVertexAI",
  "hugging_face" => "Langchain::LLM::HuggingFace",
  "llama_cpp" => "Langchain::LLM::LlamaCpp",
  "mistral_ai" => "Langchain::LLM::MistralAI",
  "ollama" => "Langchain::LLM::Ollama",
  "openai" => "Langchain::LLM::OpenAI",
  "replicate" => "Langchain::LLM::Replicate"
}.freeze

Instance Method Summary collapse

Instance Method Details

#after_generateObject

Run bundle install after running the generator



40
41
42
# File 'lib/langchainrb_rails/generators/langchainrb_rails/base_generator.rb', line 40

def after_generate
  run "bundle install"
end

#post_install_messageObject



44
45
46
47
48
49
50
51
# File 'lib/langchainrb_rails/generators/langchainrb_rails/base_generator.rb', line 44

def post_install_message
  say "Please do the following to start Q&A with your #{model_name} records:", :green
  say "1. Run `bundle install` to install the new gems."
  say "2. Set an environment variable ENV['#{llm.upcase}_API_KEY'] for your #{llm_class}."
  say "3. Run `rails db:migrate` to apply the database migrations to enable pgvector and add the embedding column."
  say "4. In Rails console, run `#{model_name}.embed!` to set the embeddings for all records."
  say "5. Ask a question in the Rails console, ie: `#{model_name}.ask('[YOUR QUESTION]')`"
end