completion-kit 0.28.11 → 0.28.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 +4 -4
- data/app/controllers/completion_kit/api/v1/datasets_controller.rb +8 -0
- data/app/controllers/completion_kit/imports_controller.rb +9 -0
- data/app/models/completion_kit/dataset.rb +8 -0
- data/app/services/completion_kit/promptfoo_importer.rb +5 -1
- data/lib/completion_kit/version.rb +1 -1
- data/lib/completion_kit.rb +2 -1
- 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: b2a34fdd9be7c2b821c749f4bdf7bc8433a774505f5351ed7fd605135a71f7fd
|
|
4
|
+
data.tar.gz: 906ccf1371d03af5a758a66464ffca8924ab4df36653113ea08a087f47237758
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4a5a11320e41d14a8de77fc2ad38e60830e6de94aa60e539d517963c9089f8538ccb82abce9f3274976aad5030e2468615ecbbb5b081507e3ecfc222aa3471c6
|
|
7
|
+
data.tar.gz: 5d0d2496547c1b834218b1eed208a186eff5f1cd82924eae22753740d78817609808afb249c25fd66cd7132c26963ce625e921c95803d7cadcf63029c1b8c7f4
|
|
@@ -3,6 +3,7 @@ module CompletionKit
|
|
|
3
3
|
module V1
|
|
4
4
|
class DatasetsController < BaseController
|
|
5
5
|
before_action :set_dataset, only: [:show, :update, :destroy]
|
|
6
|
+
before_action :reject_oversized_upload, only: [:create, :update]
|
|
6
7
|
|
|
7
8
|
def index
|
|
8
9
|
scope = Dataset.includes(:tags)
|
|
@@ -50,6 +51,13 @@ module CompletionKit
|
|
|
50
51
|
permitted[:csv_data] = upload.read.to_s.force_encoding("UTF-8") if upload.respond_to?(:read)
|
|
51
52
|
permitted
|
|
52
53
|
end
|
|
54
|
+
|
|
55
|
+
def reject_oversized_upload
|
|
56
|
+
upload = params[:file]
|
|
57
|
+
return unless upload.respond_to?(:size) && upload.size > CompletionKit.config.max_upload_bytes
|
|
58
|
+
|
|
59
|
+
render_error("File exceeds the #{CompletionKit.config.max_upload_bytes / (1024 * 1024)} MB upload limit", status: :payload_too_large)
|
|
60
|
+
end
|
|
53
61
|
end
|
|
54
62
|
end
|
|
55
63
|
end
|
|
@@ -4,6 +4,11 @@ module CompletionKit
|
|
|
4
4
|
end
|
|
5
5
|
|
|
6
6
|
def create
|
|
7
|
+
if upload_too_large?(params[:file])
|
|
8
|
+
flash.now[:alert] = "That file is too large. The limit is #{CompletionKit.config.max_upload_bytes / (1024 * 1024)} MB."
|
|
9
|
+
return render :new, status: :payload_too_large
|
|
10
|
+
end
|
|
11
|
+
|
|
7
12
|
content = uploaded_content
|
|
8
13
|
|
|
9
14
|
if content.blank?
|
|
@@ -27,5 +32,9 @@ module CompletionKit
|
|
|
27
32
|
file = params[:file]
|
|
28
33
|
file.respond_to?(:read) ? file.read : params[:config]
|
|
29
34
|
end
|
|
35
|
+
|
|
36
|
+
def upload_too_large?(file)
|
|
37
|
+
file.respond_to?(:size) && file.size > CompletionKit.config.max_upload_bytes
|
|
38
|
+
end
|
|
30
39
|
end
|
|
31
40
|
end
|
|
@@ -6,6 +6,14 @@ module CompletionKit
|
|
|
6
6
|
|
|
7
7
|
validates :name, presence: true
|
|
8
8
|
validates :csv_data, presence: true
|
|
9
|
+
validate :csv_data_within_size_limit
|
|
10
|
+
|
|
11
|
+
def csv_data_within_size_limit
|
|
12
|
+
return if csv_data.blank?
|
|
13
|
+
return if csv_data.bytesize <= CompletionKit.config.max_upload_bytes
|
|
14
|
+
|
|
15
|
+
errors.add(:csv_data, "is too large (limit #{CompletionKit.config.max_upload_bytes / (1024 * 1024)} MB)")
|
|
16
|
+
end
|
|
9
17
|
|
|
10
18
|
def as_json(options = {})
|
|
11
19
|
{
|
|
@@ -16,6 +16,10 @@ module CompletionKit
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def call
|
|
19
|
+
if @content.bytesize > CompletionKit.config.max_upload_bytes
|
|
20
|
+
return failure("The import is too large. The limit is #{CompletionKit.config.max_upload_bytes / (1024 * 1024)} MB.")
|
|
21
|
+
end
|
|
22
|
+
|
|
19
23
|
config = parse
|
|
20
24
|
return failure("Could not parse YAML: #{@parse_error}") if config.nil?
|
|
21
25
|
return failure("Top-level YAML must be a mapping of promptfoo config keys.") unless config.is_a?(Hash)
|
|
@@ -34,7 +38,7 @@ module CompletionKit
|
|
|
34
38
|
private
|
|
35
39
|
|
|
36
40
|
def parse
|
|
37
|
-
YAML.safe_load(@content
|
|
41
|
+
YAML.safe_load(@content)
|
|
38
42
|
rescue Psych::Exception => e
|
|
39
43
|
@parse_error = e.message
|
|
40
44
|
nil
|
data/lib/completion_kit.rb
CHANGED
|
@@ -11,7 +11,7 @@ module CompletionKit
|
|
|
11
11
|
attr_accessor :tenant_scope, :tenant_scope_columns
|
|
12
12
|
attr_accessor :api_reference_authentication_partial
|
|
13
13
|
attr_accessor :runs_display_scope, :runs_display_footer_partial
|
|
14
|
-
attr_accessor :api_rate_limit, :web_rate_limit
|
|
14
|
+
attr_accessor :api_rate_limit, :web_rate_limit, :max_upload_bytes
|
|
15
15
|
attr_accessor :allow_loopback_endpoints
|
|
16
16
|
attr_accessor :judge_agreement_enabled
|
|
17
17
|
attr_accessor :judge_examples_from_reviews
|
|
@@ -30,6 +30,7 @@ module CompletionKit
|
|
|
30
30
|
|
|
31
31
|
@api_rate_limit = 120
|
|
32
32
|
@web_rate_limit = 300
|
|
33
|
+
@max_upload_bytes = 25 * 1024 * 1024
|
|
33
34
|
|
|
34
35
|
@allow_loopback_endpoints = true
|
|
35
36
|
@judge_agreement_enabled = true
|