|
1 | | -require "rails/generators/active_record" |
| 1 | +# frozen_string_literal: true |
2 | 2 |
|
3 | 3 | module LangchainrbRails |
4 | 4 | module Generators |
5 | 5 | # |
6 | 6 | # Usage: |
7 | 7 | # rails g langchain:pgvector -model=Product -llm=openai |
8 | 8 | # |
9 | | - class PgvectorGenerator < Rails::Generators::Base |
| 9 | + class PgvectorGenerator < LangchainrbRails::Generators::BaseGenerator |
10 | 10 | desc "This generator adds Pgvector vectorsearch integration to your ActiveRecord model" |
11 | | - |
12 | | - include ::ActiveRecord::Generators::Migration |
13 | 11 | source_root File.join(__dir__, "templates") |
14 | 12 |
|
15 | | - class_option :model, type: :string, required: true, desc: "ActiveRecord Model to add vectorsearch to", aliases: "-m" |
16 | | - class_option :llm, type: :string, required: true, desc: "LLM provider that will be used to generate embeddings and completions" |
17 | | - |
18 | | - LLMS = { |
19 | | - "cohere" => "Langchain::LLM::Cohere", |
20 | | - "google_palm" => "Langchain::LLM::GooglePalm", |
21 | | - "hugging_face" => "Langchain::LLM::HuggingFace", |
22 | | - "llama_cpp" => "Langchain::LLM::LlamaCpp", |
23 | | - "ollama" => "Langchain::LLM::Ollama", |
24 | | - "openai" => "Langchain::LLM::OpenAI", |
25 | | - "replicate" => "Langchain::LLM::Replicate" |
26 | | - } |
27 | | - |
28 | 13 | def copy_migration |
29 | 14 | migration_template "enable_vector_extension_template.rb", "db/migrate/enable_vector_extension.rb", migration_version: migration_version |
30 | 15 | migration_template "add_vector_column_template.rb", "db/migrate/add_vector_column_to_#{table_name}.rb", migration_version: migration_version |
|
0 commit comments