langchainrb 0.9.2 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/README.md +12 -19
  4. data/lib/langchain/agent/react_agent.rb +2 -0
  5. data/lib/langchain/agent/sql_query_agent.rb +2 -0
  6. data/lib/langchain/assistants/assistant.rb +8 -24
  7. data/lib/langchain/assistants/thread.rb +2 -2
  8. data/lib/langchain/chunker/markdown.rb +0 -2
  9. data/lib/langchain/chunker/recursive_text.rb +0 -2
  10. data/lib/langchain/chunker/semantic.rb +1 -3
  11. data/lib/langchain/chunker/sentence.rb +0 -2
  12. data/lib/langchain/chunker/text.rb +0 -2
  13. data/lib/langchain/contextual_logger.rb +1 -1
  14. data/lib/langchain/conversation/memory.rb +2 -0
  15. data/lib/langchain/conversation/message.rb +2 -0
  16. data/lib/langchain/llm/ollama.rb +40 -3
  17. data/lib/langchain/llm/openai.rb +16 -4
  18. data/lib/langchain/llm/prompts/ollama/summarize_template.yaml +9 -0
  19. data/lib/langchain/output_parsers/base.rb +0 -4
  20. data/lib/langchain/output_parsers/output_fixing_parser.rb +6 -13
  21. data/lib/langchain/output_parsers/structured_output_parser.rb +0 -10
  22. data/lib/langchain/processors/eml.rb +65 -0
  23. data/lib/langchain/tool/base.rb +17 -32
  24. data/lib/langchain/tool/calculator/calculator.json +19 -0
  25. data/lib/langchain/tool/{calculator.rb → calculator/calculator.rb} +8 -5
  26. data/lib/langchain/tool/database/database.json +46 -0
  27. data/lib/langchain/tool/database/database.rb +105 -0
  28. data/lib/langchain/tool/google_search/google_search.json +19 -0
  29. data/lib/langchain/tool/{google_search.rb → google_search/google_search.rb} +5 -6
  30. data/lib/langchain/tool/ruby_code_interpreter/ruby_code_interpreter.json +19 -0
  31. data/lib/langchain/tool/{ruby_code_interpreter.rb → ruby_code_interpreter/ruby_code_interpreter.rb} +9 -1
  32. data/lib/langchain/tool/weather/weather.json +19 -0
  33. data/lib/langchain/tool/{weather.rb → weather/weather.rb} +3 -4
  34. data/lib/langchain/tool/wikipedia/wikipedia.json +19 -0
  35. data/lib/langchain/tool/{wikipedia.rb → wikipedia/wikipedia.rb} +10 -1
  36. data/lib/langchain/vectorsearch/base.rb +1 -1
  37. data/lib/langchain/version.rb +1 -1
  38. data/lib/langchain.rb +8 -1
  39. metadata +80 -16
  40. data/lib/langchain/tool/database.rb +0 -90
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: langchainrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Bondarev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-11 00:00:00.000000000 Z
11
+ date: 2024-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 7.0.8
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 7.0.8
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: baran
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -30,42 +44,42 @@ dependencies:
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: 0.8.1
47
+ version: 1.1.0
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: 0.8.1
54
+ version: 1.1.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: tiktoken_ruby
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: 0.0.5
61
+ version: 0.0.7
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: 0.0.5
68
+ version: 0.0.7
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: json-schema
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: 4.0.0
75
+ version: '4'
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: 4.0.0
82
+ version: '4'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: zeitwerk
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -178,6 +192,34 @@ dependencies:
178
192
  - - "~>"
179
193
  - !ruby/object:Gem::Version
180
194
  version: 2.2.7
195
+ - !ruby/object:Gem::Dependency
196
+ name: vcr
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: webmock
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
181
223
  - !ruby/object:Gem::Dependency
182
224
  name: ai21
183
225
  requirement: !ruby/object:Gem::Requirement
@@ -416,6 +458,20 @@ dependencies:
416
458
  - - "~>"
417
459
  - !ruby/object:Gem::Version
418
460
  version: '1.13'
461
+ - !ruby/object:Gem::Dependency
462
+ name: mail
463
+ requirement: !ruby/object:Gem::Requirement
464
+ requirements:
465
+ - - "~>"
466
+ - !ruby/object:Gem::Version
467
+ version: '2.8'
468
+ type: :development
469
+ prerelease: false
470
+ version_requirements: !ruby/object:Gem::Requirement
471
+ requirements:
472
+ - - "~>"
473
+ - !ruby/object:Gem::Version
474
+ version: '2.8'
419
475
  - !ruby/object:Gem::Dependency
420
476
  name: open-weather-ruby-client
421
477
  requirement: !ruby/object:Gem::Requirement
@@ -612,7 +668,7 @@ dependencies:
612
668
  - - ">="
613
669
  - !ruby/object:Gem::Version
614
670
  version: '0'
615
- description: Build LLM-backed Ruby applications with Ruby's LangChain
671
+ description: Build LLM-backed Ruby applications with Ruby's Langchain.rb
616
672
  email:
617
673
  - andrei.bondarev13@gmail.com
618
674
  executables: []
@@ -670,6 +726,7 @@ files:
670
726
  - lib/langchain/llm/llama_cpp.rb
671
727
  - lib/langchain/llm/ollama.rb
672
728
  - lib/langchain/llm/openai.rb
729
+ - lib/langchain/llm/prompts/ollama/summarize_template.yaml
673
730
  - lib/langchain/llm/prompts/summarize_template.yaml
674
731
  - lib/langchain/llm/replicate.rb
675
732
  - lib/langchain/llm/response/ai21_response.rb
