bx_builder_chain 0.1.4 → 0.1.5

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: 9398159d26923acd8ac5f3c51675e2934dd14a89f1fd97ce088f7cd751721425
4
- data.tar.gz: 1f272643f2c6661e11a72e7221f2497cbc27a8f843b91b71a31a63df0d184e13
3
+ metadata.gz: 29bc947f6ea34473e5155d3baf25d46056fde59bbdc24f8f79724e4d135cebd6
4
+ data.tar.gz: e1bfb8c5329ed636f0b31935c8010aea7fa4820a90444bbe8275c23ae325da65
5
5
  SHA512:
6
- metadata.gz: 88d787f0ab0ff4e7a33ef5faeae4f8bb0ae18834bd3aa36fe0d82aeedee57ae9e7f6cea770915924638b08ff2c185be83fa7a132fd40f3effe602534d1528bac
7
- data.tar.gz: c943c30ea2343e02d1c7ac98ac581b5da2ad821eb33e75595bde76756b0245785f1756671be5850350126ff6fe2d3839ef66906535f2cd5fe4a42c3a7403e057
6
+ metadata.gz: 249e336c873a34f643c84d97c08f65c8af3ad517e961410711b23d4e312db1e88e48ea1f11e2a10cdd50507b3a6811d0912e0256e601e401a36347d01788416b
7
+ data.tar.gz: 9b77e5330cebdb6008b8d7c7d4a8771fb1fb607e22af0bbf0c1e7867ae14d65c2e902717af15b487de43c6db2da81df3c784f0c0026f0b4fded16d2bf01bbbfa
data/README.md CHANGED
@@ -20,30 +20,57 @@ If bundler is not being used to manage dependencies, install the gem by executin
20
20
 
21
21
  $ gem install bx_builder_chain
22
22
 
23
- TODO: add rake task to create db structure
24
- ### Optional
25
23
 
26
- generate the endpoint & Active admin contollers for Builder Chain
24
+ ### Setup
27
25
 
28
- $ rails generate builder_chain:endpoints
26
+ generate the endpoints & Active admin contollers for Builder Chain along with the DB migrations
27
+
28
+ $ rails generate builder_chain:install
29
29
 
30
30
  this will add the following endpoint controllers
31
31
  - File upload
32
+ - List files
33
+ - Delete file
32
34
  - OpenAi ask / completion
33
35
  - ActiveAdmin documents controller
34
36
 
37
+ It will also add a test view / controller for testing the endpoints. ensure this is removed prior to production release
38
+
35
39
  ## Usage
36
40
  ```ruby
37
41
  require "bx_builder_chain"
38
42
  ```
39
43
 
44
+ edit the initializer config 'bx_builder_chain.rb' setup the api keys and db credentials
45
+ ```
46
+ BxBuilderChain.configure do |config|
47
+ config.openai_api_key = ENV['OPENAI_API_KEY']
48
+
49
+ # for db use this
50
+ config.pg_url = ENV['DB_URL'] || nil # eg 'postgres://postgres:password@localhost:5432/my_db'
51
+
52
+ # or this - pg_url with take preference
53
+ config.database_host = ENV['DB_HOSTNAME'] || 'localhost'
54
+ config.database_name = ENV['DB_NAME']
55
+ config.database_user = ENV['DB_USER']
56
+ config.database_password = ENV['DB_PASSWORD']
57
+ config.database_port = ENV['DB_PORT'] || '5432' # Defaulting to 5432 if not set
58
+
59
+ config.public_namespace = "public"
60
+ config.threshold = 0.25
61
+ config.default_prompt_template = "Context information is below
62
+ --------------------
63
+ %{context}
64
+ --------------------
65
+ Given the context information and not prior knowledge
66
+ answer the question: %{question}"
67
+ end
68
+ ```
69
+
40
70
  create the llm and client
41
71
  ```ruby
42
- llm = BxBuilderChain::Llm::OpenAi.new(api_key: 'open-ai-api-key')
43
72
  client = BxBuilderChain::Vectorsearch::Pgvector.new(
44
- url: 'postgres://postgres:password@localhost:5432/test', # postgres db url
45
- table_name: "embeddings", # table name for the documents to be stored
46
- llm: llm,
73
+ llm: BxBuilderChain::Llm::OpenAi.new,
47
74
  namespace: user_id # default is nil, nil is used for global public documents
48
75
  )
49
76
  ```
@@ -68,6 +95,22 @@ my_docx = "path/to/my.docx"
68
95
  client.add_data(paths: [my_pdf, my_text, my_docx])
69
96
  ```
70
97
 
98
+ Or via the service object
99
+ ```ruby
100
+ my_pdf = "path/to/my.pdf"
101
+ my_text = "path/to/my.txt"
102
+ my_docx = "path/to/my.docx"
103
+
104
+ service = DocumentUploadService.new(
105
+ files: [my_pdf, my_text, my_docx],
106
+ user_groups: current_user_document_groups, # optional defaults to ['public'] an uses the first value to store the docs
107
+ client_class_name: CLIENT_CLASS_NAME, # optional defaults to 'BxBuilderChain::Vectorsearch::Pgvector'
108
+ llm_class_name: LLM_CLASS_NAME # optional defaults to 'BxBuilderChain::Llm::OpenAi'
109
+ )
110
+
111
+ result = service.upload_and_process
112
+ ```
113
+
71
114
  Then ask the question
72
115
  ```ruby
73
116
  client.ask(question: "What is Frogger?")
@@ -39,7 +39,8 @@ module BxBuilderChain
39
39
  def self.token_limit(model_name)
40
40
  TOKEN_LIMITS[model_name]
41
41
  end
42
- def self.validate_max_tokens!(content, model_name, options = {})
42
+
43
+ def self.validate_max_tokens!(content, model_name, options = {})
43
44
  text_token_length = if content.is_a?(Array)
44
45
  content.sum { |item| token_length(item.to_json, model_name, options) }
45
46
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BxBuilderChain
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bx_builder_chain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Ketelle
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-02 00:00:00.000000000 Z
11
+ date: 2023-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk