completion-kit 0.5.33 → 0.5.34
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/assets/stylesheets/completion_kit/application.css.erb +31 -0
- data/app/helpers/completion_kit/application_helper.rb +14 -0
- data/app/models/completion_kit/provider_credential.rb +4 -24
- data/app/services/completion_kit/api_config.rb +20 -14
- data/app/services/completion_kit/ollama_client.rb +5 -1
- data/app/services/completion_kit/provider_endpoint.rb +47 -0
- data/app/views/completion_kit/datasets/_form.html.erb +5 -3
- data/app/views/completion_kit/datasets/index.html.erb +6 -6
- data/app/views/completion_kit/metric_groups/index.html.erb +5 -5
- data/app/views/completion_kit/metrics/_form.html.erb +5 -3
- data/app/views/completion_kit/metrics/index.html.erb +5 -5
- data/app/views/completion_kit/prompts/_form.html.erb +7 -4
- data/app/views/completion_kit/prompts/index.html.erb +7 -7
- data/app/views/completion_kit/provider_credentials/_form.html.erb +5 -3
- data/app/views/completion_kit/responses/show.html.erb +1 -1
- data/app/views/completion_kit/runs/_form.html.erb +5 -3
- data/app/views/completion_kit/runs/_response_row.html.erb +1 -1
- data/app/views/completion_kit/runs/_row.html.erb +1 -1
- data/app/views/completion_kit/runs/_status_header.html.erb +2 -2
- data/app/views/completion_kit/runs/_status_panel.html.erb +1 -1
- data/app/views/completion_kit/runs/_table.html.erb +6 -6
- data/app/views/completion_kit/suggestions/show.html.erb +1 -1
- data/app/views/completion_kit/tags/_picker.html.erb +2 -2
- data/app/views/completion_kit/tags/index.html.erb +4 -4
- data/lib/completion_kit/version.rb +1 -1
- data/lib/completion_kit.rb +3 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d6a67c2ef67eff4762711f38e46cb5df85b9136a6de59a82d962a54ef2c1466c
|
|
4
|
+
data.tar.gz: 01f86625fec3d18ee712e61d0d601687571125e8333e5f468d3c151f9714651b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 33335e4a89da8b1eb264663c50570841a7afeda8b48bcad1178b2185ceee5ec2148e1e57ea4248835e550ca936a5bccd4ece6819070cde7f44c3ef312aa40970
|
|
7
|
+
data.tar.gz: 39b1e8845d2dea0e2ac6bed5679336d639ea501796b0e15242eeef42db3e9313eaeccaa59268d11a2fcb52ce7c110634374f16fa4d7721494c6474caa524b97e
|
|
@@ -5088,3 +5088,34 @@ a.tag-mark {
|
|
|
5088
5088
|
letter-spacing: 0.04em;
|
|
5089
5089
|
text-transform: uppercase;
|
|
5090
5090
|
}
|
|
5091
|
+
|
|
5092
|
+
.ck-record-name {
|
|
5093
|
+
color: inherit;
|
|
5094
|
+
text-decoration: none;
|
|
5095
|
+
}
|
|
5096
|
+
.ck-record-name:hover,
|
|
5097
|
+
.ck-record-name:focus-visible {
|
|
5098
|
+
color: var(--ck-accent);
|
|
5099
|
+
}
|
|
5100
|
+
|
|
5101
|
+
.ck-field-error {
|
|
5102
|
+
color: var(--ck-error, #d93232);
|
|
5103
|
+
font-size: 0.85rem;
|
|
5104
|
+
margin: 4px 0 0;
|
|
5105
|
+
}
|
|
5106
|
+
|
|
5107
|
+
.ck-visually-hidden {
|
|
5108
|
+
position: absolute;
|
|
5109
|
+
width: 1px;
|
|
5110
|
+
height: 1px;
|
|
5111
|
+
padding: 0;
|
|
5112
|
+
margin: -1px;
|
|
5113
|
+
overflow: hidden;
|
|
5114
|
+
clip: rect(0 0 0 0);
|
|
5115
|
+
white-space: nowrap;
|
|
5116
|
+
border: 0;
|
|
5117
|
+
}
|
|
5118
|
+
.tag-mark:focus-within {
|
|
5119
|
+
outline: 2px solid var(--ck-accent);
|
|
5120
|
+
outline-offset: 2px;
|
|
5121
|
+
}
|
|
@@ -218,6 +218,20 @@ module CompletionKit
|
|
|
218
218
|
"#{base_path}?#{{ tag: next_set.map(&:name) }.to_query}"
|
|
219
219
|
end
|
|
220
220
|
|
|
221
|
+
def ck_field_aria(form, field)
|
|
222
|
+
return {} unless form.object.errors[field].any?
|
|
223
|
+
{ "aria-invalid" => "true", "aria-describedby" => ck_field_error_id(form, field) }
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def ck_field_error(form, field)
|
|
227
|
+
return nil unless form.object.errors[field].any?
|
|
228
|
+
content_tag(:p, form.object.errors[field].first, class: "ck-field-error", id: ck_field_error_id(form, field))
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def ck_field_error_id(form, field)
|
|
232
|
+
"#{form.object.model_name.param_key}_#{field}_error"
|
|
233
|
+
end
|
|
234
|
+
|
|
221
235
|
private
|
|
222
236
|
|
|
223
237
|
def diff_tokens(old_text, new_text, side)
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
require "ipaddr"
|
|
2
|
-
require "resolv"
|
|
3
|
-
|
|
4
1
|
module CompletionKit
|
|
5
2
|
class ProviderCredential < ApplicationRecord
|
|
6
3
|
include Turbo::Broadcastable
|
|
@@ -8,7 +5,7 @@ module CompletionKit
|
|
|
8
5
|
PROVIDER_LABELS = {
|
|
9
6
|
"openai" => "OpenAI",
|
|
10
7
|
"anthropic" => "Anthropic",
|
|
11
|
-
"ollama" => "Ollama /
|
|
8
|
+
"ollama" => "Ollama / OpenAI-compatible endpoint",
|
|
12
9
|
"openrouter" => "OpenRouter"
|
|
13
10
|
}.freeze
|
|
14
11
|
|
|
@@ -139,29 +136,12 @@ module CompletionKit
|
|
|
139
136
|
def api_endpoint_not_internal
|
|
140
137
|
return if api_endpoint.blank?
|
|
141
138
|
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
issues = ProviderEndpoint.validate(api_endpoint)
|
|
140
|
+
if issues.include?(:invalid_url)
|
|
144
141
|
errors.add(:api_endpoint, "must be a valid http or https URL")
|
|
145
|
-
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
if endpoint_addresses(uri.host).any? { |ip| ip.private? || ip.link_local? }
|
|
142
|
+
elsif issues.include?(:unsafe_host)
|
|
149
143
|
errors.add(:api_endpoint, "must not point at a private or internal address")
|
|
150
144
|
end
|
|
151
145
|
end
|
|
152
|
-
|
|
153
|
-
def safe_http_uri(value)
|
|
154
|
-
uri = URI.parse(value.to_s.strip)
|
|
155
|
-
uri if uri.is_a?(URI::HTTP) && uri.host.present?
|
|
156
|
-
rescue URI::InvalidURIError
|
|
157
|
-
nil
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
def endpoint_addresses(host)
|
|
161
|
-
bare = host.delete_prefix("[").delete_suffix("]")
|
|
162
|
-
[IPAddr.new(bare)]
|
|
163
|
-
rescue IPAddr::InvalidAddressError
|
|
164
|
-
Resolv.getaddresses(host).map { |addr| IPAddr.new(addr) }
|
|
165
|
-
end
|
|
166
146
|
end
|
|
167
147
|
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
module CompletionKit
|
|
2
2
|
class ApiConfig
|
|
3
|
+
PROVIDERS = %w[openai anthropic ollama openrouter].freeze
|
|
4
|
+
|
|
3
5
|
def self.for_model(model_name)
|
|
4
6
|
provider = provider_for_model(model_name)
|
|
5
7
|
provider ? for_provider(provider) : {}
|
|
@@ -9,21 +11,25 @@ module CompletionKit
|
|
|
9
11
|
provider = provider_name.to_s
|
|
10
12
|
stored = ProviderCredential.find_by(provider: provider)&.config_hash || {}
|
|
11
13
|
|
|
12
|
-
defaults =
|
|
13
|
-
|
|
14
|
-
{ provider: "openai", api_key: CompletionKit.config.openai_api_key || ENV["OPENAI_API_KEY"] }
|
|
15
|
-
when "anthropic"
|
|
16
|
-
{ provider: "anthropic", api_key: CompletionKit.config.anthropic_api_key || ENV["ANTHROPIC_API_KEY"] }
|
|
17
|
-
when "ollama"
|
|
18
|
-
{
|
|
19
|
-
provider: "ollama",
|
|
20
|
-
api_key: CompletionKit.config.ollama_api_key || ENV["OLLAMA_API_KEY"],
|
|
21
|
-
api_endpoint: CompletionKit.config.ollama_api_endpoint || ENV["OLLAMA_API_ENDPOINT"]
|
|
22
|
-
}
|
|
23
|
-
when "openrouter"
|
|
24
|
-
{ provider: "openrouter", api_key: ENV["OPENROUTER_API_KEY"] }
|
|
14
|
+
defaults = if CompletionKit.config.tenant_scope
|
|
15
|
+
PROVIDERS.include?(provider) ? { provider: provider } : {}
|
|
25
16
|
else
|
|
26
|
-
|
|
17
|
+
case provider
|
|
18
|
+
when "openai"
|
|
19
|
+
{ provider: "openai", api_key: CompletionKit.config.openai_api_key || ENV["OPENAI_API_KEY"] }
|
|
20
|
+
when "anthropic"
|
|
21
|
+
{ provider: "anthropic", api_key: CompletionKit.config.anthropic_api_key || ENV["ANTHROPIC_API_KEY"] }
|
|
22
|
+
when "ollama"
|
|
23
|
+
{
|
|
24
|
+
provider: "ollama",
|
|
25
|
+
api_key: CompletionKit.config.ollama_api_key || ENV["OLLAMA_API_KEY"],
|
|
26
|
+
api_endpoint: CompletionKit.config.ollama_api_endpoint || ENV["OLLAMA_API_ENDPOINT"]
|
|
27
|
+
}
|
|
28
|
+
when "openrouter"
|
|
29
|
+
{ provider: "openrouter", api_key: ENV["OPENROUTER_API_KEY"] }
|
|
30
|
+
else
|
|
31
|
+
{}
|
|
32
|
+
end
|
|
27
33
|
end
|
|
28
34
|
|
|
29
35
|
defaults.merge(stored.compact)
|
|
@@ -7,6 +7,7 @@ module CompletionKit
|
|
|
7
7
|
def generate_completion(prompt, options = {})
|
|
8
8
|
@temperature_dropped = false
|
|
9
9
|
return "Error: API endpoint not configured" unless configured?
|
|
10
|
+
return "Error: API endpoint resolves to a private address" unless ProviderEndpoint.safe?(api_endpoint)
|
|
10
11
|
|
|
11
12
|
model = options[:model]
|
|
12
13
|
max_tokens = options[:max_tokens] || 1000
|
|
@@ -44,6 +45,7 @@ module CompletionKit
|
|
|
44
45
|
|
|
45
46
|
def available_models
|
|
46
47
|
return [] unless configured?
|
|
48
|
+
return [] unless ProviderEndpoint.safe?(api_endpoint)
|
|
47
49
|
|
|
48
50
|
response = build_connection(api_endpoint).get("/v1/models") do |req|
|
|
49
51
|
req.headers["Authorization"] = "Bearer #{api_key}" if api_key.present?
|
|
@@ -74,7 +76,9 @@ module CompletionKit
|
|
|
74
76
|
end
|
|
75
77
|
|
|
76
78
|
def api_endpoint
|
|
77
|
-
|
|
79
|
+
raw = @config[:api_endpoint] || ENV["OLLAMA_API_ENDPOINT"]
|
|
80
|
+
raw ||= "http://localhost:11434/v1" if CompletionKit.config.allow_loopback_endpoints
|
|
81
|
+
raw.to_s.delete_suffix("/")
|
|
78
82
|
end
|
|
79
83
|
|
|
80
84
|
def post_completion(model:, prompt:, max_tokens:, temperature:)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require "ipaddr"
|
|
2
|
+
require "resolv"
|
|
3
|
+
|
|
4
|
+
module CompletionKit
|
|
5
|
+
module ProviderEndpoint
|
|
6
|
+
ZERO_NET = IPAddr.new("0.0.0.0/8").freeze
|
|
7
|
+
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
def validate(url)
|
|
11
|
+
uri = parse(url)
|
|
12
|
+
return [:invalid_url] unless uri
|
|
13
|
+
addrs = addresses(uri.host)
|
|
14
|
+
return [:unresolvable] if addrs.empty?
|
|
15
|
+
return [:unsafe_host] if addrs.any? { |ip| unsafe?(ip) }
|
|
16
|
+
[]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def safe?(url)
|
|
20
|
+
errors = validate(url)
|
|
21
|
+
errors.empty? || errors == [:unresolvable]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def parse(value)
|
|
25
|
+
uri = URI.parse(value.to_s.strip)
|
|
26
|
+
uri if uri.is_a?(URI::HTTP) && uri.host.present?
|
|
27
|
+
rescue URI::InvalidURIError
|
|
28
|
+
nil
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def addresses(host)
|
|
32
|
+
bare = host.delete_prefix("[").delete_suffix("]")
|
|
33
|
+
[IPAddr.new(bare)]
|
|
34
|
+
rescue IPAddr::InvalidAddressError
|
|
35
|
+
Resolv.getaddresses(host).map { |addr| IPAddr.new(addr) }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def unsafe?(ip)
|
|
39
|
+
return true if ip.private?
|
|
40
|
+
return true if ip.link_local?
|
|
41
|
+
return true if ip.to_i.zero?
|
|
42
|
+
return true if ip.ipv4? && ZERO_NET.include?(ip)
|
|
43
|
+
return true if ip.loopback? && !CompletionKit.config.allow_loopback_endpoints
|
|
44
|
+
false
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<%= form_with(model: dataset, local: true) do |form| %>
|
|
2
2
|
<% if dataset.errors.any? %>
|
|
3
|
-
<div class="ck-flash ck-flash--alert">
|
|
3
|
+
<div class="ck-flash ck-flash--alert" role="alert">
|
|
4
4
|
<p class="ck-flash__title"><%= pluralize(dataset.errors.count, "problem") %> prevented this dataset from being saved.</p>
|
|
5
5
|
<ul class="ck-error-list">
|
|
6
6
|
<% dataset.errors.full_messages.each do |message| %>
|
|
@@ -13,12 +13,14 @@
|
|
|
13
13
|
<div class="ck-card ck-form-card">
|
|
14
14
|
<div class="ck-field">
|
|
15
15
|
<%= form.label :name, "Name", class: "ck-label" %>
|
|
16
|
-
<%= form.text_field :name, class: "ck-input", placeholder: "Customer support tickets" %>
|
|
16
|
+
<%= form.text_field :name, class: "ck-input", placeholder: "Customer support tickets", **ck_field_aria(form, :name) %>
|
|
17
|
+
<%= ck_field_error(form, :name) %>
|
|
17
18
|
</div>
|
|
18
19
|
|
|
19
20
|
<div class="ck-field">
|
|
20
21
|
<%= form.label :csv_data, "CSV data", class: "ck-label" %>
|
|
21
|
-
<%= form.text_area :csv_data, rows: 12, class: "ck-input ck-input--area ck-input--code", placeholder: "content,audience\nFirst ticket text,internal\nSecond ticket text,customer" %>
|
|
22
|
+
<%= form.text_area :csv_data, rows: 12, class: "ck-input ck-input--area ck-input--code", placeholder: "content,audience\nFirst ticket text,internal\nSecond ticket text,customer", **ck_field_aria(form, :csv_data) %>
|
|
23
|
+
<%= ck_field_error(form, :csv_data) %>
|
|
22
24
|
</div>
|
|
23
25
|
|
|
24
26
|
<%= render "completion_kit/tags/picker", record: dataset, param_namespace: :dataset %>
|
|
@@ -17,18 +17,18 @@
|
|
|
17
17
|
<table class="ck-results-table ck-datasets-table">
|
|
18
18
|
<thead>
|
|
19
19
|
<tr>
|
|
20
|
-
<th>Name</th>
|
|
21
|
-
<th>Rows</th>
|
|
22
|
-
<th>Used in</th>
|
|
23
|
-
<th>Created</th>
|
|
24
|
-
<th></th>
|
|
20
|
+
<th scope="col">Name</th>
|
|
21
|
+
<th scope="col">Rows</th>
|
|
22
|
+
<th scope="col">Used in</th>
|
|
23
|
+
<th scope="col">Created</th>
|
|
24
|
+
<th scope="col"></th>
|
|
25
25
|
</tr>
|
|
26
26
|
</thead>
|
|
27
27
|
<tbody>
|
|
28
28
|
<% @datasets.each do |dataset| %>
|
|
29
29
|
<tr onclick="window.location='<%= dataset_path(dataset) %>'" style="cursor: pointer;">
|
|
30
30
|
<td>
|
|
31
|
-
|
|
31
|
+
<%= link_to dataset_path(dataset), class: "ck-record-name" do %><strong><%= dataset.name %></strong><% end %>
|
|
32
32
|
<% if dataset.tags.any? %>
|
|
33
33
|
<div class="tag-marks-row">
|
|
34
34
|
<%= render "completion_kit/tags/marks", tags: dataset.tags %>
|
|
@@ -22,17 +22,17 @@
|
|
|
22
22
|
<table class="ck-results-table ck-metric-groups-table">
|
|
23
23
|
<thead>
|
|
24
24
|
<tr>
|
|
25
|
-
<th>Name</th>
|
|
26
|
-
<th>Description</th>
|
|
27
|
-
<th>Members</th>
|
|
28
|
-
<th></th>
|
|
25
|
+
<th scope="col">Name</th>
|
|
26
|
+
<th scope="col">Description</th>
|
|
27
|
+
<th scope="col">Members</th>
|
|
28
|
+
<th scope="col"></th>
|
|
29
29
|
</tr>
|
|
30
30
|
</thead>
|
|
31
31
|
<tbody>
|
|
32
32
|
<% @metric_groups.each do |metric_group| %>
|
|
33
33
|
<tr onclick="window.location='<%= metric_group_path(metric_group) %>'" style="cursor: pointer;">
|
|
34
34
|
<td>
|
|
35
|
-
|
|
35
|
+
<%= link_to metric_group_path(metric_group), class: "ck-record-name" do %><strong><%= metric_group.name %></strong><% end %>
|
|
36
36
|
<% if metric_group.tags.any? %>
|
|
37
37
|
<div class="tag-marks-row">
|
|
38
38
|
<%= render "completion_kit/tags/marks", tags: metric_group.tags %>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<%= form_with(model: metric, local: true) do |form| %>
|
|
2
2
|
<% if metric.errors.any? %>
|
|
3
|
-
<div class="ck-flash ck-flash--alert">
|
|
3
|
+
<div class="ck-flash ck-flash--alert" role="alert">
|
|
4
4
|
<p class="ck-flash__title"><%= pluralize(metric.errors.count, "problem") %> prevented this metric from being saved.</p>
|
|
5
5
|
<ul class="ck-error-list">
|
|
6
6
|
<% metric.errors.full_messages.each do |message| %>
|
|
@@ -13,13 +13,15 @@
|
|
|
13
13
|
<div class="ck-card ck-form-card">
|
|
14
14
|
<div class="ck-field">
|
|
15
15
|
<%= form.label :name, "Metric name", class: "ck-label" %>
|
|
16
|
-
<%= form.text_field :name, class: "ck-input", placeholder: "Helpfulness" %>
|
|
16
|
+
<%= form.text_field :name, class: "ck-input", placeholder: "Helpfulness", **ck_field_aria(form, :name) %>
|
|
17
|
+
<%= ck_field_error(form, :name) %>
|
|
17
18
|
</div>
|
|
18
19
|
|
|
19
20
|
<div class="ck-field ck-field--spacious">
|
|
20
21
|
<p class="ck-section-title">Instruction</p>
|
|
21
22
|
<p class="ck-hint">What should the judge assess? This instruction is sent to the LLM judge when scoring outputs.</p>
|
|
22
|
-
<%= form.text_area :instruction, rows: 8, class: "ck-input ck-input--area", placeholder: "Evaluate whether the output..." %>
|
|
23
|
+
<%= form.text_area :instruction, rows: 8, class: "ck-input ck-input--area", placeholder: "Evaluate whether the output...", **ck_field_aria(form, :instruction) %>
|
|
24
|
+
<%= ck_field_error(form, :instruction) %>
|
|
23
25
|
</div>
|
|
24
26
|
|
|
25
27
|
<div class="ck-field ck-field--spacious">
|
|
@@ -17,17 +17,17 @@
|
|
|
17
17
|
<table class="ck-results-table ck-metrics-table">
|
|
18
18
|
<thead>
|
|
19
19
|
<tr>
|
|
20
|
-
<th>Name</th>
|
|
21
|
-
<th>Instruction</th>
|
|
22
|
-
<th>In groups</th>
|
|
23
|
-
<th></th>
|
|
20
|
+
<th scope="col">Name</th>
|
|
21
|
+
<th scope="col">Instruction</th>
|
|
22
|
+
<th scope="col">In groups</th>
|
|
23
|
+
<th scope="col"></th>
|
|
24
24
|
</tr>
|
|
25
25
|
</thead>
|
|
26
26
|
<tbody>
|
|
27
27
|
<% @metrics.each do |metric| %>
|
|
28
28
|
<tr onclick="window.location='<%= metric_path(metric) %>'" style="cursor: pointer;">
|
|
29
29
|
<td>
|
|
30
|
-
|
|
30
|
+
<%= link_to metric_path(metric), class: "ck-record-name" do %><strong><%= metric.name %></strong><% end %>
|
|
31
31
|
<% if metric.tags.any? %>
|
|
32
32
|
<div class="tag-marks-row">
|
|
33
33
|
<%= render "completion_kit/tags/marks", tags: metric.tags %>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<%= form_with(model: prompt, local: true) do |form| %>
|
|
2
2
|
<% if prompt.errors.any? %>
|
|
3
|
-
<div class="ck-flash ck-flash--alert">
|
|
3
|
+
<div class="ck-flash ck-flash--alert" role="alert">
|
|
4
4
|
<p class="ck-flash__title"><%= pluralize(prompt.errors.count, "problem") %> prevented this prompt from being saved.</p>
|
|
5
5
|
<ul class="ck-error-list">
|
|
6
6
|
<% prompt.errors.full_messages.each do |message| %>
|
|
@@ -17,17 +17,20 @@
|
|
|
17
17
|
<div class="ck-card ck-form-card">
|
|
18
18
|
<div class="ck-field">
|
|
19
19
|
<%= form.label :name, "Name", class: "ck-label" %>
|
|
20
|
-
<%= form.text_field :name, class: "ck-input", placeholder: "Support summary", autocomplete: "off", data: { "1p-ignore": "" } %>
|
|
20
|
+
<%= form.text_field :name, class: "ck-input", placeholder: "Support summary", autocomplete: "off", data: { "1p-ignore": "" }, **ck_field_aria(form, :name) %>
|
|
21
|
+
<%= ck_field_error(form, :name) %>
|
|
21
22
|
</div>
|
|
22
23
|
|
|
23
24
|
<div class="ck-field">
|
|
24
25
|
<%= form.label :description, class: "ck-label" %>
|
|
25
|
-
<%= form.text_area :description, rows: 3, class: "ck-input ck-input--area", placeholder: "Short note about this prompt." %>
|
|
26
|
+
<%= form.text_area :description, rows: 3, class: "ck-input ck-input--area", placeholder: "Short note about this prompt.", **ck_field_aria(form, :description) %>
|
|
27
|
+
<%= ck_field_error(form, :description) %>
|
|
26
28
|
</div>
|
|
27
29
|
|
|
28
30
|
<div class="ck-field">
|
|
29
31
|
<%= form.label :template, "Prompt text", class: "ck-label" %>
|
|
30
|
-
<%= form.text_area :template, rows: 12, class: "ck-input ck-input--area ck-input--code", placeholder: "Summarize {{content}} for {{audience}}" %>
|
|
32
|
+
<%= form.text_area :template, rows: 12, class: "ck-input ck-input--area ck-input--code", placeholder: "Summarize {{content}} for {{audience}}", **ck_field_aria(form, :template) %>
|
|
33
|
+
<%= ck_field_error(form, :template) %>
|
|
31
34
|
<p class="ck-hint">Use <code>{{variable}}</code>. Match your dataset column names.</p>
|
|
32
35
|
</div>
|
|
33
36
|
|
|
@@ -17,19 +17,19 @@
|
|
|
17
17
|
<table class="ck-results-table ck-prompts-table">
|
|
18
18
|
<thead>
|
|
19
19
|
<tr>
|
|
20
|
-
<th>Name</th>
|
|
21
|
-
<th>Version</th>
|
|
22
|
-
<th>Model</th>
|
|
23
|
-
<th>Best score</th>
|
|
24
|
-
<th>Runs</th>
|
|
25
|
-
<th></th>
|
|
20
|
+
<th scope="col">Name</th>
|
|
21
|
+
<th scope="col">Version</th>
|
|
22
|
+
<th scope="col">Model</th>
|
|
23
|
+
<th scope="col">Best score</th>
|
|
24
|
+
<th scope="col">Runs</th>
|
|
25
|
+
<th scope="col"></th>
|
|
26
26
|
</tr>
|
|
27
27
|
</thead>
|
|
28
28
|
<tbody>
|
|
29
29
|
<% @prompts.each do |prompt| %>
|
|
30
30
|
<tr onclick="window.location='<%= prompt_path(prompt) %>'" style="cursor: pointer;">
|
|
31
31
|
<td>
|
|
32
|
-
|
|
32
|
+
<%= link_to prompt_path(prompt), class: "ck-record-name" do %><strong><%= prompt.name %></strong><% end %>
|
|
33
33
|
<% if prompt.description.present? %>
|
|
34
34
|
<p class="ck-prompts-table__desc"><%= truncate(prompt.description, length: 120) %></p>
|
|
35
35
|
<% end %>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<%= form_with(model: provider_credential, local: true) do |form| %>
|
|
2
2
|
<% if provider_credential.errors.any? %>
|
|
3
|
-
<div class="ck-flash ck-flash--alert">
|
|
3
|
+
<div class="ck-flash ck-flash--alert" role="alert">
|
|
4
4
|
<p class="ck-flash__title"><%= pluralize(provider_credential.errors.count, "problem") %> prevented this provider credential from being saved.</p>
|
|
5
5
|
<ul class="ck-error-list">
|
|
6
6
|
<% provider_credential.errors.full_messages.each do |message| %>
|
|
@@ -18,12 +18,14 @@
|
|
|
18
18
|
|
|
19
19
|
<div class="ck-field">
|
|
20
20
|
<%= form.label :api_key, "API key", class: "ck-label" %>
|
|
21
|
-
<%= form.text_area :api_key, rows: 3, class: "ck-input ck-input--area ck-input--code", placeholder: "Paste the provider API key" %>
|
|
21
|
+
<%= form.text_area :api_key, rows: 3, class: "ck-input ck-input--area ck-input--code", placeholder: "Paste the provider API key", **ck_field_aria(form, :api_key) %>
|
|
22
|
+
<%= ck_field_error(form, :api_key) %>
|
|
22
23
|
</div>
|
|
23
24
|
|
|
24
25
|
<div class="ck-field">
|
|
25
26
|
<%= form.label :api_endpoint, "API endpoint", class: "ck-label" %>
|
|
26
|
-
<%= form.text_field :api_endpoint, class: "ck-input", placeholder: "Only needed for Ollama or custom OpenAI-compatible endpoints" %>
|
|
27
|
+
<%= form.text_field :api_endpoint, class: "ck-input", placeholder: "Only needed for Ollama or custom OpenAI-compatible endpoints", **ck_field_aria(form, :api_endpoint) %>
|
|
28
|
+
<%= ck_field_error(form, :api_endpoint) %>
|
|
27
29
|
</div>
|
|
28
30
|
|
|
29
31
|
<div class="ck-actions">
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<%= form_with(model: run, local: true) do |form| %>
|
|
2
2
|
<% if run.errors.any? %>
|
|
3
|
-
<div class="ck-flash ck-flash--alert">
|
|
3
|
+
<div class="ck-flash ck-flash--alert" role="alert">
|
|
4
4
|
<p class="ck-flash__title"><%= pluralize(run.errors.count, "problem") %> prevented this run from being saved.</p>
|
|
5
5
|
<ul class="ck-error-list">
|
|
6
6
|
<% run.errors.full_messages.each do |message| %>
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
<div class="ck-card ck-form-card">
|
|
14
14
|
<div class="ck-field">
|
|
15
15
|
<%= form.label :name, "Name (auto-generated if blank)", class: "ck-label" %>
|
|
16
|
-
<%= form.text_field :name, class: "ck-input", placeholder: run.name.presence || "Auto-generated from prompt + version + timestamp" %>
|
|
16
|
+
<%= form.text_field :name, class: "ck-input", placeholder: run.name.presence || "Auto-generated from prompt + version + timestamp", **ck_field_aria(form, :name) %>
|
|
17
|
+
<%= ck_field_error(form, :name) %>
|
|
17
18
|
</div>
|
|
18
19
|
|
|
19
20
|
<div class="ck-field">
|
|
@@ -56,7 +57,8 @@
|
|
|
56
57
|
|
|
57
58
|
<div class="ck-field" id="output-column-field" hidden>
|
|
58
59
|
<%= form.label :output_column, "Output column", class: "ck-label" %>
|
|
59
|
-
<%= form.text_field :output_column, value: run.output_column.presence || "actual_output", class: "ck-input", id: "run_output_column", placeholder: "actual_output" %>
|
|
60
|
+
<%= form.text_field :output_column, value: run.output_column.presence || "actual_output", class: "ck-input", id: "run_output_column", placeholder: "actual_output", **ck_field_aria(form, :output_column) %>
|
|
61
|
+
<%= ck_field_error(form, :output_column) %>
|
|
60
62
|
<p class="ck-field-hint">Name of the dataset column whose value will be graded as the response. Defaults to <code>actual_output</code>.</p>
|
|
61
63
|
</div>
|
|
62
64
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<% clickable = response.succeeded? %>
|
|
2
2
|
<tr id="response_<%= response.id %>"<% if clickable %> onclick="window.location='<%= run_response_path(run, response, sort: params[:sort]) %>'" style="cursor: pointer;"<% end %>>
|
|
3
|
-
<td class="ck-response-cell__index"
|
|
3
|
+
<td class="ck-response-cell__index"><% if clickable %><%= link_to index, run_response_path(run, response, sort: params[:sort]), class: "ck-record-name" %><% else %><%= index %><% end %></td>
|
|
4
4
|
<td class="ck-response-cell__text">
|
|
5
5
|
<% if response.status == "failed" %>
|
|
6
6
|
<% err = response.error_payload %>
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<div class="ck-runs-table__identity">
|
|
4
4
|
<span class="ck-run-name">
|
|
5
5
|
<span class="<%= ck_run_dot(run) %>"></span>
|
|
6
|
-
|
|
6
|
+
<%= link_to ck_run_path(run), class: "ck-record-name" do %><strong><%= run.name %></strong><% end %>
|
|
7
7
|
</span>
|
|
8
8
|
<div class="ck-runs-table__config">
|
|
9
9
|
<% if run.prompt %>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
<div id="run_status_header">
|
|
1
|
+
<div id="run_status_header" aria-live="polite">
|
|
2
2
|
<% if run.status == "failed" %>
|
|
3
|
-
<div class="ck-flash ck-flash--alert">
|
|
3
|
+
<div class="ck-flash ck-flash--alert" role="alert">
|
|
4
4
|
<%= run.failure_summary.presence || run.error_message.presence || "Run failed." %>
|
|
5
5
|
</div>
|
|
6
6
|
<% end %>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<% snap = run.progress_snapshot %>
|
|
2
|
-
<div id="run_status_panel">
|
|
2
|
+
<div id="run_status_panel" aria-live="polite" aria-atomic="true">
|
|
3
3
|
<% if run.status.in?(%w[running completed]) && snap[:generated_total] > 0 %>
|
|
4
4
|
<% failed_count = snap[:generated_failed] + snap[:judged_failed] %>
|
|
5
5
|
<% has_judge = snap[:judged_total] > 0 || run.judge_configured? %>
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
<table class="ck-results-table ck-runs-table" style="margin-top: 0.5rem;">
|
|
4
4
|
<thead>
|
|
5
5
|
<tr>
|
|
6
|
-
<th>Run</th>
|
|
7
|
-
<th>Responses</th>
|
|
8
|
-
<th>Metrics</th>
|
|
9
|
-
<th>Avg score</th>
|
|
10
|
-
<th>When</th>
|
|
11
|
-
<th></th>
|
|
6
|
+
<th scope="col">Run</th>
|
|
7
|
+
<th scope="col">Responses</th>
|
|
8
|
+
<th scope="col">Metrics</th>
|
|
9
|
+
<th scope="col">Avg score</th>
|
|
10
|
+
<th scope="col">When</th>
|
|
11
|
+
<th scope="col"></th>
|
|
12
12
|
</tr>
|
|
13
13
|
</thead>
|
|
14
14
|
<tbody>
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
<% all_tags.each do |tag| %>
|
|
8
8
|
<% checked = selected_ids.include?(tag.id) %>
|
|
9
9
|
<label class="tag-mark" style="--mark-color: var(--tag-<%= tag.color %>);">
|
|
10
|
-
<%= check_box_tag "#{param_namespace}[tag_names][]", tag.name, checked, hidden:
|
|
11
|
-
|
|
10
|
+
<%= check_box_tag "#{param_namespace}[tag_names][]", tag.name, checked, class: "ck-visually-hidden", "aria-label": "Tag: #{tag.name}" %>
|
|
11
|
+
<span aria-hidden="true"><%= tag.name %></span>
|
|
12
12
|
</label>
|
|
13
13
|
<% end %>
|
|
14
14
|
<%= text_field_tag "#{param_namespace}[tag_names][]", "",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
<table class="ck-results-table ck-tags-table">
|
|
15
15
|
<thead>
|
|
16
16
|
<tr>
|
|
17
|
-
<th>Tag</th>
|
|
18
|
-
<th>Applied to</th>
|
|
19
|
-
<th></th>
|
|
17
|
+
<th scope="col">Tag</th>
|
|
18
|
+
<th scope="col">Applied to</th>
|
|
19
|
+
<th scope="col"></th>
|
|
20
20
|
</tr>
|
|
21
21
|
</thead>
|
|
22
22
|
<tbody>
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
<% by_type = @tagging_by_type.select { |(tid, _), _| tid == tag.id } %>
|
|
26
26
|
<% breakdown = by_type.map { |(_, type), n| pluralize(n, type.demodulize.titleize.downcase) }.join(" · ") %>
|
|
27
27
|
<tr onclick="window.location='<%= edit_tag_path(tag) %>'" style="cursor: pointer;">
|
|
28
|
-
<td
|
|
28
|
+
<td><%= link_to edit_tag_path(tag), class: "ck-record-name" do %><span class="tag-mark tag-mark--lg" style="--mark-color: var(--tag-<%= tag.color %>);"><%= tag.name %></span><% end %></td>
|
|
29
29
|
<td data-label="Applied to" class="ck-meta-copy">
|
|
30
30
|
<% if count.zero? %>
|
|
31
31
|
<span class="ck-tags-table__unused">Not used yet</span>
|
data/lib/completion_kit.rb
CHANGED
|
@@ -11,6 +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 :api_rate_limit, :web_rate_limit
|
|
14
|
+
attr_accessor :allow_loopback_endpoints
|
|
14
15
|
|
|
15
16
|
def initialize
|
|
16
17
|
@openai_api_key = ENV['OPENAI_API_KEY']
|
|
@@ -25,6 +26,8 @@ module CompletionKit
|
|
|
25
26
|
@api_rate_limit = 120
|
|
26
27
|
@web_rate_limit = 300
|
|
27
28
|
|
|
29
|
+
@allow_loopback_endpoints = true
|
|
30
|
+
|
|
28
31
|
@api_reference_authentication_partial = "completion_kit/api_reference/authentication"
|
|
29
32
|
end
|
|
30
33
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: completion-kit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.34
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Damien Bastin
|
|
@@ -308,6 +308,7 @@ files:
|
|
|
308
308
|
- app/services/completion_kit/open_ai_client.rb
|
|
309
309
|
- app/services/completion_kit/open_router_client.rb
|
|
310
310
|
- app/services/completion_kit/prompt_improvement_service.rb
|
|
311
|
+
- app/services/completion_kit/provider_endpoint.rb
|
|
311
312
|
- app/services/completion_kit/worker_health.rb
|
|
312
313
|
- app/validators/completion_kit/tenant_scoped_uniqueness_validator.rb
|
|
313
314
|
- app/views/completion_kit/api_reference/_authentication.html.erb
|