langchainrb 0.11.3 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -4
- data/README.md +1 -1
- data/lib/langchain/llm/aws_bedrock.rb +52 -0
- data/lib/langchain/llm/base.rb +2 -2
- data/lib/langchain/llm/cohere.rb +1 -1
- data/lib/langchain/llm/google_palm.rb +1 -1
- data/lib/langchain/llm/google_vertex_ai.rb +1 -1
- data/lib/langchain/llm/hugging_face.rb +1 -1
- data/lib/langchain/llm/ollama.rb +2 -2
- data/lib/langchain/llm/openai.rb +1 -1
- data/lib/langchain/llm/replicate.rb +1 -1
- data/lib/langchain/llm/response/ollama_response.rb +4 -0
- data/lib/langchain/vectorsearch/elasticsearch.rb +1 -1
- data/lib/langchain/vectorsearch/epsilla.rb +2 -2
- data/lib/langchain/vectorsearch/hnswlib.rb +1 -1
- data/lib/langchain/vectorsearch/milvus.rb +1 -1
- data/lib/langchain/vectorsearch/pgvector.rb +2 -2
- data/lib/langchain/vectorsearch/pinecone.rb +1 -1
- data/lib/langchain/vectorsearch/qdrant.rb +1 -1
- data/lib/langchain/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f29aad35bc35dc95eb8673b11578b51c7449a19818989d9da5e640c6fb219c7
|
4
|
+
data.tar.gz: 4d0c4d3d424a82c7f02fb9e49ca52a5bdca5dfbce19fbfa22f2d74ef46d81eb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91b6f4fc5056308eab9119dcfda1be16857e6e9e6e531977148b1e8f31b72090794b67e6855afb95633b8f836b8d20921bc5a069afdc745d1114892143a177e1
|
7
|
+
data.tar.gz: f7a7949ab2efd960eacf3a93f7beaa9104403a93619b8c95ea094901c2d3d19b89980c81d293ae16035c5ff51fe021a09f2e81e2c0ed6854bff87d30e6def925
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
|
-
- New `Langchain::Processors::Pptx` to parse .pptx files
|
3
|
-
- New `Langchain::LLM::Anthropic#chat()` support
|
4
|
-
- Misc fixes
|
5
2
|
|
6
|
-
## [0.
|
3
|
+
## [0.12.0] - 2024-04-22
|
4
|
+
- [BREAKING] Rename `dimension` parameter to `dimensions` everywhere
|
5
|
+
|
6
|
+
## [0.11.4] - 2024-04-19
|
7
|
+
- New `Langchain::LLM::AWSBedrock#chat()` to wrap Bedrock Claude requests
|
8
|
+
- New `Langchain::LLM::OllamaResponse#total_tokens()` method
|
9
|
+
|
10
|
+
## [0.11.3] - 2024-04-16
|
7
11
|
- New `Langchain::Processors::Pptx` to parse .pptx files
|
8
12
|
- New `Langchain::LLM::Anthropic#chat()` support
|
9
13
|
- Misc fixes
|
data/README.md
CHANGED
@@ -60,7 +60,7 @@ Langchain.rb wraps supported LLMs in a unified interface allowing you to easily
|
|
60
60
|
| [OpenAI](https://openai.com/?utm_source=langchainrb&utm_medium=github) | ✅ | ✅ | ✅ | ❌ | Including Azure OpenAI |
|
61
61
|
| [AI21](https://ai21.com/?utm_source=langchainrb&utm_medium=github) | ❌ | ✅ | ❌ | ✅ | |
|
62
62
|
| [Anthropic](https://anthropic.com/?utm_source=langchainrb&utm_medium=github) | ❌ | ✅ | ✅ | ❌ | |
|
63
|
-
| [AWS Bedrock](https://aws.amazon.com/bedrock?utm_source=langchainrb&utm_medium=github) | ✅ | ✅ |
|
63
|
+
| [AWS Bedrock](https://aws.amazon.com/bedrock?utm_source=langchainrb&utm_medium=github) | ✅ | ✅ | ✅ | ❌ | Provides AWS, Cohere, AI21, Antropic and Stability AI models |
|
64
64
|
| [Cohere](https://cohere.com/?utm_source=langchainrb&utm_medium=github) | ✅ | ✅ | ✅ | ✅ | |
|
65
65
|
| [GooglePalm](https://ai.google/discover/palm2?utm_source=langchainrb&utm_medium=github) | ✅ | ✅ | ✅ | ✅ | |
|
66
66
|
| [Google Vertex AI](https://cloud.google.com/vertex-ai?utm_source=langchainrb&utm_medium=github) | ✅ | ✅ | ❌ | ✅ | |
|
@@ -46,7 +46,10 @@ module Langchain::LLM
|
|
46
46
|
}
|
47
47
|
}.freeze
|
48
48
|
|
49
|
+
attr_reader :client, :defaults
|
50
|
+
|
49
51
|
SUPPORTED_COMPLETION_PROVIDERS = %i[anthropic cohere ai21].freeze
|
52
|
+
SUPPORTED_CHAT_COMPLETION_PROVIDERS = %i[anthropic].freeze
|
50
53
|
SUPPORTED_EMBEDDING_PROVIDERS = %i[amazon].freeze
|
51
54
|
|
52
55
|
def initialize(completion_model: DEFAULTS[:completion_model_name], embedding_model: DEFAULTS[:embedding_model_name], aws_client_options: {}, default_options: {})
|
@@ -91,6 +94,8 @@ module Langchain::LLM
|
|
91
94
|
def complete(prompt:, **params)
|
92
95
|
raise "Completion provider #{completion_provider} is not supported." unless SUPPORTED_COMPLETION_PROVIDERS.include?(completion_provider)
|
93
96
|
|
97
|
+
raise "Model #{@defaults[:completion_model_name]} only supports #chat." if @defaults[:completion_model_name].include?("claude-3")
|
98
|
+
|
94
99
|
parameters = compose_parameters params
|
95
100
|
|
96
101
|
parameters[:prompt] = wrap_prompt prompt
|
@@ -105,6 +110,53 @@ module Langchain::LLM
|
|
105
110
|
parse_response response
|
106
111
|
end
|
107
112
|
|
113
|
+
# Generate a chat completion for a given prompt
|
114
|
+
# Currently only configured to work with the Anthropic provider and
|
115
|
+
# the claude-3 model family
|
116
|
+
# @param messages [Array] The messages to generate a completion for
|
117
|
+
# @param system [String] The system prompt to provide instructions
|
118
|
+
# @param model [String] The model to use for completion defaults to @defaults[:chat_completion_model_name]
|
119
|
+
# @param max_tokens [Integer] The maximum number of tokens to generate
|
120
|
+
# @param stop_sequences [Array] The stop sequences to use for completion
|
121
|
+
# @param temperature [Float] The temperature to use for completion
|
122
|
+
# @param top_p [Float] The top p to use for completion
|
123
|
+
# @param top_k [Integer] The top k to use for completion
|
124
|
+
# @return [Langchain::LLM::AnthropicMessagesResponse] Response object
|
125
|
+
def chat(
|
126
|
+
messages: [],
|
127
|
+
system: nil,
|
128
|
+
model: defaults[:completion_model_name],
|
129
|
+
max_tokens: defaults[:max_tokens_to_sample],
|
130
|
+
stop_sequences: nil,
|
131
|
+
temperature: nil,
|
132
|
+
top_p: nil,
|
133
|
+
top_k: nil
|
134
|
+
)
|
135
|
+
raise ArgumentError.new("messages argument is required") if messages.empty?
|
136
|
+
|
137
|
+
raise "Model #{model} does not support chat completions." unless Langchain::LLM::AwsBedrock::SUPPORTED_CHAT_COMPLETION_PROVIDERS.include?(completion_provider)
|
138
|
+
|
139
|
+
inference_parameters = {
|
140
|
+
messages: messages,
|
141
|
+
max_tokens: max_tokens,
|
142
|
+
anthropic_version: @defaults[:anthropic_version]
|
143
|
+
}
|
144
|
+
inference_parameters[:system] = system if system
|
145
|
+
inference_parameters[:stop_sequences] = stop_sequences if stop_sequences
|
146
|
+
inference_parameters[:temperature] = temperature if temperature
|
147
|
+
inference_parameters[:top_p] = top_p if top_p
|
148
|
+
inference_parameters[:top_k] = top_k if top_k
|
149
|
+
|
150
|
+
response = client.invoke_model({
|
151
|
+
model_id: model,
|
152
|
+
body: inference_parameters.to_json,
|
153
|
+
content_type: "application/json",
|
154
|
+
accept: "application/json"
|
155
|
+
})
|
156
|
+
|
157
|
+
parse_response response
|
158
|
+
end
|
159
|
+
|
108
160
|
private
|
109
161
|
|
110
162
|
def completion_provider
|
data/lib/langchain/llm/base.rb
CHANGED
@@ -24,8 +24,8 @@ module Langchain::LLM
|
|
24
24
|
# A client for communicating with the LLM
|
25
25
|
attr_reader :client
|
26
26
|
|
27
|
-
def
|
28
|
-
self.class.const_get(:DEFAULTS).dig(:
|
27
|
+
def default_dimensions
|
28
|
+
self.class.const_get(:DEFAULTS).dig(:dimensions)
|
29
29
|
end
|
30
30
|
|
31
31
|
#
|
data/lib/langchain/llm/cohere.rb
CHANGED
@@ -13,7 +13,7 @@ module Langchain::LLM
|
|
13
13
|
class GooglePalm < Base
|
14
14
|
DEFAULTS = {
|
15
15
|
temperature: 0.0,
|
16
|
-
|
16
|
+
dimensions: 768, # This is what the `embedding-gecko-001` model generates
|
17
17
|
completion_model_name: "text-bison-001",
|
18
18
|
chat_completion_model_name: "chat-bison-001",
|
19
19
|
embeddings_model_name: "embedding-gecko-001"
|
@@ -16,7 +16,7 @@ module Langchain::LLM
|
|
16
16
|
DEFAULTS = {
|
17
17
|
temperature: 0.0,
|
18
18
|
embeddings_model_name: "sentence-transformers/all-MiniLM-L6-v2",
|
19
|
-
|
19
|
+
dimensions: 384 # Vector size generated by the above model
|
20
20
|
}.freeze
|
21
21
|
|
22
22
|
#
|
data/lib/langchain/llm/ollama.rb
CHANGED
@@ -41,9 +41,9 @@ module Langchain::LLM
|
|
41
41
|
|
42
42
|
# Returns the # of vector dimensions for the embeddings
|
43
43
|
# @return [Integer] The # of vector dimensions
|
44
|
-
def
|
44
|
+
def default_dimensions
|
45
45
|
# since Ollama can run multiple models, look it up or generate an embedding and return the size
|
46
|
-
@
|
46
|
+
@default_dimensions ||=
|
47
47
|
EMBEDDING_SIZES.fetch(defaults[:embeddings_model_name].to_sym) do
|
48
48
|
embed(text: "test").embedding.size
|
49
49
|
end
|
data/lib/langchain/llm/openai.rb
CHANGED
@@ -54,7 +54,7 @@ module Langchain::Vectorsearch
|
|
54
54
|
@db_path = db_path
|
55
55
|
@table_name = index_name
|
56
56
|
|
57
|
-
@
|
57
|
+
@vector_dimensions = llm.default_dimensions
|
58
58
|
|
59
59
|
super(llm: llm)
|
60
60
|
end
|
@@ -64,7 +64,7 @@ module Langchain::Vectorsearch
|
|
64
64
|
status_code, response = @client.database.create_table(@table_name, [
|
65
65
|
{"name" => "ID", "dataType" => "STRING", "primaryKey" => true},
|
66
66
|
{"name" => "Doc", "dataType" => "STRING"},
|
67
|
-
{"name" => "Embedding", "dataType" => "VECTOR_FLOAT", "dimensions" => @
|
67
|
+
{"name" => "Embedding", "dataType" => "VECTOR_FLOAT", "dimensions" => @vector_dimensions}
|
68
68
|
])
|
69
69
|
raise "Failed to create table: #{response}" if status_code != 200
|
70
70
|
|
@@ -26,7 +26,7 @@ module Langchain::Vectorsearch
|
|
26
26
|
|
27
27
|
super(llm: llm)
|
28
28
|
|
29
|
-
@client = ::Hnswlib::HierarchicalNSW.new(space: DEFAULT_METRIC, dim: llm.
|
29
|
+
@client = ::Hnswlib::HierarchicalNSW.new(space: DEFAULT_METRIC, dim: llm.default_dimensions)
|
30
30
|
@path_to_index = path_to_index
|
31
31
|
|
32
32
|
initialize_index
|
@@ -101,11 +101,11 @@ module Langchain::Vectorsearch
|
|
101
101
|
def create_default_schema
|
102
102
|
db.run "CREATE EXTENSION IF NOT EXISTS vector"
|
103
103
|
namespace_column = @namespace_column
|
104
|
-
|
104
|
+
vector_dimensions = llm.default_dimensions
|
105
105
|
db.create_table? table_name.to_sym do
|
106
106
|
primary_key :id
|
107
107
|
text :content
|
108
|
-
column :vectors, "vector(#{
|
108
|
+
column :vectors, "vector(#{vector_dimensions})"
|
109
109
|
text namespace_column.to_sym, default: nil
|
110
110
|
end
|
111
111
|
end
|
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.
|
4
|
+
version: 0.12.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: 2024-04-
|
11
|
+
date: 2024-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|