extract the code and text from the text returned by LLM agent
Source:R/parseBotResponse.R
extractCode.Rd
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.
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"