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 +4 -4
- data/CHANGELOG.md +5 -1
- data/lib/langchain/llm/openai.rb +8 -4
- data/lib/langchain/processors/eml.rb +0 -1
- data/lib/langchain/tool/ruby_code_interpreter/ruby_code_interpreter.rb +34 -30
- data/lib/langchain/vectorsearch/chroma.rb +7 -0
- data/lib/langchain/vectorsearch/qdrant.rb +10 -0
- data/lib/langchain/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 833d4dafdf55e45852261e1c86b8121fd3ed1b61766a7fb121589e6549b255e0
|
4
|
+
data.tar.gz: d3834e7a5d15cf1ddd45bfc2db69b73afb5cf60b6b43004a398a688b5d5932e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98dbc07b39f956d7425c562451d9eced8162cd7d7e181ac6188d029090275f5485376db3afeb826e730c168f6d64a7cd6af90503974f8b2696b1555f3d18b589
|
7
|
+
data.tar.gz: 3e641d27e3ccdedfa363c7bfecb7f6a1293c1f866421db3ac5e74dcd4615934a132345f9c7912fec0200d2fe626747faaefa592592066e336d33c4db5d3fd050
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
## [Unreleased]
|
2
|
-
|
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
|
data/lib/langchain/llm/openai.rb
CHANGED
@@ -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-
|
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,41 +1,45 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
24
|
+
def initialize(timeout: 30)
|
25
|
+
depends_on "safe_ruby"
|
23
26
|
|
24
|
-
|
25
|
-
|
27
|
+
@timeout = timeout
|
28
|
+
end
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
35
|
-
|
37
|
+
safe_eval(input)
|
38
|
+
end
|
36
39
|
|
37
|
-
|
38
|
-
|
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
|
data/lib/langchain/version.rb
CHANGED
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
|
+
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-
|
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.
|
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
|