One constructor for what tfl_ai_prompt() tells the model about the
study and the report, and what tfl_ai_check() checks the answer
against, so a caller cannot pass the wrong shape and a prompt cannot
read a field that is not there. Each task reads its own fields; a
field another task reads is an error. Every field is optional but
output_id for a figure.
Usage
tfl_ai_context(
task,
study = NULL,
output_id = NULL,
titles = NULL,
population = NULL,
datasets = NULL,
design = NULL,
templates = NULL,
toc_fields = NULL,
reports = NULL,
language = NULL,
outputs = NULL,
shell = NULL,
study_dir = NULL,
examples = NULL
)Arguments
- task
One of
tfl_ai_tasks():"toc","figure"or"table".- study
The study: a named list or character vector with
study_idandtitle(either may be missing).- output_id
figure: the report's id (required).- titles
figure: the report's title lines, as the TOC has them.- population
figure: its analysis set: one label, or a named list or vector withid,labelandwhere(the condition, such asFASFL == "Y").- datasets
figure,tocandtable: the datasets and variables the answer may name. Atfl_ai_adam_summary()(itsvariables); or a data frame, one row a variable, withdatasetandvariableand optionallylabel,kind,levels(|between the values) anddataset_label–tfl_adam_metadata()'s result is one (itscodelistandsourceare not sent); or the ADaM datasets themselves, a named list of data frames, of which only the names, the labels (thelabelattribute) and the kinds are taken.- design
figure: the current design (atfl_fig_design()), when there is one: the prompt shows it and asks for it whole, changed.- templates
figure: the templates the answer may start from (names oftfl_fig_templates());NULLfor all.- toc_fields
toc: the columns the answer fills, amongoutput_id(always),type,title,population,footnote,program,file,note,section,datasets,label(tfl_read_toc()'s fields);NULLforoutput_id,type,title,population,footnote,section,datasets,label.- reports
toc: the reports already in the TOC: their ids, or a data frame withoutput_idand optionallytitle.- language
The language the model writes its assumptions in, such as
"Japanese";NULL: the language of the user's message. The prompt itself is English.- outputs
table: the reports to draft (5 to 10: one batch oftfl_ai_batches()), as the TOC numbers them.- shell
table: the TOC and shells as text – atfl_ai_read_shell()result (read again foroutputsalone when it holds the whole workbook) or a string;NULLwhen the workbook is attached to the chat instead.- study_dir
table: the study folder (tfl_ai_study_init()): itsspec/data.yml(the analysis sets the reports name) andspec/defaults.yml(what every report extends) go into the prompt.- examples
table: reviewed report files of this study (spec/outputs/<id>.ymlpaths) that the new reports follow – a family's first table, corrected by hand, for the rest of the family.
Details
Nothing here is sent anywhere: the context becomes text in the prompt,
which the user reads before copying it. Only names and labels are
carried, never the data's values: a dataset's levels (a variable's
values, such as its PARAMCDs) are there only when the caller gives them.
Examples
tfl_ai_context("toc", study = list(
study_id = "XYZ-ONC-01", title = "Drug X versus control in advanced solid tumours"
))
#> <tfl_ai_context: toc>
#> ## The study
#>
#> XYZ-ONC-01: Drug X versus control in advanced solid tumours
#>
#> ## The TOC's columns
#>
#> Fill these columns (the schema describes them): `output_id`, `type`, `title`, `population`, `footnote`, `section`, `datasets`, `label`.
#>
#> ## Reports already in the TOC
#>
#> None: the TOC is empty.
adam <- tfl_example_adam()
tfl_ai_context("figure", output_id = "F-14-2-1",
titles = "Kaplan-Meier Plot of Time to Death",
population = list(id = "FAS", label = "Full Analysis Set",
where = "FASFL == \"Y\""),
datasets = adam["ADTTE"])
#> <tfl_ai_context: figure>
#> ## The report
#>
#> - Report: F-14-2-1
#> - Titles: Kaplan-Meier Plot of Time to Death
#> - Analysis set: FAS, Full Analysis Set (`FASFL == "Y"`)
#>
#> ## The datasets
#>
#> Name only these datasets and variables.
#>
#> ### ADTTE
#>
#> | variable | label | kind |
#> |---|---|---|
#> | USUBJID | | character |
#> | TRT01P | | character |
#> | TRT01PN | | numeric |
#> | FASFL | Full Analysis Set Population Flag | character |
#> | PARAMCD | | character |
#> | PARAM | | character |
#> | AVAL | Analysis Value | numeric |
#> | CNSR | Censor | numeric |
#> | SEX | | character |
#> | AGEGR1 | | character |
#>
#> ## The current design
#>
#> There is none yet: start from the template that fits best.