Reads the text a chat model returned for a drafting prompt
(tfl_ai_prompt()): the first fenced block (```yaml or
```json) that can be read and starts with the tflspec_ai
header; the whole text when no block does. YAML and JSON are both
read, whichever the prompt asked for.
Arguments
- text
The answer: a string, or lines of text.
- task
One of
tfl_ai_tasks(): the task the prompt asked for.
Value
A tfl_ai_answer: a list with task, header (the
tflspec_ai mapping), output_id, sheets (toc: a list holding the
toc data frame) or design (figure), note, assumptions
(character), problems (a data frame where, problem, severity
– error or warning), format (yaml or json) and raw (the
block's text). sheets / design is NULL when the answer could
not be read.
Details
Nothing is repaired: a block YAML cannot read (a {mean} not quoted, a
tab) is a problem naming the parser's line, as is a header of another
task or version, a column or key the task does not have, a mapping
where a value is wanted, or a block that is not closed (an answer cut
off). The problems go to tfl_ai_repair_prompt().
toc: the rows become a data frame withtfl_read_toc()'s fields as columns, every value text (numbers as text, a list joined with" | ", missingNA).table: each report ofoutputsis read astfl_read_output()reads a report file, intooutputs(a list oftfl_outputby id); a key a report file does not have is a problem. The assumptions (text, or mappings withoutput_id,where,item,assumption,question) are kept as rows too, inassumption_rows.figure: the design becomes atfl_fig_design()(the 0.0.12 shapetype/style/argsis read as onefigurelayer, and astatslist of before 0.0.24.9074 after thedatasteps, each with a warning); anotekey is kept as the answer'snote.
See also
tfl_ai_check() for the checks that need the study's context.
Examples
answer <- c(
"Here is the TOC:",
"```yaml",
"tflspec_ai: {task: toc, version: 1}",
"toc:",
"- {output_id: T-14-1-1, type: table, title: Demographics,",
" population: Safety Population}",
"- {output_id: F-14-2-1, type: figure, title: Time to Death}",
"assumptions:",
"- No footnotes are given in the SAP.",
"```")
a <- tfl_ai_parse(answer, "toc")
a$sheets$toc[c("output_id", "type", "title")]
#> output_id type title
#> 1 T-14-1-1 table Demographics
#> 2 F-14-2-1 figure Time to Death
a$assumptions
#> [1] "No footnotes are given in the SAP."