patientChat() generates synthetic patients in the OMOP-CDM using an LLM API.
Source: R/patientChat.R
patientChat.RdRequires 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.
Value
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.
Details
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.
Public fields
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
Methods
Method new()
Create a new chat to create JSON test sets for OMOP-CDM.
Usage
patientChat$new(
system_prompt = NULL,
model = "gpt-5.4",
jsonSchemaPath = NULL,
echo = c("none", "output", "all"),
codelist_data = NULL
)Arguments
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
Method prompt()
Prompt to request data from LLM API
Method save()
Saves the JSON test set to disk.
Method availableModels()
Retrieves available models from the LLM API.