@@ -692,6 +749,7 @@ files:
692
749
  - lib/langchain/processors/base.rb
693
750
  - lib/langchain/processors/csv.rb
694
751
  - lib/langchain/processors/docx.rb
752
+ - lib/langchain/processors/eml.rb
695
753
  - lib/langchain/processors/html.rb
696
754
  - lib/langchain/processors/json.rb
697
755
  - lib/langchain/processors/jsonl.rb
@@ -705,12 +763,18 @@ files:
705
763
  - lib/langchain/prompt/loading.rb
706
764
  - lib/langchain/prompt/prompt_template.rb
707
765
  - lib/langchain/tool/base.rb
708
- - lib/langchain/tool/calculator.rb
709
- - lib/langchain/tool/database.rb
710
- - lib/langchain/tool/google_search.rb
711
- - lib/langchain/tool/ruby_code_interpreter.rb
712
- - lib/langchain/tool/weather.rb
713
- - lib/langchain/tool/wikipedia.rb
766
+ - lib/langchain/tool/calculator/calculator.json
767
+ - lib/langchain/tool/calculator/calculator.rb
768
+ - lib/langchain/tool/database/database.json
769
+ - lib/langchain/tool/database/database.rb
770
+ - lib/langchain/tool/google_search/google_search.json
771
+ - lib/langchain/tool/google_search/google_search.rb
772
+ - lib/langchain/tool/ruby_code_interpreter/ruby_code_interpreter.json
773
+ - lib/langchain/tool/ruby_code_interpreter/ruby_code_interpreter.rb
774
+ - lib/langchain/tool/weather/weather.json
775
+ - lib/langchain/tool/weather/weather.rb
776
+ - lib/langchain/tool/wikipedia/wikipedia.json
777
+ - lib/langchain/tool/wikipedia/wikipedia.rb
714
778
  - lib/langchain/utils/cosine_similarity.rb
715
779
  - lib/langchain/utils/token_length/ai21_validator.rb
716
780
  - lib/langchain/utils/token_length/base_validator.rb
@@ -758,5 +822,5 @@ requirements: []
758
822
  rubygems_version: 3.4.1
759
823
  signing_key:
760
824
  specification_version: 4
761
- summary: Build LLM-backed Ruby applications with Ruby's LangChain
825
+ summary: Build LLM-backed Ruby applications with Ruby's Langchain.rb
762
826
  test_files: []
@@ -1,90 +0,0 @@
1
- module Langchain::Tool
2
- class Database < Base
3
- #
4
- # Connects to a database, executes SQL queries, and outputs DB schema for Agents to use
5
- #
6
- # Gem requirements: gem "sequel", "~> 5.68.0"
7
- #
8
-
9
- NAME = "database"
10
-
11
- description <<~DESC
12
- Useful for getting the result of a database query.
13
-
14
- The input to this tool should be valid SQL.
15
- DESC
16
-
17
- attr_reader :db, :requested_tables, :excluded_tables
18
-
19
- #
20
- # Establish a database connection
21
- #
22
- # @param connection_string [String] Database connection info, e.g. 'postgres://user:password@localhost:5432/db_name'
23
- # @param tables [Array<Symbol>] The tables to use. Will use all if empty.
24
- # @param except_tables [Array<Symbol>] The tables to exclude. Will exclude none if empty.
25
-
26
- # @return [Database] Database object
27
- #
28
- def initialize(connection_string:, tables: [], exclude_tables: [])
29
- depends_on "sequel"
30
-
31
- raise StandardError, "connection_string parameter cannot be blank" if connection_string.empty?
32
-
33
- @db = Sequel.connect(connection_string)
34
- @requested_tables = tables
35
- @excluded_tables = exclude_tables
36
- end
37
-
38
- #
39
- # Returns the database schema
40
- #
41
- # @return [String] schema
42
- #
43
- def dump_schema
44
- Langchain.logger.info("Dumping schema tables and keys", for: self.class)
45
- schema = ""
46
- db.tables.each do |table|
47
- next if excluded_tables.include?(table)
48
- next unless requested_tables.empty? || requested_tables.include?(table)
49
-
50
- primary_key_columns = []
51
- primary_key_column_count = db.schema(table).count { |column| column[1][:primary_key] == true }
52
-
53
- schema << "CREATE TABLE #{table}(\n"
54
- db.schema(table).each do |column|
55
- schema << "#{column[0]} #{column[1][:type]}"
56
- if column[1][:primary_key] == true
57
- schema << " PRIMARY KEY" if primary_key_column_count == 1
58
- else
59
- primary_key_columns << column[0]
60
- end
61
- schema << ",\n" unless column == db.schema(table).last && primary_key_column_count == 1
62
- end
63
- if primary_key_column_count > 1
64
- schema << "PRIMARY KEY (#{primary_key_columns.join(",")})"
65
- end
66
- db.foreign_key_list(table).each do |fk|
67
- schema << ",\n" if fk == db.foreign_key_list(table).first
68
- schema << "FOREIGN KEY (#{fk[:columns][0]}) REFERENCES #{fk[:table]}(#{fk[:key][0]})"
69
- schema << ",\n" unless fk == db.foreign_key_list(table).last
70
- end
71
- schema << ");\n"
72
- end
73
- schema
74
- end
75
-
76
- #
77
- # Evaluates a sql expression
78
- #
79
- # @param input [String] sql expression
80
- # @return [Array] results
81
- #
82
- def execute(input:)
83
- Langchain.logger.info("Executing \"#{input}\"", for: self.class)
84
-
85
- db[input].to_a
86
- rescue Sequel::DatabaseError => e
87
- Langchain.logger.error(e.message, for: self.class)
88
- end
89
- end
90
- end