langchainrb 0.9.4 → 0.9.5

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: 62c459d5dc2f716eaeb81697bdf45ad42ae168784d28ff8a80a89d1b3e14eadd
4
- data.tar.gz: 8bb1f94373c54619235cb24ea705179626e398d517739b93014a514283068468
3
+ metadata.gz: 833d4dafdf55e45852261e1c86b8121fd3ed1b61766a7fb121589e6549b255e0
4
+ data.tar.gz: d3834e7a5d15cf1ddd45bfc2db69b73afb5cf60b6b43004a398a688b5d5932e1
5
5
  SHA512:
6
- metadata.gz: 4b6bd3fb3a983458dd0ff83573e268c4ab8ae26fcffbab93826d3f3143a648b3fa2fcb9e93ba1139551cf8b6d8641da74ea78d098e42ecd672245ca41610c137
7
- data.tar.gz: a40d5bfb0301e7e9e4d66a708fc6bc048272da772bad21473f88be219caf139c86f8cbcf9ea73a3454642042872e796595518a75eb5e9ad3ba5288adf823bfc7
6
+ metadata.gz: 98dbc07b39f956d7425c562451d9eced8162cd7d7e181ac6188d029090275f5485376db3afeb826e730c168f6d64a7cd6af90503974f8b2696b1555f3d18b589
7
+ data.tar.gz: 3e641d27e3ccdedfa363c7bfecb7f6a1293c1f866421db3ac5e74dcd4615934a132345f9c7912fec0200d2fe626747faaefa592592066e336d33c4db5d3fd050
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
- - `Langchain::LLM::Ollama` can now `#summarize`
2
+
3
+ ## [0.9.5]
4
+ - Now using OpenAI's "text-embedding-3-small" model to generate embeddings
5
+ - Added `remove_texts(ids:)` method to Qdrant and Chroma
6
+ - Add Ruby 3.3 support
3
7
 
4
8
  ## [0.9.4]
5
9
  - New `Ollama#summarize()` method
@@ -17,7 +17,7 @@ module Langchain::LLM
17
17
  n: 1,
18
18
  temperature: 0.0,
19
19
  chat_completion_model_name: "gpt-3.5-turbo",
20
- embeddings_model_name: "text-embedding-ada-002"
20
+ embeddings_model_name: "text-embedding-3-small"
21
21
  }.freeze
22
22
 
23
23
  EMBEDDING_SIZES = {
@@ -53,7 +53,8 @@ module Langchain::LLM
53
53
  text:,
54
54
  model: defaults[:embeddings_model_name],
55
55
  encoding_format: nil,
56
- user: nil
56
+ user: nil,
57
+ dimensions: EMBEDDING_SIZES.fetch(model.to_sym, nil)
57
58
  )
58
59
  raise ArgumentError.new("text argument is required") if text.empty?
59
60
  raise ArgumentError.new("model argument is required") if model.empty?
@@ -61,12 +62,15 @@ module Langchain::LLM
61
62
 
62
63
  parameters = {
63
64
  input: text,
64
- model: model,
65
- dimensions: default_dimension
65
+ model: model
66
66
  }
67
67
  parameters[:encoding_format] = encoding_format if encoding_format
68
68
  parameters[:user] = user if user
69
69
 
70
+ if ["text-embedding-3-small", "text-embedding-3-large"].include?(model)
71
+ parameters[:dimensions] = EMBEDDING_SIZES[model.to_sym] if EMBEDDING_SIZES.key?(model.to_sym)
72
+ end
73
+
70
74
  validate_max_tokens(text, parameters[:model])
71
75
 
72
76
  response = with_api_error_handling do
@@ -1,4 +1,3 @@
1
- require "mail"
2
1
  require "uri"
3
2
 
4
3
  module Langchain
