Skip to contents

This function parses the agents answer and returns the text and code as single blocks. The results can be used for code execution and might be useful for displaying purposes later on.

Usage

extractCode(text, delimiter = "```")

Arguments

text

A character string containing the text with embedded code blocks.

delimiter

A character string representing the delimiter used to enclose the code blocks (default: "“`").

Value

A list with two elements: 'code' and 'text'. 'code' contains the concatenated code blocks, and 'text' contains the remaining text with code blocks removed.

Examples

text <- "\n\nThe following, normalize the table and do PCA.
\n\n```\ndata <- read.table(\"test.txt\", header = TRUE, sep = \"\\t\")\n```"
result <- extractCode(text)
print(result$code)
#> [1] "\ndata <- read.table(\"test.txt\", header = TRUE, sep = \"\\t\")\n"
print(result$text)
#> [1] "\n\nThe following, normalize the table and do PCA.\n\n\n\n"