langchainrb_rails 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c1e0233e3c6a9b90521be85e3ce43bb0eafab6f148cc5e7ce3183493d0be423
4
- data.tar.gz: 20e683575cbc95f361df5c642fdb922638d541ffbcb8018907a76305243b852b
3
+ metadata.gz: b792e1a7888a17c54fad522042ee7f6935df92e684119d4177f9627abb999dfd
4
+ data.tar.gz: 77444b9ed6d52443c890f045c121ba1a58f78b4d532954fc858e8c01999c90a7
5
5
  SHA512:
6
- metadata.gz: 310d63172807b8cb6fcb58056fce57800a6c074423b5cd880b6ca4fd9900b44f657b8bd7dfd39de8aefc30085a257c8467708a3afd4d6cbfafe3949f5970e5d6
7
- data.tar.gz: 5b721ba6d1801760779d94e66718f6de0e0e3b242814419fd4fc664b2ba335aa585b53de706d6e44176b1609f6ff7e5be8dc3c73b114bedd34cb7b99aa4f2fd7
6
+ metadata.gz: 5d26a5c5d4a10e6ea4794d809ceb15feb6262deb4754bfc12362e1e0e536b8643f46a9f98d464ae7372d6ef1b3d45ed34cf0d5e4c88977b135b4be1d982d5c85
7
+ data.tar.gz: '084a74842710d2b24db00e01344cbde645249671f4f975a9cc8f37763af53597e4cd3d2b5cd0f036320e181cbc20f8be8dca525279550529f9d58d8234fd601b'
data/Gemfile.lock CHANGED
@@ -1,25 +1,115 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- langchainrb_rails (0.1.0)
5
- langchainrb (~> 0.6.19)
4
+ langchainrb_rails (0.1.2)
5
+ langchainrb (~> 0.7.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ actioncable (7.1.1)
11
+ actionpack (= 7.1.1)
12
+ activesupport (= 7.1.1)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ zeitwerk (~> 2.6)
16
+ actionmailbox (7.1.1)
17
+ actionpack (= 7.1.1)
18
+ activejob (= 7.1.1)
19
+ activerecord (= 7.1.1)
20
+ activestorage (= 7.1.1)
21
+ activesupport (= 7.1.1)
22
+ mail (>= 2.7.1)
23
+ net-imap
24
+ net-pop
25
+ net-smtp
26
+ actionmailer (7.1.1)
27
+ actionpack (= 7.1.1)
28
+ actionview (= 7.1.1)
29
+ activejob (= 7.1.1)
30
+ activesupport (= 7.1.1)
31
+ mail (~> 2.5, >= 2.5.4)
32
+ net-imap
33
+ net-pop
34
+ net-smtp
35
+ rails-dom-testing (~> 2.2)
36
+ actionpack (7.1.1)
37
+ actionview (= 7.1.1)
38
+ activesupport (= 7.1.1)
39
+ nokogiri (>= 1.8.5)
40
+ rack (>= 2.2.4)
41
+ rack-session (>= 1.0.1)
42
+ rack-test (>= 0.6.3)
43
+ rails-dom-testing (~> 2.2)
44
+ rails-html-sanitizer (~> 1.6)
45
+ actiontext (7.1.1)
46
+ actionpack (= 7.1.1)
47
+ activerecord (= 7.1.1)
48
+ activestorage (= 7.1.1)
49
+ activesupport (= 7.1.1)
50
+ globalid (>= 0.6.0)
51
+ nokogiri (>= 1.8.5)
52
+ actionview (7.1.1)
53
+ activesupport (= 7.1.1)
54
+ builder (~> 3.1)
55
+ erubi (~> 1.11)
56
+ rails-dom-testing (~> 2.2)
57
+ rails-html-sanitizer (~> 1.6)
58
+ activejob (7.1.1)
59
+ activesupport (= 7.1.1)
60
+ globalid (>= 0.3.6)
61
+ activemodel (7.1.1)
62
+ activesupport (= 7.1.1)
63
+ activerecord (7.1.1)
64
+ activemodel (= 7.1.1)
65
+ activesupport (= 7.1.1)
66
+ timeout (>= 0.4.0)
67
+ activestorage (7.1.1)
68
+ actionpack (= 7.1.1)
69
+ activejob (= 7.1.1)
70
+ activerecord (= 7.1.1)
71
+ activesupport (= 7.1.1)
72
+ marcel (~> 1.0)
73
+ activesupport (7.1.1)
74
+ base64
75
+ bigdecimal
76
+ concurrent-ruby (~> 1.0, >= 1.0.2)
77
+ connection_pool (>= 2.2.5)
78
+ drb
79
+ i18n (>= 1.6, < 2)
80
+ minitest (>= 5.1)
81
+ mutex_m
82
+ tzinfo (~> 2.0)
10
83
  addressable (2.8.5)
11
84
  public_suffix (>= 2.0.2, < 6.0)
12
85
  ast (2.4.2)
13
86
  baran (0.1.9)
14
87
  base64 (0.1.1)
88
+ bigdecimal (3.1.4)
89
+ builder (3.2.4)
15
90
  byebug (11.1.3)
16
91
  coderay (1.1.3)
17
92
  colorize (0.8.1)
93
+ concurrent-ruby (1.2.2)
94
+ connection_pool (2.4.1)
95
+ crass (1.0.6)
96
+ date (3.3.3)
18
97
  diff-lcs (1.5.0)
98
+ drb (2.1.1)
99
+ ruby2_keywords
100
+ erubi (1.12.0)
101
+ globalid (1.2.1)
102
+ activesupport (>= 6.1)
103
+ i18n (1.14.1)
104
+ concurrent-ruby (~> 1.0)
105
+ io-console (0.6.0)
106
+ irb (1.8.3)
107
+ rdoc
108
+ reline (>= 0.3.8)
19
109
  json (2.6.3)
20
110
  json-schema (4.0.0)
21
111
  addressable (>= 2.8)
22
- langchainrb (0.6.19)
112
+ langchainrb (0.7.0)
23
113
  baran (~> 0.1.9)
24
114
  colorize (~> 0.8.1)
25
115
  json-schema (~> 4.0.0)
@@ -28,7 +118,31 @@ GEM
28
118
  zeitwerk (~> 2.5)
29
119
  language_server-protocol (3.17.0.3)
30
120
  lint_roller (1.1.0)
121
+ loofah (2.21.4)
122
+ crass (~> 1.0.2)
123
+ nokogiri (>= 1.12.0)
124
+ mail (2.8.1)
125
+ mini_mime (>= 0.1.1)
126
+ net-imap
127
+ net-pop
128
+ net-smtp
129
+ marcel (1.0.2)
31
130
  method_source (1.0.0)
131
+ mini_mime (1.1.5)
132
+ minitest (5.20.0)
133
+ mutex_m (0.1.2)
134
+ net-imap (0.4.2)
135
+ date
136
+ net-protocol
137
+ net-pop (0.1.2)
138
+ net-protocol
139
+ net-protocol (0.2.1)
140
+ timeout
141
+ net-smtp (0.4.0)
142
+ net-protocol
143
+ nio4r (2.5.9)
144
+ nokogiri (1.15.4-x86_64-darwin)
145
+ racc (~> 1.4)
32
146
  parallel (1.23.0)
33
147
  parser (3.2.2.4)
34
148
  ast (~> 2.4.1)
@@ -41,11 +155,54 @@ GEM
41
155
  pry-byebug (3.10.1)
42
156
  byebug (~> 11.0)
43
157
  pry (>= 0.13, < 0.15)
158
+ psych (5.1.1.1)
159
+ stringio
44
160
  public_suffix (5.0.3)
45
161
  racc (1.7.1)
162
+ rack (3.0.8)
163
+ rack-session (2.0.0)
164
+ rack (>= 3.0.0)
165
+ rack-test (2.1.0)
166
+ rack (>= 1.3)
167
+ rackup (2.1.0)
168
+ rack (>= 3)
169
+ webrick (~> 1.8)
170
+ rails (7.1.1)
171
+ actioncable (= 7.1.1)
172
+ actionmailbox (= 7.1.1)
173
+ actionmailer (= 7.1.1)
174
+ actionpack (= 7.1.1)
175
+ actiontext (= 7.1.1)
176
+ actionview (= 7.1.1)
177
+ activejob (= 7.1.1)
178
+ activemodel (= 7.1.1)
179
+ activerecord (= 7.1.1)
180
+ activestorage (= 7.1.1)
181
+ activesupport (= 7.1.1)
182
+ bundler (>= 1.15.0)
183
+ railties (= 7.1.1)
184
+ rails-dom-testing (2.2.0)
185
+ activesupport (>= 5.0.0)
186
+ minitest
187
+ nokogiri (>= 1.6)
188
+ rails-html-sanitizer (1.6.0)
189
+ loofah (~> 2.21)
190
+ nokogiri (~> 1.14)
191
+ railties (7.1.1)
192
+ actionpack (= 7.1.1)
193
+ activesupport (= 7.1.1)
194
+ irb
195
+ rackup (>= 1.0.0)
196
+ rake (>= 12.2)
197
+ thor (~> 1.0, >= 1.2.2)
198
+ zeitwerk (~> 2.6)
46
199
  rainbow (3.1.1)
47
200
  rake (13.0.6)
201
+ rdoc (6.5.0)
202
+ psych (>= 4.0.0)
48
203
  regexp_parser (2.8.2)
204
+ reline (0.3.9)
205
+ io-console (~> 0.5)
49
206
  rexml (3.2.6)
50
207
  rspec (3.12.0)
51
208
  rspec-core (~> 3.12.0)
@@ -78,6 +235,7 @@ GEM
78
235
  rubocop (>= 1.7.0, < 2.0)
79
236
  rubocop-ast (>= 0.4.0)
80
237
  ruby-progressbar (1.13.0)
238
+ ruby2_keywords (0.0.5)
81
239
  standard (1.31.2)
82
240
  language_server-protocol (~> 3.17.0.2)
83
241
  lint_roller (~> 1.0)
@@ -92,9 +250,18 @@ GEM
92
250
  rubocop-performance (~> 1.19.1)
93
251
  standardrb (1.0.1)
94
252
  standard
253
+ stringio (3.0.8)
254
+ thor (1.3.0)
95
255
  tiktoken_ruby (0.0.6-x86_64-darwin)
256
+ timeout (0.4.0)
257
+ tzinfo (2.0.6)
258
+ concurrent-ruby (~> 1.0)
96
259
  unicode (0.4.4.4)
97
260
  unicode-display_width (2.5.0)
261
+ webrick (1.8.1)
262
+ websocket-driver (0.7.6)
263
+ websocket-extensions (>= 0.1.0)
264
+ websocket-extensions (0.1.5)
98
265
  yard (0.9.34)
99
266
  zeitwerk (2.6.11)
100
267
 
@@ -105,6 +272,7 @@ DEPENDENCIES
105
272
  langchainrb
106
273
  langchainrb_rails!
107
274
  pry-byebug (~> 3.10.0)
275
+ rails (> 6.0.0)
108
276
  rake (~> 13.0)
109
277
  rspec (~> 3.0)
110
278
  standardrb
data/README.md CHANGED
@@ -4,8 +4,6 @@
4
4
 
5
5
  👨‍💻👩‍💻 CURRENTLY SEEKING PEOPLE TO FORM THE CORE GROUP OF MAINTAINERS WITH
6
6
 
7
- :warning: UNDER ACTIVE AND RAPID DEVELOPMENT (MAY BE BUGGY AND UNTESTED)
8
-
9
7
  ![Tests status](https://github.com/andreibondarev/langchainrb_rails/actions/workflows/ci.yml/badge.svg?branch=main)
10
8
  [![Gem Version](https://badge.fury.io/rb/langchainrb_rails.svg)](https://badge.fury.io/rb/langchainrb_rails)
11
9
  [![Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/gems/langchainrb_rails)
@@ -25,8 +23,19 @@ If bundler is not being used to manage dependencies, install the gem by executin
25
23
 
26
24
  gem install langchainrb_rails
27
25
 
28
- ## Usage
26
+ ## Rails Generators
27
+
28
+ ### Pinecone Generator - adds vectorsearch to your ActiveRecord model
29
29
 
30
- ```ruby
31
- require "langchainrb_rails"
32
30
  ```
31
+ rails generate langchainrb_rails:pinecone --model=Product --llm=openai
32
+ ```
33
+
34
+ Available `--llm` options: `cohere`, `google_palm`, `hugging_face`, `llama_cpp`, `ollama`, `openai`, and `replicate`. The selected LLM will be used to generate embeddings and completions.
35
+
36
+ The `--model` option is used to specify which ActiveRecord model vectorsearch capabilities will be added to.
37
+
38
+ Pinecone Generator does the following:
39
+ 1. Creates the `config/initializers/langchainrb_rails.rb` initializer file
40
+ 2. Adds necessary code to the ActiveRecord model to enable vectorsearch
41
+ 3. Adds `pinecone` gem to the Gemfile
@@ -9,12 +9,7 @@ module LangchainrbRails
9
9
  #
10
10
  # Usage:
11
11
  # class Recipe < ActiveRecord::Base
12
- # vectorsearch provider: Langchain::Vectorsearch::Weaviate.new(
13
- # api_key: ENV["WEAVIATE_API_KEY"],
14
- # url: ENV["WEAVIATE_URL"],
15
- # index_name: "Recipes",
16
- # llm: Langchain::LLM::OpenAI.new(api_key: ENV["OPENAI_API_KEY"])
17
- # )
12
+ # vectorsearch
18
13
  #
19
14
  # after_save :upsert_to_vectorsearch
20
15
  #
@@ -73,8 +68,8 @@ module LangchainrbRails
73
68
  # Set the vector search provider
74
69
  #
75
70
  # @param provider [Object] The `Langchain::Vectorsearch::*` instance
76
- def vectorsearch(provider:)
77
- class_variable_set(:@@provider, provider)
71
+ def vectorsearch
72
+ class_variable_set(:@@provider, LangchainrbRails.config.vectorsearch)
78
73
  end
79
74
 
80
75
  # Search for similar texts
@@ -109,4 +104,4 @@ module LangchainrbRails
109
104
  end
110
105
  end
111
106
  end
112
- end
107
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LangchainrbRails
4
+ class Config
5
+ # This class is used to configure the gem config inside Rails apps, in the `config/initializers/langchainrb_rails.rb` file.
6
+ #
7
+ # Langchain is configured in the following way:
8
+ # LangchainrbRails.configure do |config|
9
+ # config.vectorsearch = ...
10
+ # end
11
+ attr_accessor :vectorsearch
12
+
13
+ def initialize
14
+ # Define the defaults for future configuration here
15
+ @vectorsearch = {}
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,70 @@
1
+ require "rails/generators/active_record"
2
+
3
+ module LangchainrbRails
4
+ module Generators
5
+ #
6
+ # PineconeGenerator does the following:
7
+ # 1. Creates the `langchainrb_rails.rb` initializer file
8
+ # 2. Adds necessary code to the ActiveRecord model to enable vectorsearch
9
+ # 3. Adds `pinecone` gem to the Gemfile
10
+ #
11
+ # Usage:
12
+ # rails generate langchainrb_rails:pinecone --model=Product --llm=openai
13
+ #
14
+ class PineconeGenerator < Rails::Generators::Base
15
+ desc "This generator adds Pinecone vectorsearch integration to your ActiveRecord model"
16
+
17
+ include ::ActiveRecord::Generators::Migration
18
+ source_root File.join(__dir__, "templates")
19
+
20
+ class_option :model, type: :string, required: true, desc: "ActiveRecord Model to add vectorsearch to", aliases: "-m"
21
+ class_option :llm, type: :string, required: true, desc: "LLM provider that will be used to generate embeddings and completions"
22
+
23
+ # Available LLM providers to be passed in as --llm option
24
+ LLMS = {
25
+ "cohere" => "Langchain::LLM::Cohere",
26
+ "google_palm" => "Langchain::LLM::GooglePalm",
27
+ "hugging_face" => "Langchain::LLM::HuggingFace",
28
+ "llama_cpp" => "Langchain::LLM::LlamaCpp",
29
+ "ollama" => "Langchain::LLM::Ollama",
30
+ "openai" => "Langchain::LLM::OpenAI",
31
+ "replicate" => "Langchain::LLM::Replicate"
32
+ }
33
+
34
+ # Creates the `langchainrb_rails.rb` initializer file
35
+ def create_initializer_file
36
+ template "pinecone_initializer.rb", "config/initializers/langchainrb_rails.rb"
37
+ end
38
+
39
+ # Adds `vectorsearch` class method to the model and `after_save` callback that calls `upsert_to_vectorsearch()`
40
+ def add_to_model
41
+ inject_into_class "app/models/#{model_name.downcase}.rb", model_name do
42
+ " vectorsearch\n\n after_save :upsert_to_vectorsearch\n\n"
43
+ end
44
+ end
45
+
46
+ # Adds `pinecone` gem to the Gemfile
47
+ # TODO: Can we automatically run `bundle install`?
48
+ def add_to_gemfile
49
+ gem "pinecone"
50
+ end
51
+
52
+ private
53
+
54
+ # @return [String] Name of the model
55
+ def model_name
56
+ options["model"]
57
+ end
58
+
59
+ # @return [String] LLM provider to use
60
+ def llm
61
+ options["llm"]
62
+ end
63
+
64
+ # @return [Langchain::LLM::*] LLM class
65
+ def llm_class
66
+ Langchain::LLM.const_get(LLMS[llm])
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ LangchainrbRails.configure do |config|
4
+ config.vectorsearch = Langchain::Vectorsearch::Pinecone.new(
5
+ llm: <%= llm_class %>.new(api_key: ENV["<%= llm.upcase %>_API_KEY"]),
6
+ environment: "",
7
+ api_key: ENV["PINECONE_API_KEY"],
8
+ index_name: ""
9
+ )
10
+ end
@@ -7,5 +7,9 @@ module LangchainrbRails
7
7
  ::ActiveRecord::Base.include LangchainrbRails::ActiveRecord::Hooks
8
8
  end
9
9
  end
10
+
11
+ generators do
12
+ require_relative "generators/langchainrb_rails/pinecone_generator"
13
+ end
10
14
  end
11
15
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LangchainrbRails
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -3,11 +3,31 @@
3
3
  require "langchain"
4
4
  require_relative "langchainrb_rails/version"
5
5
  require "langchainrb_rails/railtie"
6
+ require "langchainrb_rails/config"
6
7
 
7
8
  module LangchainrbRails
8
9
  class Error < StandardError; end
9
-
10
+
10
11
  module ActiveRecord
11
12
  autoload :Hooks, "langchainrb_rails/active_record/hooks"
12
13
  end
14
+
15
+ module Generators
16
+ autoload :PgvectorGenerator, "langchainrb_rails/generators/langchainrb_rails/pgvector_generator"
17
+ end
18
+
19
+ class << self
20
+ # Configures global settings for LangchainrbRails
21
+ # LangchainrbRails.configure do |config|
22
+ # config.vectorsearch = ...
23
+ # end
24
+ def configure
25
+ yield(config)
26
+ end
27
+
28
+ # @return [Config] The global configuration object
29
+ def config
30
+ @_config ||= Config.new
31
+ end
32
+ end
13
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: langchainrb_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Bondarev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-23 00:00:00.000000000 Z
11
+ date: 2023-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: langchainrb
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.19
19
+ version: 0.7.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.6.19
26
+ version: 0.7.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pry-byebug
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.9.34
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">"
60
+ - !ruby/object:Gem::Version
61
+ version: 6.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">"
67
+ - !ruby/object:Gem::Version
68
+ version: 6.0.0
55
69
  description: Rails wrapper for langchainrb gem
56
70
  email:
57
71
  - andrei.bondarev13@gmail.com
@@ -68,6 +82,9 @@ files:
68
82
  - Rakefile
69
83
  - lib/langchainrb_rails.rb
70
84
  - lib/langchainrb_rails/active_record/hooks.rb
85
+ - lib/langchainrb_rails/config.rb
86
+ - lib/langchainrb_rails/generators/langchainrb_rails/pinecone_generator.rb
87
+ - lib/langchainrb_rails/generators/langchainrb_rails/templates/pinecone_initializer.rb.tt
71
88
  - lib/langchainrb_rails/railtie.rb
72
89
  - lib/langchainrb_rails/version.rb
73
90
  - sig/langchainrb_rails.rbs