Skip to contents

The function extracts and executes the code in the response. If required it can try to correct errors in the code via different strategies.

Usage

runCodeInResponse(
  response,
  prompt = NULL,
  agent = NULL,
  context = NULL,
  correction = c("none", "selfcorrect", "sampleMore", "sampleThenCorrect",
    "correctThenSample"),
  attempts = 3,
  output.file = NULL,
  ...
)

Arguments

response

response to be parsed for code and executed

prompt

prompt for the response, if correction="none" it is not needed

agent

AI agent, if correction="none" it is not needed

context

context for the prompt, if correction="none" it is not needed

correction

"none" no code correction is needed. "selfcorrect" feedback the errors to LLM and ask for fix. "sampleMore" sample responses for the #prompt until an executable code is returned or number of attempts reached. "correctThenSample" first try self-correct "attempt" number of times. If no executable code is returned. It will sample new responses "attempt" number of times or until executable code

attempts

Numeric value denoting how many times the code should be sent back for fixing.

output.file

Optional output file created holding parsed code

...

arguments to sendPrompt()

Value

A list containing the following elements:

init.response

A character vector representing the initial prompt response.

init.blocks

A list of initial blocks.

final.blocks

A list of final blocks.

code.works

A boolean value indicating whether the code works.

exec.result

A character string representing the execution results.

tried.attempts

An integer representing the number of attempts.

Examples

if (FALSE) { # \dontrun{

resp.list <- runCodeInResponse(agent,prompt,context=rbionfoExp,correction="sampleMore",attempt=2)
} # }