@@ -1,41 +1,45 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Langchain::Tool
4
- class RubyCodeInterpreter < Base
5
- #
6
- # A tool that execute Ruby code in a sandboxed environment.
7
- #
8
- # Gem requirements:
9
- # gem "safe_ruby", "~> 1.0.4"
10
- #
11
- # Usage:
12
- # interpreter = Langchain::Tool::RubyCodeInterpreter.new
13
- #
14
- NAME = "ruby_code_interpreter"
15
- ANNOTATIONS_PATH = Langchain.root.join("./langchain/tool/#{NAME}/#{NAME}.json").to_path
3
+ # RubyCodeInterpreter does not work with Ruby 3.3;
4
+ # https://github.com/ukutaht/safe_ruby/issues/4
5
+ if RUBY_VERSION <= "3.2"
6
+ module Langchain::Tool
7
+ class RubyCodeInterpreter < Base
8
+ #
9
+ # A tool that execute Ruby code in a sandboxed environment.
10
+ #
11
+ # Gem requirements:
12
+ # gem "safe_ruby", "~> 1.0.4"
13
+ #
14
+ # Usage:
15
+ # interpreter = Langchain::Tool::RubyCodeInterpreter.new
16
+ #
17
+ NAME = "ruby_code_interpreter"
18
+ ANNOTATIONS_PATH = Langchain.root.join("./langchain/tool/#{NAME}/#{NAME}.json").to_path
16
19
 
17
- description <<~DESC
18
- A Ruby code interpreter. Use this to execute ruby expressions. Input should be a valid ruby expression. If you want to see the output of the tool, make sure to return a value.
19
- DESC
20
+ description <<~DESC
21
+ A Ruby code interpreter. Use this to execute ruby expressions. Input should be a valid ruby expression. If you want to see the output of the tool, make sure to return a value.
22
+ DESC
20
23
 
21
- def initialize(timeout: 30)
22
- depends_on "safe_ruby"
24
+ def initialize(timeout: 30)
25
+ depends_on "safe_ruby"
23
26
 
24
- @timeout = timeout
25
- end
27
+ @timeout = timeout
28
+ end
26
29
 
27
- # Executes Ruby code in a sandboxes environment.
28
- #
29
- # @param input [String] ruby code expression
30
- # @return [String] Answer
31
- def execute(input:)
32
- Langchain.logger.info("Executing \"#{input}\"", for: self.class)
30
+ # Executes Ruby code in a sandboxes environment.
31
+ #
32
+ # @param input [String] ruby code expression
33
+ # @return [String] Answer
34
+ def execute(input:)
35
+ Langchain.logger.info("Executing \"#{input}\"", for: self.class)
33
36
 
34
- safe_eval(input)
35
- end
37
+ safe_eval(input)
38
+ end
36
39
 
37
- def safe_eval(code)
38
- SafeRuby.eval(code, timeout: @timeout)
40
+ def safe_eval(code)
41
+ SafeRuby.eval(code, timeout: @timeout)
42
+ end
39
43
  end
40
44
  end
41
45
  end
@@ -60,6 +60,13 @@ module Langchain::Vectorsearch
60
60
  collection.update(embeddings)
61
61
  end
62
62
 
63
+ # Remove a list of texts from the index
64
+ # @param ids [Array<String>] The list of ids to remove
65
+ # @return [Hash] The response from the server
66
+ def remove_texts(ids:)
67
+ collection.delete(ids)
68
+ end
69
+
63
70
  # Create the collection with the default schema
64
71
  # @return [::Chroma::Resources::Collection] Created collection
65
72
  def create_default_schema
@@ -64,6 +64,16 @@ module Langchain::Vectorsearch
64
64
  add_texts(texts: texts, ids: ids)
65
65
  end
66
66
 
67
+ # Remove a list of texts from the index
68
+ # @param ids [Array<Integer>] The ids to remove
69
+ # @return [Hash] The response from the server
70
+ def remove_texts(ids:)
71
+ client.points.delete(
72
+ collection_name: index_name,
73
+ points: ids
74
+ )
75
+ end
76
+
67
77
  # Get the default schema
68
78
  # @return [Hash] The response from the server
69
79
  def get_default_schema
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Langchain
4
- VERSION = "0.9.4"
4
+ VERSION = "0.9.5"
5
5
  end
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.9.4
4
+ version: 0.9.5
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-28 00:00:00.000000000 Z
11
+ date: 2024-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -819,7 +819,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
819
819
  - !ruby/object:Gem::Version
820
820
  version: '0'
821
821
  requirements: []
822
- rubygems_version: 3.4.1
822
+ rubygems_version: 3.5.3
823
823
  signing_key:
824
824
  specification_version: 4
825
825
  summary: Build LLM-backed Ruby applications with Ruby's Langchain.rb