A step does one part of a run: it takes what the step before it returned
(the item, for the first step) and returns what the next step takes.
hr_chain() runs steps in order as one hr_arm(). gr_step() and
gr_step_retrieve() build the document steps (ingest, segment, retrieve,
read) with this function.
Usage
hr_step(
name,
fn = NULL,
params = list(),
schema = NULL,
input = NULL,
output = NULL,
version = "0.0.1",
build = NULL,
skill = NULL
)Arguments
- name
The step's name: one non-blank string.
hr_chain()uses it when the step is given without a name.- fn
A function of
(input, ctx), or of...;NULLwhenbuildis given.- params
A named list of the step's settings.
- schema
An
hr_schema()the settings are checked against, orNULL.- input, output
What the step takes and returns:
NULLor one of"document","doc","chunks","answer"and"state".- version
The step's version, one string. Change it when the step's behaviour changes.
- build
A function of the settings that returns the step's function, or
NULLwhenfnis given.- skill
A skill from
hr_skill(), orNULL. Insidehr_chain(), the step'sctx$call()andctx$call_json()send the skill's instructions and references as a system message before the step's own messages, andctx$skillholds the skill. The skill's hash is kept as the fixed settingskilland is part of the fingerprint, and the skill's version, when it has one, is the step's version.
Value
A function of (input, ctx) with class hr_step and the
attributes name, params (as given), resolved (the settings the
schema resolved, or params without a schema), extras (settings the
schema does not name), schema, input, output, version, build
skill and fingerprint, a hash of the step's code, the values it
reads, its settings and its version.
Details
Give exactly one of fn and build:
fnA function of
(input, ctx). Inside a chain,ctxis the contexthr_benchmark()gives the arm (seehr_arm()), with two more entries:step, the step's name in the chain, andstep_params, its resolved settings.ctx$paramsis still the arm'sparams.buildA function of one argument, the step's settings as a named list, that returns such a function. It is called here, so a setting it checks is checked when the step is built, not on the first run of a benchmark.
With a schema (an hr_schema()), the settings in params that the
schema names are checked and resolved by hr_validate(), and every
setting the schema has is filled from its default. A setting the schema
does not name is an error of class hr_unknown_param for a step given
fn. A step given build keeps it as a fixed extra setting, which
reaches build but is not part of the schema. Without a schema, params
is kept as given.
input and output say what the step takes and returns, so
hr_chain() can check the order of its steps: "document" (a file, URL
or text), "doc" (an ingested document), "chunks", "answer" or
"state" (anything else). NULL declares nothing.
See also
hr_chain(), gr_step(), hr_arm(), hr_set()
Other harness:
gr_arm(),
gr_condensation_check(),
gr_qa_reference(),
gr_reverse_text(),
gr_scorer_answer(),
hr_arm(),
hr_benchmark(),
hr_chain(),
hr_contrast(),
hr_drift_check(),
hr_effort_check(),
hr_effort_escalate(),
hr_effort_event(),
hr_effort_log(),
hr_mdd(),
hr_modules(),
hr_reference(),
hr_register(),
hr_report(),
hr_scorer(),
hr_set(),
hr_settings(),
hr_skill(),
hr_step_command(),
hr_sweep(),
hr_sweep_check()
Examples
shout <- hr_step("shout", function(input, ctx) {
paste0(toupper(input), strrep("!", ctx$step_params$marks))
}, params = list(marks = 2L),
schema = hr_schema(hr_param("marks", "integer", default = 1L, min = 0, max = 5)))
attr(shout, "resolved")
#> $marks
#> [1] 2
#>
shout("hello", list(step_params = attr(shout, "resolved")))
#> [1] "HELLO!!"