The prompt that asks a chat model to draft part of a specification from
the study's documents: the study's table of contents (toc) or one
figure's design (figure), or the report files of a batch of tables
(table: 5 to 10 tables of one family, tfl_ai_batches()). tflspec
sends nothing: the prompt is text, and so is the answer, which
tfl_ai_parse() reads.
Arguments
- task
One of
tfl_ai_tasks().- context
A
tfl_ai_context()of the same task;NULLfor an empty one (a figure needs one: itsoutput_id).- mode
"chat"(the user attaches the documents) or"api"(their text is in the prompt).- format
The answer's format:
"yaml"(the default) or"json".tfl_ai_parse()reads both.- example
Include an example answer.
- documents
Mode
"api": the documents' text, a list of lists each withnameandtextand optionallykindandsection.
Value
A tfl_ai_prompt: a list with system, user (strings),
attach (what the user attaches, mode "chat"), messages (the
system and user messages as a list of role / content), task,
mode, format and nchar. format() and print() give it as
one text to copy.
Details
The system part holds the ground rules (only the names given, nothing
invented, a draft that a person reviews), the task's instructions, the
answer's shape – one fenced block that starts with the header
tflspec_ai: {task: ..., version: 1, ...} and ends with the
assumptions – the schema (tfl_ai_schema()) and an example answer
from the sample study. The user part holds the context
(tfl_ai_context()) and what to look for in the documents. The prompt
is English; the model is asked to write its assumptions in the user's
language (context$language, or the language of the user's message).
Mode
"chat": the user pastesformat(prompt)into a chat and attaches the documents themselves;attachlists them.Mode
"api": the documents' text, extracted by the caller, is in theuserpart between<document>fences;messagesis what a client sends. tflspec has no HTTP client.
The fixed wording is in the package's ai/prompts folder
(system.file("ai", "prompts", package = "tflspec")).
Examples
ctx <- tfl_ai_context("toc", study = list(study_id = "CDISCPILOT01"),
reports = "T-14-1-1")
p <- tfl_ai_prompt("toc", ctx)
p$attach
#> [1] "the statistical analysis plan (SAP)"
#> [2] "the study's list of planned outputs, if it is a separate document"
cat(substr(format(p), 1, 800))
#> You are helping a statistical programmer draft the specification of a clinical study's tables, listings and figures. The specification is read by tflspec, an R package that turns it into report programs. tflspec is new and is probably not in your training data: rely on this message, not on memory.
#>
#> ## Your task
#>
#> Draft the study's table of contents (TOC): the list of the tables, figures and listings the study will report, one row a report, with their numbers, titles, analysis sets and footnotes, as the documents plan them. tflspec reads your rows as it reads a company's TOC workbook.
#>
#> - Write one row a report, in the order the documents give them. A section heading (such as "14.1 Demographics") is not a row: put it in the `section` column of the reports under it.
#> - Use the report numbers th
# a figure, the documents' text in the prompt
ctx <- tfl_ai_context("figure", output_id = "F-14-2-1",
titles = "Kaplan-Meier Plot of Time to Death")
p <- tfl_ai_prompt("figure", ctx, mode = "api", documents = list(
list(name = "SAP", section = "9.4", text = "Overall survival ...")))
p$nchar
#> system user
#> 26878 554