bx_builder_chain 0.1.10 → 0.1.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d16cadffa1ec3539c314ae22581283f341ab129ebb7015377163d862f0a4c634
4
- data.tar.gz: 8b5f037a98477791dad85e7c2a257d927f0c8a41a0c78e7b0c399e645bbf3b6c
3
+ metadata.gz: eb8dc7d40d37072877b376103879593077531cecc15e4487197892eea0101c0f
4
+ data.tar.gz: d49614a734f1add1ead4e75d71fdead7b20437a41ed1a01d85780766dd75dd81
5
5
  SHA512:
6
- metadata.gz: 03ff418896064cb8bacae0d9e21a18a92a6a10ad56216ebb553c79d4d1742ec0d7d35f7b8399529f5aed2adf0a3bff5ea2564536bb343b10bf93e67456d803c7
7
- data.tar.gz: '0810e1e449e075f1516d88d4916655729850778668f4ada4e82073e32a3972a3e46675b32d122f505c06fdd35d2ad4106016b48e7bdd144e664f1383f7dfc59e'
6
+ metadata.gz: a847b3db61c0e705b06208061288690da66d2036449be89519d146b304a657ac31e1d2bd88dcae0c2ee91d8471e768b3ef7a8576222e3884199b15b9082bbb9e
7
+ data.tar.gz: eae9012d1602ad2cedf44b5173edc08eda4c17c3081a1b88808989bc1eee7540b36a2a2d01839e6a01076cab4ec26829bc569cc5a5044aa0fcb07651b0bbf66f
@@ -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").first.dig("embedding")
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
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BxBuilderChain
4
- VERSION = "0.1.10"
4
+ VERSION = "0.1.12"
5
5
  end
@@ -3,7 +3,7 @@ require 'rails/generators/active_record'
3
3
 
4
4
  module BxBuilderChain
5
5
  class InstallGenerator < Rails::Generators::Base
6
- source_root File.expand_path('../../../templates', __dir__)
6
+ source_root File.expand_path('templates', __dir__)
7
7
 
8
8
  desc "Creates BxBuilderChain initializer, migration, and copies app templates for your application"
9
9
 
@@ -1,22 +1,26 @@
1
1
  BxBuilderChain.configure do |config|
2
- config.openai_api_key = ENV['OPENAI_API_KEY']
2
+ begin
3
+ config.openai_api_key = ENV['OPENAI_API_KEY']
3
4
 
4
- # for db use this
5
- config.pg_url = ENV['DB_URL'] || nil # eg 'postgres://postgres:password@localhost:5432/my_db'
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
- # or this - pg_url with take preference
8
- config.database_host = ENV['DB_HOSTNAME'] || 'localhost'
9
- config.database_name = ENV['DB_NAME']
10
- config.database_user = ENV['DB_USER']
11
- config.database_password = ENV['DB_PASSWORD']
12
- config.database_port = ENV['DB_PORT'] || '5432' # Defaulting to 5432 if not set
13
-
14
- config.public_namespace = "public"
15
- config.threshold = 0.25
16
- config.default_prompt_template = "Context information is below
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
- select_append(Sequel.lit("#{neighbor_distance} AS neighbor_distance", value))
40
- .exclude(column => nil)
41
- .order(Sequel.lit(order, value))
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bx_builder_chain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Ketelle