extractCode {mergen}R Documentation

extract the code and text from the text returned by LLM agent

Description

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)
print(result$text)



[Package mergen version 0.2.1 Index]