| patientChat | R Documentation |
patientChat() generates synthetic patients in the OMOP-CDM using an LLM API.Requires an OPEN_AI_KEY in ~/.Renviron. After that just sent a prompt and save() the results. The JSON file can be used as an OMOP-CDM patient test set.
Accepts a prompt as input. Produces a test set using a structured JSON schema. Utilizes tools such as CodelistGenerator or Hecate to look up concept IDs. Accepts subsequent prompts to modify existing test sets that the LLM uses as context.
This class allows testing patient sets created by the LLM, prompt engineering, integration of search tools and functionality, and creating a set of patients to test analytical packages.
A JSON response that includes: the natural language answer from the LLM and a JSON with test set patients in accordance to the provided schema.
chatAn ellmer chat instance
json_schema_pathJSON schema to output structured results
responseOuput from the LLM
codelistA codelist with details to search for concepts ids
patientChat$new()Create a new chat to create JSON test sets for OMOP-CDM.
patientChat$new(
system_prompt = NULL,
model = "gpt-5.4",
jsonSchemaPath = NULL,
echo = c("none", "output", "all"),
codelist_data = NULL
)
system_promptInitial system prompt to impose behaviour to the LLM
modelSuch as "gpt-5.3". For a complete list, call patientChat$availableModels()
jsonSchemaPathThe JSON schema to structure output from LLM
echoHow the output will be displayed in the console
codelist_dataA codelist with details to search for concepts ids
A new patientChat object.
patientChat$prompt()Prompt to request data from LLM API
patientChat$prompt(prompt)
promptA query in character.
patientChat$json_response()Output in JSON format
patientChat$json_response()
patientChat$output()Returns the chat object
patientChat$output()
patientChat$retrieveCodelist()Retrieves and filters data from codelist_data
patientChat$retrieveCodelist(concept_label = "Stage 1", domain = "Measurement")
concept_labelFilters the concept_name in the codelist with details
domainFilters the domain in the codelist with details.
patientChat$save()Saves the JSON test set to disk.
patientChat$save(name = "patient-chat-test", path = NULL)
nameName of the file
pathTo save the file.
If NULL, the package first tries testthat::test_path("testCases"),
then checks options(PatientGenerator.testSetDir = "..."), and finally
falls back to the package user data directory.
patientChat$availableModels()Retrieves available models from the LLM API.
patientChat$availableModels()
patientChat$clone()The objects of this class are cloneable with this method.
patientChat$clone(deep = FALSE)
deepWhether to make a deep clone.
## Not run:
generator <- patientChat$new()
generator$prompt("Give me 5 patients")
generator$save("my_test")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.