bx_builder_chain 0.1.9 → 0.1.11
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/lib/bx_builder_chain/llm/open_ai.rb +7 -1
- data/lib/bx_builder_chain/version.rb +1 -1
- data/lib/generators/bx_builder_chain/templates/app/controllers/bx_builder_chain/documents_controller.rb +1 -1
- data/lib/generators/bx_builder_chain/templates/initializer.rb +22 -18
- data/lib/sequel/plugins/pgvector.rb +10 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11f1eadf29ceef8ebd78087f6c49d22c1586e5850d13489c2c6bfca14346dd80
|
4
|
+
data.tar.gz: 8ae63c3ae73284c5248d7f5a427aef2b99fdb6b298de627cd7cd810392d39a37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dca990841242d29fa54f01550a562ea8a2df2395761797a9c5f2af4dd85cfa2399ab32e98f58309d2a0ce39cc24f284078878e0b1301f6947a3ba17485ae4d03
|
7
|
+
data.tar.gz: c0ff76ccd8cd4d89be26fa24a22b7db998b5aa93291d0c46a0959aa34b2a8f878b54c271029324a2dbf2ed95cea841a548a2f5a451a4193ac7b2b0c05b03427f
|
@@ -46,7 +46,13 @@ module BxBuilderChain::Llm
|
|
46
46
|
validate_max_tokens(text, parameters[:model])
|
47
47
|
|
48
48
|
response = client.embeddings(parameters: parameters.merge(params))
|
49
|
-
response.dig("data"
|
49
|
+
embedding = response.dig("data", 0, "embedding")
|
50
|
+
|
51
|
+
return embedding if embedding
|
52
|
+
|
53
|
+
puts response
|
54
|
+
raise "Error: #{response.dig("data")}"
|
55
|
+
|
50
56
|
end
|
51
57
|
|
52
58
|
#
|
@@ -44,7 +44,7 @@ module BxBuilderChain
|
|
44
44
|
def document_service
|
45
45
|
@service ||= DocumentUploadService.new(
|
46
46
|
files: params[:files],
|
47
|
-
|
47
|
+
user_groups: current_user_document_groups,
|
48
48
|
client_class_name: CLIENT_CLASS_NAME,
|
49
49
|
llm_class_name: LLM_CLASS_NAME
|
50
50
|
)
|
@@ -1,22 +1,26 @@
|
|
1
1
|
BxBuilderChain.configure do |config|
|
2
|
-
|
2
|
+
begin
|
3
|
+
config.openai_api_key = ENV['OPENAI_API_KEY']
|
3
4
|
|
4
|
-
|
5
|
-
|
5
|
+
# for db use this
|
6
|
+
config.pg_url = ENV['DB_URL'] || nil # eg 'postgres://postgres:password@localhost:5432/my_db'
|
7
|
+
|
8
|
+
# or this - pg_url with take preference
|
9
|
+
config.database_host = ENV['TEMPLATE_DATABASE_HOSTNAME'] || 'localhost'
|
10
|
+
config.database_name = ENV['TEMPLATEAPP_DATABASE']
|
11
|
+
config.database_user = ENV['TEMPLATEAPP_DATABASE_USER']
|
12
|
+
config.database_password = ENV['TEMPLATEAPP_DATABASE_PASSWORD']
|
13
|
+
config.database_port = '5432'
|
6
14
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
%{context}
|
19
|
-
--------------------
|
20
|
-
Given the context information and not prior knowledge
|
21
|
-
answer the question: %{question}"
|
15
|
+
config.public_namespace = "public" # namespace everyone has access to
|
16
|
+
config.threshold = 0.25 # return content with a match of less than this.
|
17
|
+
config.default_prompt_template = "Context information is below
|
18
|
+
--------------------
|
19
|
+
%{context}
|
20
|
+
--------------------
|
21
|
+
Given the context information and not prior knowledge
|
22
|
+
answer the question: %{question}"
|
23
|
+
rescue StandardError => e
|
24
|
+
logger.error("Failed to set configuration: #{e.message}")
|
25
|
+
end
|
22
26
|
end
|
@@ -10,7 +10,7 @@ module Sequel
|
|
10
10
|
end
|
11
11
|
|
12
12
|
module DatasetMethods
|
13
|
-
def nearest_neighbors(column, value, distance:)
|
13
|
+
def nearest_neighbors(column, value, distance:, threshold: nil)
|
14
14
|
value = ::Pgvector.encode(value) unless value.is_a?(String)
|
15
15
|
quoted_column = quote_identifier(column)
|
16
16
|
distance = distance.to_s
|
@@ -36,9 +36,15 @@ module Sequel
|
|
36
36
|
order
|
37
37
|
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
|
40
|
+
query = select_append(Sequel.lit("#{neighbor_distance} AS neighbor_distance", value))
|
41
|
+
.exclude(column => nil)
|
42
|
+
.order(Sequel.lit(order, value))
|
43
|
+
|
44
|
+
# Apply the WHERE condition only if threshold is provided
|
45
|
+
query = query.where(Sequel.lit("(#{neighbor_distance}) < ?", value, threshold)) if threshold
|
46
|
+
|
47
|
+
query
|
42
48
|
end
|
43
49
|
end
|
44
50
|
|