langchainrb 0.6.19 → 0.7.0

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: d7be5e031274fba7a4c0d7fc2cd3f472ed83fb66d8c6b355fb71fbf69a825b73
4
- data.tar.gz: 745cbc4f3d7b569d2e1407acc8be123f77a0aac2964840d7c3dca215592811ee
3
+ metadata.gz: 4efc896c1c0fa895ebd11bdb3c4d5604ccd34878aa29472419efca85800072da
4
+ data.tar.gz: c703f8150c7a6a6cb802260da2eeb95d4f7542cc0c5490794cea844351b4fe7c
5
5
  SHA512:
6
- metadata.gz: e1392abe2fc0c4928593bd77d0e62688e3959ec39fd3f7bb5effc784b47599402c611ecc545868178b5d04ec688d68d6406f220697e8bfe40771cc593292a192
7
- data.tar.gz: 926bccf20c71af3d31d942cf439336df9edc489a8e5e0359a6c24bb26e5b818be048a7ef63ebcce721bb99392b49e407288ffdd7387dd33d3f0161e92ff6e045
6
+ metadata.gz: 18b0c48b747978b2a92ecd8d118f31b199d5f58469a5dd55ccbfc3a56a9044faf42784e4760ff9a9fca94da019107629c107a3fe586b7d55243aa92bd1c5b949
7
+ data.tar.gz: d8513d2018ce48a60fbecc9ca3efb91411385fd71301e0c79ac3612d91b2b504427f2ea19b41991f2f4b43a8bd3b650035684b02a46ae0b114d83343ef5bce18
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.7.0] - 2023-10-22
4
+ - BREAKING: Moving Rails-specific code to `langchainrb_rails` gem
5
+
3
6
  ## [0.6.19] - 2023-10-18
4
7
  - Elasticsearch vector search support
5
8
  - Fix `lib/langchain/railtie.rb` not being loaded with the gem
@@ -152,7 +152,3 @@ module Langchain::Vectorsearch
152
152
  end
153
153
  end
154
154
  end
155
-
156
- # Rails connection when configuring vectorsearch
157
- # Update READMEs
158
- # Rails migration to create a migration
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Langchain
4
- VERSION = "0.6.19"
4
+ VERSION = "0.7.0"
5
5
  end
data/lib/langchain.rb CHANGED
@@ -89,5 +89,3 @@ module Langchain
89
89
  class BaseError < StandardError; end
90
90
  end
91
91
  end
92
-
93
- require "langchain/railtie" if defined?(Rails)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: langchainrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.19
4
+ version: 0.7.0
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-18 00:00:00.000000000 Z
11
+ date: 2023-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: baran
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: zeitwerk
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '='
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 2.6.11
75
+ version: '2.5'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '='
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 2.6.11
82
+ version: '2.5'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pragmatic_segmenter
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -539,7 +539,6 @@ files:
539
539
  - LICENSE.txt
540
540
  - README.md
541
541
  - lib/langchain.rb
542
- - lib/langchain/active_record/hooks.rb
543
542
  - lib/langchain/agent/base.rb
544
543
  - lib/langchain/agent/react_agent.rb
545
544
  - lib/langchain/agent/react_agent/react_agent_prompt.yaml
@@ -601,7 +600,6 @@ files:
601
600
  - lib/langchain/prompt/few_shot_prompt_template.rb
602
601
  - lib/langchain/prompt/loading.rb
603
602
  - lib/langchain/prompt/prompt_template.rb
604
- - lib/langchain/railtie.rb
605
603
  - lib/langchain/tool/base.rb
606
604
  - lib/langchain/tool/calculator.rb
607
605
  - lib/langchain/tool/database.rb
@@ -1,112 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Langchain
4
- module ActiveRecord
5
- # This module adds the following functionality to your ActiveRecord models:
6
- # * `vectorsearch` class method to set the vector search provider
7
- # * `similarity_search` class method to search for similar texts
8
- # * `upsert_to_vectorsearch` instance method to upsert the record to the vector search provider
9
- #
10
- # Usage:
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
- # )
18
- #
19
- # after_save :upsert_to_vectorsearch
20
- #
21
- # # Overwriting how the model is serialized before it's indexed
22
- # def as_vector
23
- # [
24
- # "Title: #{title}",
25
- # "Description: #{description}",
26
- # ...
27
- # ]
28
- # .compact
29
- # .join("\n")
30
- # end
31
- # end
32
- #
33
- # Create the default schema
34
- # Recipe.class_variable_get(:@@provider).create_default_schema
35
- # Query the vector search provider
36
- # Recipe.similarity_search("carnivore dish")
37
- # Delete the default schema to start over
38
- # Recipe.class_variable_get(:@@provider).destroy_default_schema
39
- #
40
- module Hooks
41
- def self.included(base)
42
- base.extend ClassMethods
43
- end
44
-
45
- # Index the text to the vector search provider
46
- # You'd typically call this method in an ActiveRecord callback
47
- #
48
- # @return [Boolean] true
49
- # @raise [Error] Indexing to vector search DB failed
50
- def upsert_to_vectorsearch
51
- if previously_new_record?
52
- self.class.class_variable_get(:@@provider).add_texts(
53
- texts: [as_vector],
54
- ids: [id]
55
- )
56
- else
57
- self.class.class_variable_get(:@@provider).update_texts(
58
- texts: [as_vector],
59
- ids: [id]
60
- )
61
- end
62
- end
63
-
64
- # Used to serialize the DB record to an indexable vector text
65
- # Overwrite this method in your model to customize
66
- #
67
- # @return [String] the text representation of the model
68
- def as_vector
69
- to_json
70
- end
71
-
72
- module ClassMethods
73
- # Set the vector search provider
74
- #
75
- # @param provider [Object] The `Langchain::Vectorsearch::*` instance
76
- def vectorsearch(provider:)
77
- class_variable_set(:@@provider, provider)
78
- end
79
-
80
- # Search for similar texts
81
- #
82
- # @param query [String] The query to search for
83
- # @param k [Integer] The number of results to return
84
- # @return [ActiveRecord::Relation] The ActiveRecord relation
85
- def similarity_search(query, k: 1)
86
- records = class_variable_get(:@@provider).similarity_search(
87
- query: query,
88
- k: k
89
- )
90
-
91
- # We use "__id" when Weaviate is the provider
92
- ids = records.map { |record| record.dig("id") || record.dig("__id") }
93
- where(id: ids)
94
- end
95
-
96
- # Ask a question and return the answer
97
- #
98
- # @param question [String] The question to ask
99
- # @param k [Integer] The number of results to have in context
100
- # @yield [String] Stream responses back one String at a time
101
- # @return [String] The answer to the question
102
- def ask(question:, k: 4, &block)
103
- class_variable_get(:@@provider).ask(
104
- question: question,
105
- k: k,
106
- &block
107
- )
108
- end
109
- end
110
- end
111
- end
112
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Langchain
4
- class Railtie < Rails::Railtie
5
- initializer "langchain" do
6
- ActiveSupport.on_load(:active_record) do
7
- ::ActiveRecord::Base.include Langchain::ActiveRecord::Hooks
8
- end
9
- end
10
- end
11
- end