boxcars 0.2.9 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -1
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/boxcars/{embedding.rb → boxcar/vector_search.rb} +2 -2
- data/lib/boxcars/boxcar/vector_store.rb +34 -0
- data/lib/boxcars/boxcar/{embeddings → vector_stores}/document.rb +1 -1
- data/lib/boxcars/boxcar/{embeddings → vector_stores}/embed_via_open_ai.rb +9 -9
- data/lib/boxcars/boxcar/vector_stores/embed_via_tensorflow.rb +12 -0
- data/lib/boxcars/boxcar/{embeddings → vector_stores}/hnswlib/build_vector_store.rb +7 -9
- data/lib/boxcars/boxcar/{embeddings → vector_stores}/hnswlib/hnswlib_config.rb +1 -1
- data/lib/boxcars/boxcar/{embeddings → vector_stores}/hnswlib/hnswlib_search.rb +2 -2
- data/lib/boxcars/boxcar/{embeddings → vector_stores}/hnswlib/save_to_hnswlib.rb +3 -3
- data/lib/boxcars/boxcar/vector_stores/in_memory/add_documents.rb +67 -0
- data/lib/boxcars/boxcar/vector_stores/in_memory/search.rb +81 -0
- data/lib/boxcars/boxcar/{embeddings → vector_stores}/similarity_search.rb +4 -6
- data/lib/boxcars/boxcar/{embeddings → vector_stores}/split_text.rb +2 -2
- data/lib/boxcars/boxcar.rb +1 -0
- data/lib/boxcars/engine/openai.rb +11 -3
- data/lib/boxcars/version.rb +1 -1
- data/lib/boxcars.rb +0 -1
- metadata +16 -13
- data/lib/boxcars/boxcar/embeddings.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7d76e1223cfa17d11ab3670ebc6d43a8dbdc142e6aa85bd6bb6c230ccdea160
|
4
|
+
data.tar.gz: 39172ff71234851bcef10c762ba29481b4dba199e851c37e8092794ed24604b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b720092a75593e767564234f5990ccb7e57a382f7e5065c5cbaf9496ca0622ceb9dc63f07c10ff1ba305672c42817f94b371fadc3562b0043cfcde83ef2f1a8d
|
7
|
+
data.tar.gz: 2ded919f3e0157d777b541589d48472b0cceb348f1f9bfeb18f63b29dad25a4d23183a34aa111db726c366bbe0b74283d34a1c0e14372b726448e9c69961dc65
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,27 @@
|
|
2
2
|
|
3
3
|
## [Unreleased](https://github.com/BoxcarsAI/boxcars/tree/HEAD)
|
4
4
|
|
5
|
-
[Full Changelog](https://github.com/BoxcarsAI/boxcars/compare/v0.2.
|
5
|
+
[Full Changelog](https://github.com/BoxcarsAI/boxcars/compare/v0.2.9...HEAD)
|
6
|
+
|
7
|
+
**Implemented enhancements:**
|
8
|
+
|
9
|
+
- Notion Q&A [\#13](https://github.com/BoxcarsAI/boxcars/issues/13)
|
10
|
+
|
11
|
+
## [v0.2.9](https://github.com/BoxcarsAI/boxcars/tree/v0.2.9) (2023-04-22)
|
12
|
+
|
13
|
+
[Full Changelog](https://github.com/BoxcarsAI/boxcars/compare/v0.2.8...v0.2.9)
|
14
|
+
|
15
|
+
**Closed issues:**
|
16
|
+
|
17
|
+
- Getting started docs out of date [\#58](https://github.com/BoxcarsAI/boxcars/issues/58)
|
18
|
+
|
19
|
+
**Merged pull requests:**
|
20
|
+
|
21
|
+
- add default openai client, and new notebook [\#59](https://github.com/BoxcarsAI/boxcars/pull/59) ([francis](https://github.com/francis))
|
22
|
+
|
23
|
+
## [v0.2.8](https://github.com/BoxcarsAI/boxcars/tree/v0.2.8) (2023-04-19)
|
24
|
+
|
25
|
+
[Full Changelog](https://github.com/BoxcarsAI/boxcars/compare/v0.2.7...v0.2.8)
|
6
26
|
|
7
27
|
**Closed issues:**
|
8
28
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -85,7 +85,7 @@ calc = Boxcars::Calculator.new # just use the default Engine
|
|
85
85
|
puts calc.run "what is pi to the forth power divided by 22.1?"
|
86
86
|
```
|
87
87
|
You can change the default_engine with `Boxcars::configuration.default_engine = NewDefaultEngine`
|
88
|
-
### Boxcars currently
|
88
|
+
### Boxcars currently implemented
|
89
89
|
|
90
90
|
Here is what we have so far, but please put up a PR with your new ideas.
|
91
91
|
- GoogleSearch: uses the SERP API to do seaches
|
@@ -3,9 +3,9 @@
|
|
3
3
|
# Boxcars is a framework for running a series of tools to get an answer to a question.
|
4
4
|
module Boxcars
|
5
5
|
# For Boxcars that use an engine to do their work.
|
6
|
-
class
|
6
|
+
class VectorSearch < Boxcar
|
7
7
|
Error = Class.new(StandardError)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
require "boxcars/boxcar/
|
11
|
+
require "boxcars/boxcar/vector_store"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Boxcars is a framework for running a series of tools to get an answer to a question.
|
4
|
+
module Boxcars
|
5
|
+
module VectorStore
|
6
|
+
module ClassMethods
|
7
|
+
VectorStoresError = Class.new(StandardError)
|
8
|
+
|
9
|
+
def call(*args, **kw_args)
|
10
|
+
new(*args, **kw_args).call
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.included(base)
|
15
|
+
base.extend(ClassMethods)
|
16
|
+
|
17
|
+
class << base
|
18
|
+
private :new
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require_relative "vector_stores/document"
|
25
|
+
require_relative "vector_stores/embed_via_open_ai"
|
26
|
+
require_relative "vector_stores/embed_via_tensorflow"
|
27
|
+
require_relative "vector_stores/split_text"
|
28
|
+
require_relative "vector_stores/similarity_search"
|
29
|
+
require_relative "vector_stores/hnswlib/hnswlib_config"
|
30
|
+
require_relative "vector_stores/hnswlib/save_to_hnswlib"
|
31
|
+
require_relative "vector_stores/hnswlib/build_vector_store"
|
32
|
+
require_relative "vector_stores/hnswlib/hnswlib_search"
|
33
|
+
require_relative "vector_stores/in_memory/add_documents"
|
34
|
+
require_relative "vector_stores/in_memory/search"
|
@@ -3,16 +3,16 @@
|
|
3
3
|
require 'openai'
|
4
4
|
|
5
5
|
module Boxcars
|
6
|
-
module
|
6
|
+
module VectorStores
|
7
7
|
class EmbedViaOpenAI
|
8
|
-
include
|
8
|
+
include VectorStore
|
9
9
|
|
10
|
-
attr_accessor :texts, :
|
10
|
+
attr_accessor :texts, :client, :model
|
11
11
|
|
12
|
-
def initialize(texts:,
|
13
|
-
validate_params(texts,
|
12
|
+
def initialize(texts:, client:, model: 'text-embedding-ada-002')
|
13
|
+
validate_params(texts, client)
|
14
14
|
@texts = texts
|
15
|
-
@
|
15
|
+
@client = client
|
16
16
|
@model = model
|
17
17
|
end
|
18
18
|
|
@@ -28,13 +28,13 @@ module Boxcars
|
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
|
-
def validate_params(texts,
|
31
|
+
def validate_params(texts, client)
|
32
32
|
raise_error 'texts must be an array of strings' unless texts.is_a?(Array) && texts.all? { |text| text.is_a?(String) }
|
33
|
-
raise_error 'openai_connection must be an OpenAI::Client' unless
|
33
|
+
raise_error 'openai_connection must be an OpenAI::Client' unless client.is_a?(OpenAI::Client)
|
34
34
|
end
|
35
35
|
|
36
36
|
def embedding_with_retry(request)
|
37
|
-
response = @
|
37
|
+
response = @client.embeddings(parameters: request)
|
38
38
|
response['data'][0]['embedding']
|
39
39
|
end
|
40
40
|
|
@@ -5,10 +5,10 @@ require 'hnswlib'
|
|
5
5
|
require 'json'
|
6
6
|
|
7
7
|
module Boxcars
|
8
|
-
module
|
8
|
+
module VectorStores
|
9
9
|
module Hnswlib
|
10
10
|
class BuildVectorStore
|
11
|
-
include
|
11
|
+
include VectorStore
|
12
12
|
|
13
13
|
# This class is responsible for building the vector store for the hnswlib similarity search.
|
14
14
|
# It will load the training data, generate the embeddings, and save the vector store.
|
@@ -76,7 +76,7 @@ module Boxcars
|
|
76
76
|
|
77
77
|
docs = []
|
78
78
|
data.each do |chunk|
|
79
|
-
doc_output = Boxcars::
|
79
|
+
doc_output = Boxcars::VectorStores::SplitText.call(
|
80
80
|
separator: "\n", chunk_size: split_chunk_size, chunk_overlap: 0, text: chunk
|
81
81
|
)
|
82
82
|
docs.concat(doc_output)
|
@@ -97,10 +97,8 @@ module Boxcars
|
|
97
97
|
return true unless rebuild_required?
|
98
98
|
|
99
99
|
puts "Initializing Store..."
|
100
|
-
openai_client =
|
101
|
-
|
102
|
-
embeddings_with_dim = Boxcars::Embeddings::EmbedViaOpenAI.call(texts: documents, openai_connection: openai_client)
|
103
|
-
|
100
|
+
openai_client = Openai.open_ai_client
|
101
|
+
embeddings_with_dim = Boxcars::VectorStores::EmbedViaOpenAI.call(texts: documents, client: openai_client)
|
104
102
|
document_embeddings = embeddings_with_dim.map.with_index do |item, index|
|
105
103
|
{ doc_id: index, embedding: item[:embedding], document: documents[index] }
|
106
104
|
end
|
@@ -112,7 +110,7 @@ module Boxcars
|
|
112
110
|
return true unless rebuild_required?
|
113
111
|
|
114
112
|
puts "Saving Vectorstore"
|
115
|
-
Boxcars::
|
113
|
+
Boxcars::VectorStores::Hnswlib::SaveToHnswlib.call(
|
116
114
|
document_embeddings: embeddings_with_config[:document_embeddings],
|
117
115
|
index_file_path: index_file_path,
|
118
116
|
json_doc_file_path: json_doc_file_path,
|
@@ -123,7 +121,7 @@ module Boxcars
|
|
123
121
|
|
124
122
|
def hnswlib_config(dim)
|
125
123
|
# dim: length of datum point vector that will be indexed.
|
126
|
-
Boxcars::
|
124
|
+
Boxcars::VectorStores::Hnswlib::HnswlibConfig.new(
|
127
125
|
metric: "l2", max_item: 10000, dim: dim
|
128
126
|
)
|
129
127
|
end
|
@@ -4,7 +4,7 @@ require 'hnswlib'
|
|
4
4
|
require 'json'
|
5
5
|
|
6
6
|
module Boxcars
|
7
|
-
module
|
7
|
+
module VectorStores
|
8
8
|
module Hnswlib
|
9
9
|
class HnswlibSearch
|
10
10
|
def initialize(vector_store:, options: {})
|
@@ -46,7 +46,7 @@ module Boxcars
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def raise_error(message)
|
49
|
-
raise ArgumentError, message
|
49
|
+
raise ::Boxcars::ArgumentError, message
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -5,14 +5,14 @@ require 'json'
|
|
5
5
|
require 'fileutils'
|
6
6
|
|
7
7
|
module Boxcars
|
8
|
-
module
|
8
|
+
module VectorStores
|
9
9
|
module Hnswlib
|
10
10
|
class SaveToHnswlib
|
11
|
-
include
|
11
|
+
include VectorStore
|
12
12
|
|
13
13
|
# @param document_embeddings [Array] An array of hashes containing the document id, document text, and embedding.
|
14
14
|
# @param index_file_path [String] The path to the index file.
|
15
|
-
# @param hnswlib_config [Boxcars::
|
15
|
+
# @param hnswlib_config [Boxcars::VectorStores::Hnswlib::Config] The config object for the hnswlib index.
|
16
16
|
# @option json_doc_file_path [String] Optional. The path to the json file containing the document text.
|
17
17
|
def initialize(document_embeddings:, index_file_path:, hnswlib_config:, json_doc_file_path: nil)
|
18
18
|
@document_embeddings = document_embeddings
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boxcars
|
4
|
+
module VectorStores
|
5
|
+
module InMemory
|
6
|
+
MemoryVector = Struct.new(:content, :embedding, :metadatax)
|
7
|
+
|
8
|
+
class AddDocuments
|
9
|
+
include VectorStore
|
10
|
+
|
11
|
+
def initialize(embedding_tool: :openai, documents: nil)
|
12
|
+
validate_params(embedding_tool, documents)
|
13
|
+
@embedding_tool = embedding_tool
|
14
|
+
@documents = documents
|
15
|
+
@memory_vectors = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def call
|
19
|
+
texts = @documents.map { |doc| doc[:page_content] }
|
20
|
+
vectors = generate_vectors(texts)
|
21
|
+
add_vectors(vectors, @documents)
|
22
|
+
@memory_vectors
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def validate_params(embedding_tool, documents)
|
28
|
+
raise ::Boxcars::ArgumentError, 'documents is nil' unless documents
|
29
|
+
return if %i[openai tensorflow].include?(embedding_tool)
|
30
|
+
|
31
|
+
raise ::Boxcars::ArgumentError, 'embedding_tool is invalid'
|
32
|
+
end
|
33
|
+
|
34
|
+
# returns array of documents with vectors
|
35
|
+
def add_vectors(vectors, documents)
|
36
|
+
vectors.zip(documents).each do |vector, doc|
|
37
|
+
memory_vector = MemoryVector.new(doc[:page_content], vector, doc[:metadata])
|
38
|
+
@memory_vectors << memory_vector
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def generate_vectors(texts)
|
43
|
+
embeddings_method[:klass].call(
|
44
|
+
texts: texts, client: embeddings_method[:client]
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
def embeddings_method
|
49
|
+
@embeddings_method ||=
|
50
|
+
case @embedding_tool
|
51
|
+
when :openai
|
52
|
+
{ klass: Boxcars::VectorStores::EmbedViaOpenAI, client: openai_client }
|
53
|
+
when :tensorflow
|
54
|
+
{ klass: Boxcars::VectorStores::EmbedViaTensorflow, client: nil }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Get the OpenAI client
|
59
|
+
# @param openai_access_token [String] the OpenAI access token
|
60
|
+
# @return [OpenAI::Client]
|
61
|
+
def openai_client(openai_access_token: nil)
|
62
|
+
@openai_client ||= Openai.open_ai_client(openai_access_token: openai_access_token)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# require 'openai'
|
4
|
+
#
|
5
|
+
# documents = [
|
6
|
+
# { page_content: "hello", metadata: { a: 1 } },
|
7
|
+
# { page_content: "hi", metadata: { a: 1 } },
|
8
|
+
# { page_content: "bye", metadata: { a: 1 } },
|
9
|
+
# { page_content: "what's this", metadata: { a: 1 } },
|
10
|
+
# ]
|
11
|
+
#
|
12
|
+
# vector_documents = Boxcars::VectorStores::InMemory::AddDocuments.call(embedding_tool: :openai, documents: documents)
|
13
|
+
#
|
14
|
+
# result = Boxcars::VectorStores::InMemory::Search.call(vecotr_documents: vector_documents, query: "hello")
|
15
|
+
#
|
16
|
+
# expect(result).to eq(Boxcars::VectorStores::Document.new({ page_content: "hello", metadata: { a: 1 } }))
|
17
|
+
|
18
|
+
module Boxcars
|
19
|
+
module VectorStores
|
20
|
+
module InMemory
|
21
|
+
class Search
|
22
|
+
include VectorStore
|
23
|
+
def initialize(vector_documents:, query:, embedding_tool: :openai)
|
24
|
+
validate_params(vector_documents, query, embedding_tool)
|
25
|
+
@vector_documents = vector_documents
|
26
|
+
@query = query
|
27
|
+
@embedding_tool = embedding_tool
|
28
|
+
end
|
29
|
+
|
30
|
+
def call
|
31
|
+
results = @vector_documents.map do |doc|
|
32
|
+
{
|
33
|
+
document: doc,
|
34
|
+
similarity: cosine_similarity(query_vector, doc[:vector])
|
35
|
+
}
|
36
|
+
end
|
37
|
+
results.min_by { |result| -result[:similarity] }[:document]
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def validate_params(vector_documents, query, embedding_tool)
|
43
|
+
raise ::Boxcars::ArgumentError, 'query is empty' if query.to_s.empty?
|
44
|
+
raise ::Boxcars::ArgumentError, 'embedding_tool is invalid' unless %i[openai tensorflow].include?(embedding_tool)
|
45
|
+
|
46
|
+
unless vector_documents.is_a?(Array) && vector_documents.all? do |doc|
|
47
|
+
doc.is_a?(Hash) && doc.key?(:document) && doc.key?(:vector)
|
48
|
+
end
|
49
|
+
raise ::Boxcars::ArgumentError, "vector_documents is not valid"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def query_vector
|
54
|
+
embeddings_method(@embedding_tool)[:klass].call(
|
55
|
+
texts: [@query], client: embeddings_method(@embedding_tool)[:client]
|
56
|
+
).first
|
57
|
+
end
|
58
|
+
|
59
|
+
def openai_client(openai_access_token: nil)
|
60
|
+
@openai_client ||= Openai.open_ai_client(openai_access_token: openai_access_token)
|
61
|
+
end
|
62
|
+
|
63
|
+
def embeddings_method(embedding_tool)
|
64
|
+
case embedding_tool
|
65
|
+
when :openai
|
66
|
+
{ klass: Boxcars::VectorStores::EmbedViaOpenAI, client: openai_client }
|
67
|
+
when :tensorflow
|
68
|
+
{ klass: Boxcars::VectorStores::EmbedViaTensorflow, client: nil }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def cosine_similarity(vector1, vector2)
|
73
|
+
dot_product = vector1.zip(vector2).reduce(0) { |sum, (a, b)| sum + (a * b) }
|
74
|
+
magnitude1 = Math.sqrt(vector1.reduce(0) { |sum, a| sum + (a**2) })
|
75
|
+
magnitude2 = Math.sqrt(vector2.reduce(0) { |sum, b| sum + (b**2) })
|
76
|
+
dot_product / (magnitude1 * magnitude2)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'hnswlib'
|
4
4
|
|
5
5
|
module Boxcars
|
6
|
-
module
|
6
|
+
module VectorStores
|
7
7
|
class SimilaritySearch
|
8
8
|
def initialize(embeddings:, vector_store:, openai_connection: nil, openai_access_token: nil)
|
9
9
|
@embeddings = embeddings
|
@@ -23,9 +23,7 @@ module Boxcars
|
|
23
23
|
attr_reader :embeddings, :vector_store, :openai_connection
|
24
24
|
|
25
25
|
def default_connection(openai_access_token: nil)
|
26
|
-
|
27
|
-
organization_id = Boxcars.configuration.organization_id
|
28
|
-
::OpenAI::Client.new(access_token: access_token, organization_id: organization_id)
|
26
|
+
Openai.open_ai_client(openai_access_token: openai_access_token)
|
29
27
|
end
|
30
28
|
|
31
29
|
def validate_query(query)
|
@@ -34,13 +32,13 @@ module Boxcars
|
|
34
32
|
end
|
35
33
|
|
36
34
|
def convert_query_to_vector(query)
|
37
|
-
Boxcars::
|
35
|
+
Boxcars::VectorStores::EmbedViaOpenAI.call(texts: [query], client: openai_connection).first[:embedding]
|
38
36
|
end
|
39
37
|
|
40
38
|
def create_similarity_search_instance
|
41
39
|
case vector_store
|
42
40
|
when ::Hnswlib::HierarchicalNSW
|
43
|
-
Boxcars::
|
41
|
+
Boxcars::VectorStores::Hnswlib::HnswlibSearch.new(
|
44
42
|
vector_store: vector_store,
|
45
43
|
options: { json_doc_path: embeddings, num_neighbors: 2 }
|
46
44
|
)
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Boxcars
|
4
|
-
module
|
4
|
+
module VectorStores
|
5
5
|
# Split a text into chunks of a given size.
|
6
6
|
class SplitText
|
7
|
-
include
|
7
|
+
include VectorStore
|
8
8
|
|
9
9
|
attr_reader :separator, :chunk_size, :chunk_overlap, :text
|
10
10
|
|
data/lib/boxcars/boxcar.rb
CHANGED
@@ -33,15 +33,23 @@ module Boxcars
|
|
33
33
|
super(description: description, name: name)
|
34
34
|
end
|
35
35
|
|
36
|
+
# Get the OpenAI API client
|
37
|
+
# @param openai_access_token [String] The access token to use when asking the engine.
|
38
|
+
# Defaults to Boxcars.configuration.openai_access_token.
|
39
|
+
# @return [OpenAI::Client] The OpenAI API client.
|
40
|
+
def self.open_ai_client(openai_access_token: nil)
|
41
|
+
access_token = Boxcars.configuration.openai_access_token(openai_access_token: openai_access_token)
|
42
|
+
organization_id = Boxcars.configuration.organization_id
|
43
|
+
::OpenAI::Client.new(access_token: access_token, organization_id: organization_id)
|
44
|
+
end
|
45
|
+
|
36
46
|
# Get an answer from the engine.
|
37
47
|
# @param prompt [String] The prompt to use when asking the engine.
|
38
48
|
# @param openai_access_token [String] The access token to use when asking the engine.
|
39
49
|
# Defaults to Boxcars.configuration.openai_access_token.
|
40
50
|
# @param kwargs [Hash] Additional parameters to pass to the engine if wanted.
|
41
51
|
def client(prompt:, inputs: {}, openai_access_token: nil, **kwargs)
|
42
|
-
|
43
|
-
organization_id = Boxcars.configuration.organization_id
|
44
|
-
clnt = ::OpenAI::Client.new(access_token: access_token, organization_id: organization_id)
|
52
|
+
clnt = Openai.open_ai_client(openai_access_token: openai_access_token)
|
45
53
|
params = open_ai_params.merge(kwargs)
|
46
54
|
if params[:model] == "gpt-3.5-turbo"
|
47
55
|
prompt = prompt.first if prompt.is_a?(Array)
|
data/lib/boxcars/version.rb
CHANGED
data/lib/boxcars.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boxcars
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francis Sullivan
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-05-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: debug
|
@@ -120,23 +120,26 @@ files:
|
|
120
120
|
- lib/boxcars/boxcar.rb
|
121
121
|
- lib/boxcars/boxcar/active_record.rb
|
122
122
|
- lib/boxcars/boxcar/calculator.rb
|
123
|
-
- lib/boxcars/boxcar/embeddings.rb
|
124
|
-
- lib/boxcars/boxcar/embeddings/document.rb
|
125
|
-
- lib/boxcars/boxcar/embeddings/embed_via_open_ai.rb
|
126
|
-
- lib/boxcars/boxcar/embeddings/hnswlib/build_vector_store.rb
|
127
|
-
- lib/boxcars/boxcar/embeddings/hnswlib/hnswlib_config.rb
|
128
|
-
- lib/boxcars/boxcar/embeddings/hnswlib/hnswlib_search.rb
|
129
|
-
- lib/boxcars/boxcar/embeddings/hnswlib/save_to_hnswlib.rb
|
130
|
-
- lib/boxcars/boxcar/embeddings/similarity_search.rb
|
131
|
-
- lib/boxcars/boxcar/embeddings/split_text.rb
|
132
123
|
- lib/boxcars/boxcar/engine_boxcar.rb
|
133
124
|
- lib/boxcars/boxcar/google_search.rb
|
134
125
|
- lib/boxcars/boxcar/sql.rb
|
135
126
|
- lib/boxcars/boxcar/swagger.rb
|
127
|
+
- lib/boxcars/boxcar/vector_search.rb
|
128
|
+
- lib/boxcars/boxcar/vector_store.rb
|
129
|
+
- lib/boxcars/boxcar/vector_stores/document.rb
|
130
|
+
- lib/boxcars/boxcar/vector_stores/embed_via_open_ai.rb
|
131
|
+
- lib/boxcars/boxcar/vector_stores/embed_via_tensorflow.rb
|
132
|
+
- lib/boxcars/boxcar/vector_stores/hnswlib/build_vector_store.rb
|
133
|
+
- lib/boxcars/boxcar/vector_stores/hnswlib/hnswlib_config.rb
|
134
|
+
- lib/boxcars/boxcar/vector_stores/hnswlib/hnswlib_search.rb
|
135
|
+
- lib/boxcars/boxcar/vector_stores/hnswlib/save_to_hnswlib.rb
|
136
|
+
- lib/boxcars/boxcar/vector_stores/in_memory/add_documents.rb
|
137
|
+
- lib/boxcars/boxcar/vector_stores/in_memory/search.rb
|
138
|
+
- lib/boxcars/boxcar/vector_stores/similarity_search.rb
|
139
|
+
- lib/boxcars/boxcar/vector_stores/split_text.rb
|
136
140
|
- lib/boxcars/boxcar/wikipedia_search.rb
|
137
141
|
- lib/boxcars/conversation.rb
|
138
142
|
- lib/boxcars/conversation_prompt.rb
|
139
|
-
- lib/boxcars/embedding.rb
|
140
143
|
- lib/boxcars/engine.rb
|
141
144
|
- lib/boxcars/engine/engine_result.rb
|
142
145
|
- lib/boxcars/engine/gpt4all_eng.rb
|
@@ -173,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
176
|
- !ruby/object:Gem::Version
|
174
177
|
version: '0'
|
175
178
|
requirements: []
|
176
|
-
rubygems_version: 3.
|
179
|
+
rubygems_version: 3.4.10
|
177
180
|
signing_key:
|
178
181
|
specification_version: 4
|
179
182
|
summary: Boxcars is a gem that enables you to create new systems with AI composability.
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Boxcars is a framework for running a series of tools to get an answer to a question.
|
4
|
-
module Boxcars
|
5
|
-
module Embeddings
|
6
|
-
module ClassMethods
|
7
|
-
EmbeddingsError = Class.new(StandardError)
|
8
|
-
|
9
|
-
def call(*args, **kw_args)
|
10
|
-
new(*args, **kw_args).call
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.included(base)
|
15
|
-
base.extend(ClassMethods)
|
16
|
-
|
17
|
-
class << base
|
18
|
-
private :new
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
require_relative "embeddings/document"
|
25
|
-
require_relative "embeddings/embed_via_open_ai"
|
26
|
-
require_relative "embeddings/split_text"
|
27
|
-
require_relative "embeddings/similarity_search"
|
28
|
-
require_relative "embeddings/hnswlib/hnswlib_config"
|
29
|
-
require_relative "embeddings/hnswlib/save_to_hnswlib"
|
30
|
-
require_relative "embeddings/hnswlib/build_vector_store"
|
31
|
-
require_relative "embeddings/hnswlib/hnswlib_search"
|