Learn R Programming

sdcMicro (version 5.8.0)

KI_applyAnonymization: KI_applyAnonymization: Automatically apply anonymization strategy using LLM

Description

Applies an anonymization plan suggested by an LLM based on the structure and risk profile of an sdcMicro object.

Usage

KI_applyAnonymization(
  sdcObj,
  auto = TRUE,
  generateReport = TRUE,
  k = 3,
  verbose = TRUE,
  model = "gpt-4",
  api_key = Sys.getenv("OPENAI_API_KEY")
)

Value

Modified sdcMicroObj with anonymization applied (if auto = TRUE).

Arguments

sdcObj

An object of class sdcMicroObj.

auto

If TRUE, automatically applies the suggested strategy.

generateReport

If TRUE, generates internal and external reports.

k

Desired k-anonymity level.

verbose

If TRUE, prints LLM strategy.

model

OpenAI model (default: 'gpt-4').

api_key

Optional API key. Defaults to Sys.getenv("OPENAI_API_KEY").

Author

Matthias Templ

Examples

Run this code
if (FALSE) {
if (interactive() && nzchar(Sys.getenv("OPENAI_API_KEY"))) {
  library(sdcMicro)
  data(testdata)
  sdc <- KI_createSdcObj(
    dat = testdata,
    policy = "open",
    model = "gpt-4",
    api_key = Sys.getenv("OPENAI_API_KEY")
  )
  sdc <- KI_applyAnonymization(
    sdcObj = sdc,
    k = 3,
    auto = TRUE,
    generateReport = FALSE,
    verbose = TRUE,
    model = "gpt-4",
    api_key = Sys.getenv("OPENAI_API_KEY")
  )
  sdc <- KI_applyAnonymization(
    sdcObj = sdc,
    k = 3,
    auto = TRUE,
    generateReport = FALSE,
    verbose = TRUE,
    model = "gpt-4-turbo",
    api_key = Sys.getenv("OPENAI_API_KEY")
  ) 
}
}

Run the code above in your browser using DataLab