inquirex-llm 0.12.2 → 0.12.3
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/CHANGELOG.md +4 -0
- data/lib/inquirex/llm/evals/adapter.rb +8 -8
- data/lib/inquirex/llm/evals/model_adapter.rb +3 -3
- data/lib/inquirex/llm/evals/scorer.rb +14 -14
- data/lib/inquirex/llm/version.rb +1 -1
- metadata +67 -68
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ddbe155ad9a37e63b979e9c7d91875a0e26c5e6ef5beba0eca687c2291067009
|
|
4
|
+
data.tar.gz: cf4dbe5247865f2698c1650e90719e875c8006b28e411a79c03fb698160d497d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ff0fd8da9de94294c9329b53023d56e55583bf66851b2023e48066e6e4cebb33137cc2b5ae427cc0fb7b0017cf9444ccadeb05662b4a1bcf4161fadf62e3e3c7
|
|
7
|
+
data.tar.gz: 9e378290bda04d747bd08e4720c86ff3b47d51db63c918d8e4168c5a226c742bf3aa0bc00c4d9da1110462d300b3ee02fa9f8115ac22fdf0eac33df652000950
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.12.3
|
|
4
|
+
|
|
5
|
+
- Use the module-scoped constants of llm-evals 0.5.0 (`LLM::Evals::Actions::Adapter`, `Scoring::Scorer` and so on). The suite needs llm-evals `~> 0.5.0`.
|
|
6
|
+
|
|
3
7
|
## 0.12.2 (unreleased)
|
|
4
8
|
|
|
5
9
|
- **The eval suite now runs on llm-evals.** `inquirex/llm/evals` requires `llm/evals` and subclasses `::LLM::Evals`, because `agent-evals` was renamed and is no longer on RubyGems. The config file is `evals/.llm-evals.config.yml` and the executable is `evals`. Inside `Inquirex::LLM`, a bare `LLM` means this gem, so the leading `::` is required.
|
|
@@ -9,9 +9,9 @@ module Inquirex
|
|
|
9
9
|
# canonicalized by the gem. It never scores; {Scorer} does that.
|
|
10
10
|
#
|
|
11
11
|
# A reply that is not a JSON object is the model's failure and comes
|
|
12
|
-
# back as a {LLM::Evals::Reply} with `error` set. A transport failure
|
|
12
|
+
# back as a {LLM::Evals::Results::Reply} with `error` set. A transport failure
|
|
13
13
|
# raises, and the run counts it as an error rather than a wrong answer.
|
|
14
|
-
class Adapter < ::LLM::Evals::Adapter
|
|
14
|
+
class Adapter < ::LLM::Evals::Actions::Adapter
|
|
15
15
|
# Recorded with every experiment: which prompt the models saw.
|
|
16
16
|
PROMPT = "Inquirex::LLM::OpenAIAdapter"
|
|
17
17
|
|
|
@@ -36,14 +36,14 @@ module Inquirex
|
|
|
36
36
|
set.schema
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
# @param kase [LLM::Evals::Case]
|
|
40
|
-
# @param model [LLM::Evals::Model]
|
|
41
|
-
# @return [LLM::Evals::Reply]
|
|
39
|
+
# @param kase [LLM::Evals::Datasets::Case]
|
|
40
|
+
# @param model [LLM::Evals::Models::Model]
|
|
41
|
+
# @return [LLM::Evals::Results::Reply]
|
|
42
42
|
def call(kase, model:)
|
|
43
43
|
set = dataset(kase.dataset)
|
|
44
44
|
adapter = ModelAdapter.new(model)
|
|
45
45
|
extraction = adapter.call(set.node, { set.source_step => kase.input })
|
|
46
|
-
::LLM::Evals::Reply.new(
|
|
46
|
+
::LLM::Evals::Results::Reply.new(
|
|
47
47
|
output: extraction.output.transform_keys(&:to_s),
|
|
48
48
|
raw: extraction.raw.transform_keys(&:to_s),
|
|
49
49
|
usage: adapter.completion.usage,
|
|
@@ -52,13 +52,13 @@ module Inquirex
|
|
|
52
52
|
rescue Errors::AdapterError => e
|
|
53
53
|
raise if adapter.completion.nil? # nothing was asked: not the model's doing
|
|
54
54
|
|
|
55
|
-
::LLM::Evals::Reply.new(error: e.message.lines.first.strip,
|
|
55
|
+
::LLM::Evals::Results::Reply.new(error: e.message.lines.first.strip,
|
|
56
56
|
raw: adapter.completion.text,
|
|
57
57
|
usage: adapter.completion.usage,
|
|
58
58
|
metadata: { prompt: adapter.prompt })
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
-
# @param kase [LLM::Evals::Case]
|
|
61
|
+
# @param kase [LLM::Evals::Datasets::Case]
|
|
62
62
|
# @return [Hash] the schema the scorer grades against
|
|
63
63
|
def context(kase) = { schema: dataset(kase.dataset).schema }
|
|
64
64
|
|
|
@@ -4,7 +4,7 @@ module Inquirex
|
|
|
4
4
|
module LLM
|
|
5
5
|
module Evals
|
|
6
6
|
# The gem's {OpenAIAdapter} with its transport swapped for an
|
|
7
|
-
# llm-evals {LLM::Evals::Model}. Everything the model sees and
|
|
7
|
+
# llm-evals {LLM::Evals::Models::Model}. Everything the model sees and
|
|
8
8
|
# everything done to its answer is production's: the system prompt,
|
|
9
9
|
# the schema contract, the user prompt built from the step's `from`
|
|
10
10
|
# answers, fence stripping, JSON parsing and the canonicalization of
|
|
@@ -18,13 +18,13 @@ module Inquirex
|
|
|
18
18
|
# OpenAIAdapter insists on a key; the eval model holds the real one.
|
|
19
19
|
NO_KEY = "(unused: the eval model carries its own key)"
|
|
20
20
|
|
|
21
|
-
# @return [LLM::Evals::
|
|
21
|
+
# @return [LLM::Evals::Results::ProviderResponse, nil] what the model answered, once asked
|
|
22
22
|
attr_reader :completion
|
|
23
23
|
|
|
24
24
|
# @return [Hash{Symbol => String}, nil] the system and user prompts, once sent
|
|
25
25
|
attr_reader :prompt
|
|
26
26
|
|
|
27
|
-
# @param model [LLM::Evals::Model]
|
|
27
|
+
# @param model [LLM::Evals::Models::Model]
|
|
28
28
|
def initialize(model)
|
|
29
29
|
super(api_key: NO_KEY, model: model.id)
|
|
30
30
|
@model = model
|
|
@@ -13,36 +13,36 @@ module Inquirex
|
|
|
13
13
|
# share the model answered anyway; it is nil when the truth has no
|
|
14
14
|
# null, so a dataset of complete texts neither earns nor loses by it.
|
|
15
15
|
# `invalid_rate` is the share of fields the schema would reject.
|
|
16
|
-
class Scorer < ::LLM::Evals::Scorer
|
|
16
|
+
class Scorer < ::LLM::Evals::Scoring::Scorer
|
|
17
17
|
METRICS = [
|
|
18
|
-
::LLM::Evals::Metric.new(name: "score",
|
|
18
|
+
::LLM::Evals::Scoring::Metric.new(name: "score",
|
|
19
19
|
primary: true,
|
|
20
20
|
description: "Mean field value: correct 1.0, missed 0.2, hallucinated 0.15, incorrect 0.1, invalid 0; " \
|
|
21
21
|
"a multi_enum is the mean of its elements."),
|
|
22
|
-
::LLM::Evals::Metric.new(name: "exact", description: "1 when every field is correct."),
|
|
23
|
-
::LLM::Evals::Metric.new(name: "hallucinated_rate",
|
|
22
|
+
::LLM::Evals::Scoring::Metric.new(name: "exact", description: "1 when every field is correct."),
|
|
23
|
+
::LLM::Evals::Scoring::Metric.new(name: "hallucinated_rate",
|
|
24
24
|
description: "Of the fields the text never answers (truth null), the share the model answered anyway; " \
|
|
25
25
|
"nothing recorded when the truth has no null."),
|
|
26
|
-
::LLM::Evals::Metric.new(name: "invalid_rate",
|
|
26
|
+
::LLM::Evals::Scoring::Metric.new(name: "invalid_rate",
|
|
27
27
|
description: "Share of fields whose value the schema does not allow: off the list, wrong type.")
|
|
28
28
|
].freeze
|
|
29
29
|
|
|
30
|
-
# How the gem's field types read to {LLM::Evals::SchemaValidator}.
|
|
30
|
+
# How the gem's field types read to {LLM::Evals::Scoring::SchemaValidator}.
|
|
31
31
|
VALIDATOR_TYPES = { enum: :enum, multi_enum: :multi_enum, integer: :integer, boolean: :boolean,
|
|
32
32
|
decimal: :number, currency: :number }.freeze
|
|
33
33
|
|
|
34
|
-
# @return [Array<LLM::Evals::Metric>]
|
|
34
|
+
# @return [Array<LLM::Evals::Scoring::Metric>]
|
|
35
35
|
def metrics = METRICS
|
|
36
36
|
|
|
37
|
-
# @param kase [LLM::Evals::Case]
|
|
38
|
-
# @param reply [LLM::Evals::Reply]
|
|
37
|
+
# @param kase [LLM::Evals::Datasets::Case]
|
|
38
|
+
# @param reply [LLM::Evals::Results::Reply]
|
|
39
39
|
# @param context [Hash] `:schema`, the {Inquirex::LLM::Schema} the dataset extracts
|
|
40
|
-
# @return [LLM::Evals::Score]
|
|
40
|
+
# @return [LLM::Evals::Results::Score]
|
|
41
41
|
def call(kase, reply, context:)
|
|
42
42
|
schema = context.fetch(:schema)
|
|
43
43
|
fields = field_scores(schema, kase.expected, reply.raw)
|
|
44
44
|
open = fields.select { kase.expected[it.field].nil? }
|
|
45
|
-
::LLM::Evals::Score.new(
|
|
45
|
+
::LLM::Evals::Results::Score.new(
|
|
46
46
|
value: mean(fields.map(&:value)),
|
|
47
47
|
metrics: { "score" => mean(fields.map(&:value)),
|
|
48
48
|
"exact" => fields.all?(&:correct?) ? 1.0 : 0.0,
|
|
@@ -74,7 +74,7 @@ module Inquirex
|
|
|
74
74
|
# Checks expected.json against the schema, every field nullable: a
|
|
75
75
|
# null is how the truth says the text never answers it.
|
|
76
76
|
#
|
|
77
|
-
# @param kase [LLM::Evals::Case]
|
|
77
|
+
# @param kase [LLM::Evals::Datasets::Case]
|
|
78
78
|
# @param context [Hash]
|
|
79
79
|
# @return [Array<String>] unknown keys, missing keys, off-list values, wrong types
|
|
80
80
|
def verify(kase, context:)
|
|
@@ -82,10 +82,10 @@ module Inquirex
|
|
|
82
82
|
fields = schema.field_specs.to_h do |name, spec|
|
|
83
83
|
[name.to_s, { type: VALIDATOR_TYPES.fetch(spec.type, :string), enum: spec.values, nullable: true }]
|
|
84
84
|
end
|
|
85
|
-
::LLM::Evals::SchemaValidator.new(fields).problems(kase.expected)
|
|
85
|
+
::LLM::Evals::Scoring::SchemaValidator.new(fields).problems(kase.expected)
|
|
86
86
|
end
|
|
87
87
|
|
|
88
|
-
# @param kase [LLM::Evals::Case]
|
|
88
|
+
# @param kase [LLM::Evals::Datasets::Case]
|
|
89
89
|
# @return [String] "answered 7/10"
|
|
90
90
|
def summary(kase)
|
|
91
91
|
return nil unless kase.expected.is_a?(Hash)
|
data/lib/inquirex/llm/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,94 +1,93 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: inquirex-llm
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.12.
|
|
4
|
+
version: 0.12.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
|
|
7
|
+
- Konstantin Gredeskoul
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: inquirex
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 0.12.1
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 0.12.1
|
|
26
|
+
description: 'Extends the Inquirex DSL with an LLM-powered `extract` verb (alias:
|
|
27
|
+
`clarify`) that runs server-side to turn free-text answers into structured data.
|
|
28
|
+
Pluggable adapter interface keeps the gem LLM-agnostic; a NullAdapter ships for
|
|
29
|
+
testing.'
|
|
29
30
|
email:
|
|
30
|
-
|
|
31
|
+
- kigster@gmail.com
|
|
31
32
|
executables:
|
|
32
|
-
|
|
33
|
+
- inquirex-llm
|
|
33
34
|
extensions: []
|
|
34
35
|
extra_rdoc_files: []
|
|
35
36
|
files:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
homepage:
|
|
37
|
+
- CHANGELOG.md
|
|
38
|
+
- LICENSE.txt
|
|
39
|
+
- README.md
|
|
40
|
+
- exe/inquirex-llm
|
|
41
|
+
- lib/inquirex-llm.rb
|
|
42
|
+
- lib/inquirex/llm.rb
|
|
43
|
+
- lib/inquirex/llm/adapter.rb
|
|
44
|
+
- lib/inquirex/llm/anthropic_adapter.rb
|
|
45
|
+
- lib/inquirex/llm/configuration.rb
|
|
46
|
+
- lib/inquirex/llm/dsl/flow_builder.rb
|
|
47
|
+
- lib/inquirex/llm/dsl/llm_step_builder.rb
|
|
48
|
+
- lib/inquirex/llm/errors.rb
|
|
49
|
+
- lib/inquirex/llm/evals.rb
|
|
50
|
+
- lib/inquirex/llm/evals/adapter.rb
|
|
51
|
+
- lib/inquirex/llm/evals/dataset.rb
|
|
52
|
+
- lib/inquirex/llm/evals/field_score.rb
|
|
53
|
+
- lib/inquirex/llm/evals/model_adapter.rb
|
|
54
|
+
- lib/inquirex/llm/evals/scorer.rb
|
|
55
|
+
- lib/inquirex/llm/extraction.rb
|
|
56
|
+
- lib/inquirex/llm/jev_adapter.rb
|
|
57
|
+
- lib/inquirex/llm/models.rb
|
|
58
|
+
- lib/inquirex/llm/node.rb
|
|
59
|
+
- lib/inquirex/llm/null_adapter.rb
|
|
60
|
+
- lib/inquirex/llm/numbers.rb
|
|
61
|
+
- lib/inquirex/llm/open_router_adapter.rb
|
|
62
|
+
- lib/inquirex/llm/openai_adapter.rb
|
|
63
|
+
- lib/inquirex/llm/prompts.rb
|
|
64
|
+
- lib/inquirex/llm/safe_source.rb
|
|
65
|
+
- lib/inquirex/llm/schema.rb
|
|
66
|
+
- lib/inquirex/llm/version.rb
|
|
67
|
+
homepage: https://github.com/inquirex/inquirex-llm
|
|
67
68
|
licenses:
|
|
68
|
-
|
|
69
|
+
- MIT
|
|
69
70
|
metadata:
|
|
70
|
-
allowed_push_host:
|
|
71
|
-
homepage_uri:
|
|
72
|
-
source_code_uri:
|
|
73
|
-
changelog_uri:
|
|
74
|
-
rubygems_mfa_required:
|
|
71
|
+
allowed_push_host: https://rubygems.org
|
|
72
|
+
homepage_uri: https://github.com/inquirex/inquirex-llm
|
|
73
|
+
source_code_uri: https://github.com/inquirex/inquirex-llm
|
|
74
|
+
changelog_uri: https://github.com/inquirex/inquirex-llm/blob/main/CHANGELOG.md
|
|
75
|
+
rubygems_mfa_required: 'true'
|
|
75
76
|
rdoc_options: []
|
|
76
77
|
require_paths:
|
|
77
|
-
|
|
78
|
+
- lib
|
|
78
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
80
|
requirements:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
version: 4.0.0
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: 4.0.0
|
|
84
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
85
|
requirements:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
version: "0"
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
90
89
|
requirements: []
|
|
91
|
-
rubygems_version: 4.
|
|
90
|
+
rubygems_version: 4.0.23
|
|
92
91
|
specification_version: 4
|
|
93
92
|
summary: LLM integration verbs for the Inquirex questionnaire engine
|
|
94
93
|
test_files: []
|