diff --git a/pkgdown.yml b/pkgdown.yml index 2809479..f27c5d2 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -3,5 +3,5 @@ pkgdown: 2.0.7 pkgdown_sha: ~ articles: mergen: mergen.html -last_built: 2023-12-21T18:18Z +last_built: 2023-12-21T21:58Z diff --git a/reference/check_install.html b/reference/check_install.html index 4279411..254751f 100644 --- a/reference/check_install.html +++ b/reference/check_install.html @@ -70,7 +70,7 @@

ArgumentsValue

-

No value returned. Called for installation of package.

+

TRUE if the package is already installed or can be installed. FALSE otherwise

diff --git a/reference/extractInstallPkg.html b/reference/extractInstallPkg.html index b94f677..8e3716d 100644 --- a/reference/extractInstallPkg.html +++ b/reference/extractInstallPkg.html @@ -73,7 +73,8 @@

ArgumentsValue

-

No value returned. Called for installation of package.

+

final status of the packages as a logical vector, TRUE if packages is already installed +or could be installed. FALSE if the package can't be install.

@@ -82,6 +83,10 @@

Examples# Check code for packages that need installing code <- "library(devtools)\n x<-5" extractInstallPkg(code) +#> Loading required package: devtools +#> Loading required package: usethis +#> devtools +#> TRUE # }

diff --git a/search.json b/search.json index 2cdd02a..66fb0b0 100644 --- a/search.json +++ b/search.json @@ -1 +1 @@ -[{"path":"/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2023 mergen authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"/articles/mergen.html","id":"setting-up-an-ai-agent","dir":"Articles","previous_headings":"","what":"Setting up an AI-agent","title":"Introduction to mergen","text":"able interact AI agent use agent subsequent tasks, mergen contains setupAgent function setting framework agent.Mergen allows set agent openai API platform well replicate API platform.","code":""},{"path":"/articles/mergen.html","id":"setting-up-an-openai-agent","dir":"Articles","previous_headings":"Setting up an AI-agent","what":"Setting up an openai agent","title":"Introduction to mergen","text":"setting agent openai API platform, can make use setupAgent function setting name=\"openai\" argument. Let’s look setting agent works: setupAgent function returns list containing agent information can used subsequent functions. mportant note ai_api_key OpenAI API key, provided string.","code":"myAgent <- setupAgent(name=\"openai\",type=\"chat\",model=\"gpt-4\",ai_api_key = \"your_key\") myAgent #> $name #> [1] \"userAgent\" #> #> $type #> [1] \"chat\" #> #> $API #> [1] \"openai\" #> #> $url #> [1] \"https://api.openai.com/v1/chat/completions\" #> #> $model #> [1] \"gpt-4\" #> #> $headers #> Authorization Content-Type #> \"Bearer your_key\" \"application/json\" #> #> $ai_api_key #> [1] \"your_key\""},{"path":"/articles/mergen.html","id":"setting-up-an-agent-for-replicate","dir":"Articles","previous_headings":"Setting up an AI-agent","what":"Setting up an agent for replicate","title":"Introduction to mergen","text":"setupAgent also contains functionality setting agent replicate AIs. Let’s look works:","code":"myAgent <- setupAgent(name=\"replicate\",type=NULL,model=\"llama-2-70b-chat\",ai_api_key=\"my_key\") myAgent #> $name #> [1] \"userAgent\" #> #> $type #> NULL #> #> $API #> [1] \"replicate\" #> #> $url #> [1] \"https://api.replicate.com/v1/predictions\" #> #> $model #> [1] \"llama-2-70b-chat\" #> #> $headers #> Authorization Content-Type #> \"Token my_key\" \"application/json\" #> #> $ai_api_key #> [1] \"my_key\""},{"path":"/articles/mergen.html","id":"sending-a-prompt","dir":"Articles","previous_headings":"","what":"Sending a prompt","title":"Introduction to mergen","text":"set agent, time ask questions AI model choice! , can make use sendPrompt function, selfcorrect function. choice one use depends whether want possible errors answered code corrected sending another request model .","code":""},{"path":"/articles/mergen.html","id":"using-the-sendprompt-function","dir":"Articles","previous_headings":"Sending a prompt","what":"Using the sendPrompt function","title":"Introduction to mergen","text":"Sending prompt sendPrompt function easy. function takes arguments agent, prompt, return.type context. default context set rbionfoExp. tells model choice act bioinformatics expert, return code R code triple backticks. prompt must given string, can contain question additional information want send. return value string containing models answer.","code":"answer <- sendPrompt(myAgent, \"how do I perform PCA on data in a file called test.txt?\",return.type = \"text\") answer #> [1] \"\\n\\nThe following R code will read the file called \\\"test.txt\\\", normalize the table and do PCA. First, the code will read the file into an R data frame: \\n\\n```\\ndata <- read.table(\\\"test.txt\\\", header = TRUE, sep = \\\"\\\\t\\\")\\n```\\n\\nNext, the data will be normalized to the range of 0 to 1:\\n\\n```\\nnormalized.data <- scale(data, center = TRUE, scale = TRUE)\\n```\\n\\nFinally, the normalized data will be used to do a Principal Component Analysis (PCA):\\n\\n```\\npca <- princomp(normalized.data)\\n```\""},{"path":"/articles/mergen.html","id":"using-the-selfcorrect-function","dir":"Articles","previous_headings":"Sending a prompt","what":"Using the selfcorrect function","title":"Introduction to mergen","text":"Sending prompt selfcorrect function, allow possible generated code optimized performance accuracy. code returned model excecutable, selfcorrect function send prompt back agent together list errors warnings, code can optimized. amount rounds possible selfcorrect can set user using attempts = n argument. return value list containing initial answer agent final answer n rounds selfcorrection.","code":"answer <- selfcorrect(myAgent, prompt=\"How do I perform PCA?\",attempts=3) print(answer) #> $init.response #> [1] \"\\n\\nThe following R code will read the file called \\\"test.txt\\\", normalize the table and do PCA. First, the code will read the file into an R data frame: \\n\\n```R\\ndata <- read.table(\\\"test.txt\\\", header = TRUE, sep = \\\"\\\\t\\\")\\n```\\n\\nNext, the data will be normalized to the range of 0 to 1:\\n\\n```{r}\\nnormalized.data <- scale(data, center = TRUE, scale = TRUE)\\n```\\n\\nFinally, the normalized data will be used to do a Principal Component Analysis (PCA):\\n\\n```{R}\\npca <- princomp(normalized.data)\\n```\" #> #> $init.blocks #> $init.blocks$code #> [1] \"\\ndata <- read.table(\\\"test.txt\\\", header = TRUE, sep = \\\"\\\\t\\\")\\n\\n\\nnormalized.data <- scale(data, center = TRUE, scale = TRUE)\\n\\n\\npca <- princomp(normalized.data)\\n\" #> #> $init.blocks$text #> [1] \"\\n\\nThe following R code will read the file called \\\"test.txt\\\", normalize the table and do PCA. First, the code will read the file into an R data frame: \\n\\n\\n\\n\\nNext, the data will be normalized to the range of 0 to 1:\\n\\n\\n\\n\\nFinally, the normalized data will be used to do a Principal Component Analysis (PCA):\\n\\n\\n\" #> #> #> $final.response #> [1] \"\\n\\nThe third response.The following R code will read the file called \\\"test.txt\\\", normalize the table and do PCA. First, the code will read the file into an R data frame: \\n\\n```{r}\\nplot(1:10)```\\n\\nNext, the data will be normalized to the range of 0 to 1:\\n\\n\" #> #> $final.blocks #> $final.blocks$code #> [1] \"\\nplot(1:10)\" #> #> $final.blocks$text #> [1] \"\\n\\nThe third response.The following R code will read the file called \\\"test.txt\\\", normalize the table and do PCA. First, the code will read the file into an R data frame: \\n\\n\\n\\n\\nNext, the data will be normalized to the range of 0 to 1:\\n\\n\" #> #> #> $code.works #> [1] TRUE #> #> $exec.result #> [1] \"path/to/html/file\" #> #> $tried.attempts #> [1] 3"},{"path":[]},{"path":"/articles/mergen.html","id":"extracting-code-blocks","dir":"Articles","previous_headings":"Running the code","what":"Extracting code blocks","title":"Introduction to mergen","text":"sent prompt recieved answer, mergen features function extractCode allows user extract code blocks given text. using , however, code blocks need cleaned , every agent return answer slightly different way. can done help clean_code_blocks function. example clean_code_blocks answer returned agent : can see , clean_code_blocks ensures code stripped extra symbols {r}, R, r {R}. ensures function extractCode can extract code blocks properly. extractCode function takes input string, also allows user set delimiter used enclose code blocks (default three backtics). Now lets look extractCode function returns: shown , extractCode returns list containing actual code associated text. code block can tested execution using executeCode function.","code":"code_cleaned <- clean_code_blocks(answer$final.response) cat(code_cleaned) #> #> #> The third response.The following R code will read the file called \"test.txt\", normalize the table and do PCA. First, the code will read the file into an R data frame: #> #> ``` #> plot(1:10)``` #> #> Next, the data will be normalized to the range of 0 to 1: final_code <- extractCode(code_cleaned,delimiter = \"```\") print (final_code) #> $code #> [1] \"\\nplot(1:10)\" #> #> $text #> [1] \"\\n\\nThe third response.The following R code will read the file called \\\"test.txt\\\", normalize the table and do PCA. First, the code will read the file into an R data frame: \\n\\n\\n\\n\\nNext, the data will be normalized to the range of 0 to 1:\\n\\n\""},{"path":"/articles/mergen.html","id":"running-the-code-1","dir":"Articles","previous_headings":"Running the code","what":"Running the code","title":"Introduction to mergen","text":"mergen features functions make easy user run code returned AI agent. code blocks cleaned extracted, code blocks can executed using executeCode function. , however, advised run extractInstallPkg function. function extracts package names installs missing packages needed code run. Finally, executeCode function can used. Lets see executeCode function : shown , code runs ! important note executeCode function change global environment. variables might created executing code deleted function completes.","code":"executeCode(final_code$code) #> NULL"},{"path":"/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Altuna Akalin. Author, maintainer. Jacqueline Anne Jansen. Author.","code":""},{"path":"/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Akalin , Jansen J (2023). mergen: AI-Driven Code Generation, Explanation Execution Data Analysis. R package version 0.1.1, https://bioinformatics.mdc-berlin.de/mergen/, https://github.com/BIMSBbioinfo/mergen.","code":"@Manual{, title = {mergen: AI-Driven Code Generation, Explanation and Execution for Data Analysis}, author = {Altuna Akalin and Jacqueline Anne Jansen}, year = {2023}, note = {R package version 0.1.1, https://bioinformatics.mdc-berlin.de/mergen/}, url = {https://github.com/BIMSBbioinfo/mergen}, }"},{"path":[]},{"path":"/index.html","id":"overview","dir":"","previous_headings":"","what":"Overview","title":"AI-Driven Code Generation, Explanation and Execution for Data Analysis","text":"mergen employs artificial intelligence convert data analysis questions executable code, explanations, algorithms. self-correction feature ensures generated code optimized performance accuracy. mergen features user-friendly chat interface, enabling users interact AI agent extract valuable insights data effortlessly.","code":""},{"path":"/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"AI-Driven Code Generation, Explanation and Execution for Data Analysis","text":"easiest way install mergen via install.packages","code":"install.packages(\"mergen\")"},{"path":"/index.html","id":"development-version","dir":"","previous_headings":"Installation","what":"Development version","title":"AI-Driven Code Generation, Explanation and Execution for Data Analysis","text":"get bug fix use feature development version, can install development version mergen GitHub.","code":"# install.packages(\"pak\") pak::pak(\"BIMSBbioinfo/mergen\")"},{"path":"/index.html","id":"prerequisites","dir":"","previous_headings":"","what":"Prerequisites","title":"AI-Driven Code Generation, Explanation and Execution for Data Analysis","text":"Make AI platform account. Choices openai.com, neets.ai (time writing free limits), replicate.com , perplexity.ai etc. addition, can locally run LLM server mode can interact via API. One example GPT4all. solutions tested work mergen. Create OpenAI API key use package Create replicate API key Set API key R","code":""},{"path":"/index.html","id":"configuring-your-ai-api-key","dir":"","previous_headings":"Prerequisites","what":"Configuring your AI API key","title":"AI-Driven Code Generation, Explanation and Execution for Data Analysis","text":"interact AI API, require valid AI API key. configure key present globally environment times, can include .Renviron file. ensure key automatically loaded. setting mergen, variable called AI_API_KEY. information setting agent, recommend visit Get Started . Caution: ’re using version control systems like GitHub, include .Renviron .gitignore file prevent exposing personal API key. open .Renviron file modification project: persistent loading API key, add following line .Renviron file replacing \"your_key\" key. NOTE: setting API key .Renviron file, either restart R session run readRenviron(\".Renviron\") apply changes. however wish set variable single session, can use following command:","code":"require(usethis) edit_r_environ(scope=\"project\") AI_API_KEY=\"your_key\" Sys.setenv(AI_API_KEY=\"your_key\")"},{"path":"/index.html","id":"citing-mergen","dir":"","previous_headings":"","what":"Citing mergen","title":"AI-Driven Code Generation, Explanation and Execution for Data Analysis","text":"used mergen please cite: Jacqueline Jansen, Artür Manukyan, Nour Al Khoury, Altuna Akalin. (2023) “Leveraging large language models data analysis automation” bioRxiv, doi: 10.1101/2023.12.11.571140","code":""},{"path":"/index.html","id":"getting-help","dir":"","previous_headings":"","what":"Getting help","title":"AI-Driven Code Generation, Explanation and Execution for Data Analysis","text":"encounter clear bug, please file issue minimal reproducible example GitHub. can also post questions.","code":""},{"path":"/reference/check_install.html","id":null,"dir":"Reference","previous_headings":"","what":"Check and Install R Package — check_install","title":"Check and Install R Package — check_install","text":"function checks R package installed, , attempts install using either standard CRAN repository Bioconductor repository.","code":""},{"path":"/reference/check_install.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check and Install R Package — check_install","text":"","code":"check_install(package_name)"},{"path":"/reference/check_install.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check and Install R Package — check_install","text":"package_name character string specifying name package checked installed.","code":""},{"path":"/reference/check_install.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Check and Install R Package — check_install","text":"value returned. Called installation package.","code":""},{"path":"/reference/check_install.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Check and Install R Package — check_install","text":"","code":"# \\donttest{ # Check and install \"dplyr\" package check_install(\"dplyr\") #> Loading required package: dplyr #> #> Attaching package: ‘dplyr’ #> The following objects are masked from ‘package:stats’: #> #> filter, lag #> The following objects are masked from ‘package:base’: #> #> intersect, setdiff, setequal, union # }"},{"path":"/reference/clean_code_blocks.html","id":null,"dir":"Reference","previous_headings":"","what":"Clean code blocks returned by the agent — clean_code_blocks","title":"Clean code blocks returned by the agent — clean_code_blocks","text":"function cleans response returned agent ensure code blocks can run. ensures characters 'R' 'r' cleaned code blocks agents response, code blocks able extracted extractCode() function ran expected. also cleans response install.package calls, recorded output, code blocks extracted, code can run smoothly.","code":""},{"path":"/reference/clean_code_blocks.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Clean code blocks returned by the agent — clean_code_blocks","text":"","code":"clean_code_blocks(response)"},{"path":"/reference/clean_code_blocks.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Clean code blocks returned by the agent — clean_code_blocks","text":"response response received agent","code":""},{"path":"/reference/clean_code_blocks.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Clean code blocks returned by the agent — clean_code_blocks","text":"string holding response agent, cleaned unwanted characters.","code":""},{"path":"/reference/clean_code_blocks.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Clean code blocks returned by the agent — clean_code_blocks","text":"","code":"{ response <- \"To perform PCA, do the following: ```R prcomp(data)``` This funcion will perform PCA.\" clean_code <- clean_code_blocks(response) }"},{"path":"/reference/executeCode.html","id":null,"dir":"Reference","previous_headings":"","what":"execute code — executeCode","title":"execute code — executeCode","text":"function executes chunk code either current working environment saves output HTML file rendered part web page","code":""},{"path":"/reference/executeCode.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"execute code — executeCode","text":"","code":"executeCode(code, output = \"eval\", output.file = NULL)"},{"path":"/reference/executeCode.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"execute code — executeCode","text":"code code chunk text, without decorators HTML-specific characters. output output \"eval\", code executed . output \"html\", code executed. output.file output \"html\", user can provide file name html. provided temporary file created.","code":""},{"path":"/reference/executeCode.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"execute code — executeCode","text":"output \"eval\": running code causes errors, errors returned. Otherwise NA returned output \"html\", output file returned.","code":""},{"path":"/reference/extractCode.html","id":null,"dir":"Reference","previous_headings":"","what":"extract the code and text from the text returned by LLM agent — extractCode","title":"extract the code and text from the text returned by LLM agent — extractCode","text":"function parses agents answer returns text code single blocks. results can used code execution might useful displaying purposes later .","code":""},{"path":"/reference/extractCode.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"extract the code and text from the text returned by LLM agent — extractCode","text":"","code":"extractCode(text, delimiter = \"```\")"},{"path":"/reference/extractCode.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"extract the code and text from the text returned by LLM agent — extractCode","text":"text character string containing text embedded code blocks. delimiter character string representing delimiter used enclose code blocks (default: \"```\").","code":""},{"path":"/reference/extractCode.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"extract the code and text from the text returned by LLM agent — extractCode","text":"list two elements: 'code' 'text'. 'code' contains concatenated code blocks, 'text' contains remaining text code blocks removed.","code":""},{"path":"/reference/extractCode.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"extract the code and text from the text returned by LLM agent — extractCode","text":"","code":"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\""},{"path":"/reference/extractFilenames.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract file names from user prompt — extractFilenames","title":"Extract file names from user prompt — extractFilenames","text":"function extracts file names user prompt. Current filenames supported function *.txt, *.tsv, *.csv *.xls, *.xlsx, *.bed, *.bigWig, *.bw *.bigBed. filenames extracted. filenames found, function return NA.","code":""},{"path":"/reference/extractFilenames.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract file names from user prompt — extractFilenames","text":"","code":"extractFilenames(text)"},{"path":"/reference/extractFilenames.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract file names from user prompt — extractFilenames","text":"text user prompt","code":""},{"path":"/reference/extractFilenames.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract file names from user prompt — extractFilenames","text":"list holding file names user prompt.","code":""},{"path":"/reference/extractFilenames.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract file names from user prompt — extractFilenames","text":"","code":"{ user_prompt <- \"How do I perform PCA on data in my file called test.txt?\" extractFilenames(text=user_prompt) } #> [1] \"test.txt\""},{"path":"/reference/extractInstallPkg.html","id":null,"dir":"Reference","previous_headings":"","what":"extract package names and install them — extractInstallPkg","title":"extract package names and install them — extractInstallPkg","text":"function extracts package names needed run code returned agent installs needed.","code":""},{"path":"/reference/extractInstallPkg.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"extract package names and install them — extractInstallPkg","text":"","code":"extractInstallPkg(code)"},{"path":"/reference/extractInstallPkg.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"extract package names and install them — extractInstallPkg","text":"code code block returned agent.","code":""},{"path":"/reference/extractInstallPkg.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"extract package names and install them — extractInstallPkg","text":"value returned. Called installation package.","code":""},{"path":"/reference/extractInstallPkg.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"extract package names and install them — extractInstallPkg","text":"","code":"# \\donttest{ # Check code for packages that need installing code <- \"library(devtools)\\n x<-5\" extractInstallPkg(code) # }"},{"path":"/reference/fileHeaderPrompt.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract file headers from files in prompt — fileHeaderPrompt","title":"Extract file headers from files in prompt — fileHeaderPrompt","text":"function extracts file headers files. Recommended use function results extractFilenames","code":""},{"path":"/reference/fileHeaderPrompt.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract file headers from files in prompt — fileHeaderPrompt","text":"","code":"fileHeaderPrompt(filenames)"},{"path":"/reference/fileHeaderPrompt.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract file headers from files in prompt — fileHeaderPrompt","text":"filenames list containing file names.","code":""},{"path":"/reference/fileHeaderPrompt.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract file headers from files in prompt — fileHeaderPrompt","text":"string containing file headers files \"filenames\" list","code":""},{"path":"/reference/fileHeaderPrompt.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract file headers from files in prompt — fileHeaderPrompt","text":"","code":"if (FALSE) { prompt <- \"how do I perform PCA on data in a file called test.txt?\" filenames <- extractFilenames(prompt) fileHeaderPrompt(filenames) }"},{"path":"/reference/promptContext.html","id":null,"dir":"Reference","previous_headings":"","what":"Predefined prompt contexts for prompt engineering — promptContext","title":"Predefined prompt contexts for prompt engineering — promptContext","text":"function holds various predefined prompt contexts can used prompt engineering.","code":""},{"path":"/reference/promptContext.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Predefined prompt contexts for prompt engineering — promptContext","text":"","code":"promptContext(type = \"simple\")"},{"path":"/reference/promptContext.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Predefined prompt contexts for prompt engineering — promptContext","text":"type specifies type context wish returned. Valid options \"simple\", \"actAs\", \"CoT\" \"rbionfoExp\"","code":""},{"path":"/reference/promptContext.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Predefined prompt contexts for prompt engineering — promptContext","text":"string holding predefined context.","code":""},{"path":"/reference/selfcorrect.html","id":null,"dir":"Reference","previous_headings":"","what":"Self correct the code returned by the agent — selfcorrect","title":"Self correct the code returned by the agent — selfcorrect","text":"function attempts correct code returned agent re-feeding agent error message. error messages function returns original response.","code":""},{"path":"/reference/selfcorrect.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Self correct the code returned by the agent — selfcorrect","text":"","code":"selfcorrect( agent, prompt, context = rbionfoExp, attempts = 3, output.file = NULL, ... )"},{"path":"/reference/selfcorrect.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Self correct the code returned by the agent — selfcorrect","text":"agent object containing agent's information (e.g., type model). prompt prompt text send language model. context Optional context provide alongside prompt (default rbionfoExp). attempts Numeric value denoting many times code sent back fixing. output.file Optional output file created holding parsed code ... Additional arguments passed sendPrompt function.","code":""},{"path":"/reference/selfcorrect.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Self correct the code returned by the agent — selfcorrect","text":"list containing following elements: init.response character vector representing initial prompt response. init.blocks list initial blocks. final.blocks list final blocks. code.works boolean value indicating whether code works. exec.result character string representing execution results. tried.attempts integer representing number attempts.","code":""},{"path":[]},{"path":"/reference/selfcorrect.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Self correct the code returned by the agent — selfcorrect","text":"","code":"if (FALSE) { response <- selfcorrect(agent,prompt,context=rbionfoExp, max_tokens = 500) }"},{"path":"/reference/sendPrompt.html","id":null,"dir":"Reference","previous_headings":"","what":"Send a prompt to a specified language model agent and return the response. — sendPrompt","title":"Send a prompt to a specified language model agent and return the response. — sendPrompt","text":"Send prompt specified language model agent return response.","code":""},{"path":"/reference/sendPrompt.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Send a prompt to a specified language model agent and return the response. — sendPrompt","text":"","code":"sendPrompt( agent, prompt, context = rbionfoExp, return.type = c(\"text\", \"object\"), ... )"},{"path":"/reference/sendPrompt.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Send a prompt to a specified language model agent and return the response. — sendPrompt","text":"agent object containing agent's information (e.g., type model etc.). prompt prompt text send language model. context Optional context provide alongside prompt (default rbionfoExp). return.type type output return, either text response (\"text\") entire response object (\"object\"). ... Additional arguments passed prompt function.","code":""},{"path":"/reference/sendPrompt.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Send a prompt to a specified language model agent and return the response. — sendPrompt","text":"text response entire response object, based specified return type.","code":""},{"path":[]},{"path":"/reference/sendPrompt.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Send a prompt to a specified language model agent and return the response. — sendPrompt","text":"","code":"if (FALSE) { agent <- setupAgent(name=\"openai\",type=\"chat\",model=\"gpt-4\", ai_api_key=Sys.getenv(\"OPENAI_API_KEY\")) prompt <- \"tell me a joke\" response <- sendPrompt(agent, prompt) response <- sendPrompt(agent,prompt,context=rbionfoExp,return.type=\"text\", max_tokens = 500) }"},{"path":"/reference/setupAgent.html","id":null,"dir":"Reference","previous_headings":"","what":"set up an online LLM API for subsequent tasks — setupAgent","title":"set up an online LLM API for subsequent tasks — setupAgent","text":"function sets large language model API tasks.","code":""},{"path":"/reference/setupAgent.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"set up an online LLM API for subsequent tasks — setupAgent","text":"","code":"setupAgent( name = c(\"openai\", \"replicate\", \"generic\"), type = NULL, model = NULL, url = NULL, ai_api_key = Sys.getenv(\"AI_API_KEY\") )"},{"path":"/reference/setupAgent.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"set up an online LLM API for subsequent tasks — setupAgent","text":"name string name API, one \"openai\", \"replicate\" \"generic\". Currently supported APIs \"openai\" \"replicate\". user wishes use another API similar syntax openai API also supported via \"generic\" option. case, user also provide url API using type Specify type model (chat completion). parameter needs specified using 'openai model LLM model wish use. openAI chat model examples : 'gtp-3-5-turbo' 'gtp-4' openAI completion models examples : 'text-curie-001' 'text-davinci-002' replicate models examples : llama-2-70b-chat ( '02e509c789964a7ea8736978a43525956ef40397be9033abf9fd2badfe68c9e3') llama-2-13b-chat ( 'f4e2de70d66816a838a89eeeb621910adffb0dd0baba3976c96980970978018d') full list openAI models click . full list Replicate models, click . url url API case API \"generic\" selected. (Default: NULL) ai_api_key personal API key accessing LLM","code":""},{"path":"/reference/setupAgent.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"set up an online LLM API for subsequent tasks — setupAgent","text":"list holding agent information.","code":""},{"path":"/reference/setupAgent.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"set up an online LLM API for subsequent tasks — setupAgent","text":"","code":"{ myAgent <- setupAgent(name=\"openai\",type=\"chat\",model=\"gpt-4\",ai_api_key=\"my_key\") myAgent <- setupAgent(name=\"replicate\",type=NULL, model=\"02e509c789964a7ea8736978a43525956ef40397be9033abf9fd2badfe68c9e3\", ai_api_key=\"my_key\") }"},{"path":"/news/index.html","id":"mergen-version-011-2023-12-29","dir":"Changelog","previous_headings":"","what":"mergen Version 0.1.1 2023-12-29","title":"mergen Version 0.1.1 2023-12-29","text":"URLs DESCRIPTION added new feature: now users can specify openai-like APIs providing url setting agent name “generic” setupAgent() function new feature: clean_code_blocks() now automatically runs extractCode() called fix: typos setupAgent fixed fix: sendPrompt fixed broken due openai API changes fix: extractInstallPkg can now deal require() calls code blocks","code":""}] +[{"path":"/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2023 mergen authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"/articles/mergen.html","id":"setting-up-an-ai-agent","dir":"Articles","previous_headings":"","what":"Setting up an AI-agent","title":"Introduction to mergen","text":"able interact AI agent use agent subsequent tasks, mergen contains setupAgent function setting framework agent.Mergen allows set agent openai API platform well replicate API platform.","code":""},{"path":"/articles/mergen.html","id":"setting-up-an-openai-agent","dir":"Articles","previous_headings":"Setting up an AI-agent","what":"Setting up an openai agent","title":"Introduction to mergen","text":"setting agent openai API platform, can make use setupAgent function setting name=\"openai\" argument. Let’s look setting agent works: setupAgent function returns list containing agent information can used subsequent functions. mportant note ai_api_key OpenAI API key, provided string.","code":"myAgent <- setupAgent(name=\"openai\",type=\"chat\",model=\"gpt-4\",ai_api_key = \"your_key\") myAgent #> $name #> [1] \"userAgent\" #> #> $type #> [1] \"chat\" #> #> $API #> [1] \"openai\" #> #> $url #> [1] \"https://api.openai.com/v1/chat/completions\" #> #> $model #> [1] \"gpt-4\" #> #> $headers #> Authorization Content-Type #> \"Bearer your_key\" \"application/json\" #> #> $ai_api_key #> [1] \"your_key\""},{"path":"/articles/mergen.html","id":"setting-up-an-agent-for-replicate","dir":"Articles","previous_headings":"Setting up an AI-agent","what":"Setting up an agent for replicate","title":"Introduction to mergen","text":"setupAgent also contains functionality setting agent replicate AIs. Let’s look works:","code":"myAgent <- setupAgent(name=\"replicate\",type=NULL,model=\"llama-2-70b-chat\",ai_api_key=\"my_key\") myAgent #> $name #> [1] \"userAgent\" #> #> $type #> NULL #> #> $API #> [1] \"replicate\" #> #> $url #> [1] \"https://api.replicate.com/v1/predictions\" #> #> $model #> [1] \"llama-2-70b-chat\" #> #> $headers #> Authorization Content-Type #> \"Token my_key\" \"application/json\" #> #> $ai_api_key #> [1] \"my_key\""},{"path":"/articles/mergen.html","id":"sending-a-prompt","dir":"Articles","previous_headings":"","what":"Sending a prompt","title":"Introduction to mergen","text":"set agent, time ask questions AI model choice! , can make use sendPrompt function, selfcorrect function. choice one use depends whether want possible errors answered code corrected sending another request model .","code":""},{"path":"/articles/mergen.html","id":"using-the-sendprompt-function","dir":"Articles","previous_headings":"Sending a prompt","what":"Using the sendPrompt function","title":"Introduction to mergen","text":"Sending prompt sendPrompt function easy. function takes arguments agent, prompt, return.type context. default context set rbionfoExp. tells model choice act bioinformatics expert, return code R code triple backticks. prompt must given string, can contain question additional information want send. return value string containing models answer.","code":"answer <- sendPrompt(myAgent, \"how do I perform PCA on data in a file called test.txt?\",return.type = \"text\") answer #> [1] \"\\n\\nThe following R code will read the file called \\\"test.txt\\\", normalize the table and do PCA. First, the code will read the file into an R data frame: \\n\\n```\\ndata <- read.table(\\\"test.txt\\\", header = TRUE, sep = \\\"\\\\t\\\")\\n```\\n\\nNext, the data will be normalized to the range of 0 to 1:\\n\\n```\\nnormalized.data <- scale(data, center = TRUE, scale = TRUE)\\n```\\n\\nFinally, the normalized data will be used to do a Principal Component Analysis (PCA):\\n\\n```\\npca <- princomp(normalized.data)\\n```\""},{"path":"/articles/mergen.html","id":"using-the-selfcorrect-function","dir":"Articles","previous_headings":"Sending a prompt","what":"Using the selfcorrect function","title":"Introduction to mergen","text":"Sending prompt selfcorrect function, allow possible generated code optimized performance accuracy. code returned model excecutable, selfcorrect function send prompt back agent together list errors warnings, code can optimized. amount rounds possible selfcorrect can set user using attempts = n argument. return value list containing initial answer agent final answer n rounds selfcorrection.","code":"answer <- selfcorrect(myAgent, prompt=\"How do I perform PCA?\",attempts=3) print(answer) #> $init.response #> [1] \"\\n\\nThe following R code will read the file called \\\"test.txt\\\", normalize the table and do PCA. First, the code will read the file into an R data frame: \\n\\n```R\\ndata <- read.table(\\\"test.txt\\\", header = TRUE, sep = \\\"\\\\t\\\")\\n```\\n\\nNext, the data will be normalized to the range of 0 to 1:\\n\\n```{r}\\nnormalized.data <- scale(data, center = TRUE, scale = TRUE)\\n```\\n\\nFinally, the normalized data will be used to do a Principal Component Analysis (PCA):\\n\\n```{R}\\npca <- princomp(normalized.data)\\n```\" #> #> $init.blocks #> $init.blocks$code #> [1] \"\\ndata <- read.table(\\\"test.txt\\\", header = TRUE, sep = \\\"\\\\t\\\")\\n\\n\\nnormalized.data <- scale(data, center = TRUE, scale = TRUE)\\n\\n\\npca <- princomp(normalized.data)\\n\" #> #> $init.blocks$text #> [1] \"\\n\\nThe following R code will read the file called \\\"test.txt\\\", normalize the table and do PCA. First, the code will read the file into an R data frame: \\n\\n\\n\\n\\nNext, the data will be normalized to the range of 0 to 1:\\n\\n\\n\\n\\nFinally, the normalized data will be used to do a Principal Component Analysis (PCA):\\n\\n\\n\" #> #> #> $final.response #> [1] \"\\n\\nThe third response.The following R code will read the file called \\\"test.txt\\\", normalize the table and do PCA. First, the code will read the file into an R data frame: \\n\\n```{r}\\nplot(1:10)```\\n\\nNext, the data will be normalized to the range of 0 to 1:\\n\\n\" #> #> $final.blocks #> $final.blocks$code #> [1] \"\\nplot(1:10)\" #> #> $final.blocks$text #> [1] \"\\n\\nThe third response.The following R code will read the file called \\\"test.txt\\\", normalize the table and do PCA. First, the code will read the file into an R data frame: \\n\\n\\n\\n\\nNext, the data will be normalized to the range of 0 to 1:\\n\\n\" #> #> #> $code.works #> [1] TRUE #> #> $exec.result #> [1] \"path/to/html/file\" #> #> $tried.attempts #> [1] 3"},{"path":[]},{"path":"/articles/mergen.html","id":"extracting-code-blocks","dir":"Articles","previous_headings":"Running the code","what":"Extracting code blocks","title":"Introduction to mergen","text":"sent prompt recieved answer, mergen features function extractCode allows user extract code blocks given text. using , however, code blocks need cleaned , every agent return answer slightly different way. can done help clean_code_blocks function. example clean_code_blocks answer returned agent : can see , clean_code_blocks ensures code stripped extra symbols {r}, R, r {R}. ensures function extractCode can extract code blocks properly. extractCode function takes input string, also allows user set delimiter used enclose code blocks (default three backtics). Now lets look extractCode function returns: shown , extractCode returns list containing actual code associated text. code block can tested execution using executeCode function.","code":"code_cleaned <- clean_code_blocks(answer$final.response) cat(code_cleaned) #> #> #> The third response.The following R code will read the file called \"test.txt\", normalize the table and do PCA. First, the code will read the file into an R data frame: #> #> ``` #> plot(1:10)``` #> #> Next, the data will be normalized to the range of 0 to 1: final_code <- extractCode(code_cleaned,delimiter = \"```\") print (final_code) #> $code #> [1] \"\\nplot(1:10)\" #> #> $text #> [1] \"\\n\\nThe third response.The following R code will read the file called \\\"test.txt\\\", normalize the table and do PCA. First, the code will read the file into an R data frame: \\n\\n\\n\\n\\nNext, the data will be normalized to the range of 0 to 1:\\n\\n\""},{"path":"/articles/mergen.html","id":"running-the-code-1","dir":"Articles","previous_headings":"Running the code","what":"Running the code","title":"Introduction to mergen","text":"mergen features functions make easy user run code returned AI agent. code blocks cleaned extracted, code blocks can executed using executeCode function. , however, advised run extractInstallPkg function. function extracts package names installs missing packages needed code run. Finally, executeCode function can used. Lets see executeCode function : shown , code runs ! important note executeCode function change global environment. variables might created executing code deleted function completes.","code":"executeCode(final_code$code) #> NULL"},{"path":"/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Altuna Akalin. Author, maintainer. Jacqueline Anne Jansen. Author.","code":""},{"path":"/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Akalin , Jansen J (2023). mergen: AI-Driven Code Generation, Explanation Execution Data Analysis. R package version 0.1.1, https://bioinformatics.mdc-berlin.de/mergen/, https://github.com/BIMSBbioinfo/mergen.","code":"@Manual{, title = {mergen: AI-Driven Code Generation, Explanation and Execution for Data Analysis}, author = {Altuna Akalin and Jacqueline Anne Jansen}, year = {2023}, note = {R package version 0.1.1, https://bioinformatics.mdc-berlin.de/mergen/}, url = {https://github.com/BIMSBbioinfo/mergen}, }"},{"path":[]},{"path":"/index.html","id":"overview","dir":"","previous_headings":"","what":"Overview","title":"AI-Driven Code Generation, Explanation and Execution for Data Analysis","text":"mergen employs artificial intelligence convert data analysis questions executable code, explanations, algorithms. self-correction feature ensures generated code optimized performance accuracy. mergen features user-friendly chat interface, enabling users interact AI agent extract valuable insights data effortlessly.","code":""},{"path":"/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"AI-Driven Code Generation, Explanation and Execution for Data Analysis","text":"easiest way install mergen via install.packages","code":"install.packages(\"mergen\")"},{"path":"/index.html","id":"development-version","dir":"","previous_headings":"Installation","what":"Development version","title":"AI-Driven Code Generation, Explanation and Execution for Data Analysis","text":"get bug fix use feature development version, can install development version mergen GitHub.","code":"# install.packages(\"pak\") pak::pak(\"BIMSBbioinfo/mergen\")"},{"path":"/index.html","id":"prerequisites","dir":"","previous_headings":"","what":"Prerequisites","title":"AI-Driven Code Generation, Explanation and Execution for Data Analysis","text":"Make AI platform account. Choices openai.com, neets.ai (time writing free limits), replicate.com , perplexity.ai etc. addition, can locally run LLM server mode can interact via API. One example GPT4all. solutions tested work mergen. Create OpenAI API key use package Create replicate API key Set API key R","code":""},{"path":"/index.html","id":"configuring-your-ai-api-key","dir":"","previous_headings":"Prerequisites","what":"Configuring your AI API key","title":"AI-Driven Code Generation, Explanation and Execution for Data Analysis","text":"interact AI API, require valid AI API key. configure key present globally environment times, can include .Renviron file. ensure key automatically loaded. setting mergen, variable called AI_API_KEY. information setting agent, recommend visit Get Started . Caution: ’re using version control systems like GitHub, include .Renviron .gitignore file prevent exposing personal API key. open .Renviron file modification project: persistent loading API key, add following line .Renviron file replacing \"your_key\" key. NOTE: setting API key .Renviron file, either restart R session run readRenviron(\".Renviron\") apply changes. however wish set variable single session, can use following command:","code":"require(usethis) edit_r_environ(scope=\"project\") AI_API_KEY=\"your_key\" Sys.setenv(AI_API_KEY=\"your_key\")"},{"path":"/index.html","id":"citing-mergen","dir":"","previous_headings":"","what":"Citing mergen","title":"AI-Driven Code Generation, Explanation and Execution for Data Analysis","text":"used mergen please cite: Jacqueline Jansen, Artür Manukyan, Nour Al Khoury, Altuna Akalin. (2023) “Leveraging large language models data analysis automation” bioRxiv, doi: 10.1101/2023.12.11.571140","code":""},{"path":"/index.html","id":"getting-help","dir":"","previous_headings":"","what":"Getting help","title":"AI-Driven Code Generation, Explanation and Execution for Data Analysis","text":"encounter clear bug, please file issue minimal reproducible example GitHub. can also post questions.","code":""},{"path":"/reference/check_install.html","id":null,"dir":"Reference","previous_headings":"","what":"Check and Install R Package — check_install","title":"Check and Install R Package — check_install","text":"function checks R package installed, , attempts install using either standard CRAN repository Bioconductor repository.","code":""},{"path":"/reference/check_install.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check and Install R Package — check_install","text":"","code":"check_install(package_name)"},{"path":"/reference/check_install.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check and Install R Package — check_install","text":"package_name character string specifying name package checked installed.","code":""},{"path":"/reference/check_install.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Check and Install R Package — check_install","text":"TRUE package already installed can installed. FALSE otherwise","code":""},{"path":"/reference/check_install.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Check and Install R Package — check_install","text":"","code":"# \\donttest{ # Check and install \"dplyr\" package check_install(\"dplyr\") #> Loading required package: dplyr #> #> Attaching package: ‘dplyr’ #> The following objects are masked from ‘package:stats’: #> #> filter, lag #> The following objects are masked from ‘package:base’: #> #> intersect, setdiff, setequal, union # }"},{"path":"/reference/clean_code_blocks.html","id":null,"dir":"Reference","previous_headings":"","what":"Clean code blocks returned by the agent — clean_code_blocks","title":"Clean code blocks returned by the agent — clean_code_blocks","text":"function cleans response returned agent ensure code blocks can run. ensures characters 'R' 'r' cleaned code blocks agents response, code blocks able extracted extractCode() function ran expected. also cleans response install.package calls, recorded output, code blocks extracted, code can run smoothly.","code":""},{"path":"/reference/clean_code_blocks.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Clean code blocks returned by the agent — clean_code_blocks","text":"","code":"clean_code_blocks(response)"},{"path":"/reference/clean_code_blocks.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Clean code blocks returned by the agent — clean_code_blocks","text":"response response received agent","code":""},{"path":"/reference/clean_code_blocks.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Clean code blocks returned by the agent — clean_code_blocks","text":"string holding response agent, cleaned unwanted characters.","code":""},{"path":"/reference/clean_code_blocks.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Clean code blocks returned by the agent — clean_code_blocks","text":"","code":"{ response <- \"To perform PCA, do the following: ```R prcomp(data)``` This funcion will perform PCA.\" clean_code <- clean_code_blocks(response) }"},{"path":"/reference/executeCode.html","id":null,"dir":"Reference","previous_headings":"","what":"execute code — executeCode","title":"execute code — executeCode","text":"function executes chunk code either current working environment saves output HTML file rendered part web page","code":""},{"path":"/reference/executeCode.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"execute code — executeCode","text":"","code":"executeCode(code, output = \"eval\", output.file = NULL)"},{"path":"/reference/executeCode.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"execute code — executeCode","text":"code code chunk text, without decorators HTML-specific characters. output output \"eval\", code executed . output \"html\", code executed. output.file output \"html\", user can provide file name html. provided temporary file created.","code":""},{"path":"/reference/executeCode.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"execute code — executeCode","text":"output \"eval\": running code causes errors, errors returned. Otherwise NA returned output \"html\", output file returned.","code":""},{"path":"/reference/extractCode.html","id":null,"dir":"Reference","previous_headings":"","what":"extract the code and text from the text returned by LLM agent — extractCode","title":"extract the code and text from the text returned by LLM agent — extractCode","text":"function parses agents answer returns text code single blocks. results can used code execution might useful displaying purposes later .","code":""},{"path":"/reference/extractCode.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"extract the code and text from the text returned by LLM agent — extractCode","text":"","code":"extractCode(text, delimiter = \"```\")"},{"path":"/reference/extractCode.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"extract the code and text from the text returned by LLM agent — extractCode","text":"text character string containing text embedded code blocks. delimiter character string representing delimiter used enclose code blocks (default: \"```\").","code":""},{"path":"/reference/extractCode.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"extract the code and text from the text returned by LLM agent — extractCode","text":"list two elements: 'code' 'text'. 'code' contains concatenated code blocks, 'text' contains remaining text code blocks removed.","code":""},{"path":"/reference/extractCode.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"extract the code and text from the text returned by LLM agent — extractCode","text":"","code":"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\""},{"path":"/reference/extractFilenames.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract file names from user prompt — extractFilenames","title":"Extract file names from user prompt — extractFilenames","text":"function extracts file names user prompt. Current filenames supported function *.txt, *.tsv, *.csv *.xls, *.xlsx, *.bed, *.bigWig, *.bw *.bigBed. filenames extracted. filenames found, function return NA.","code":""},{"path":"/reference/extractFilenames.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract file names from user prompt — extractFilenames","text":"","code":"extractFilenames(text)"},{"path":"/reference/extractFilenames.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract file names from user prompt — extractFilenames","text":"text user prompt","code":""},{"path":"/reference/extractFilenames.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract file names from user prompt — extractFilenames","text":"list holding file names user prompt.","code":""},{"path":"/reference/extractFilenames.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract file names from user prompt — extractFilenames","text":"","code":"{ user_prompt <- \"How do I perform PCA on data in my file called test.txt?\" extractFilenames(text=user_prompt) } #> [1] \"test.txt\""},{"path":"/reference/extractInstallPkg.html","id":null,"dir":"Reference","previous_headings":"","what":"extract package names and install them — extractInstallPkg","title":"extract package names and install them — extractInstallPkg","text":"function extracts package names needed run code returned agent installs needed.","code":""},{"path":"/reference/extractInstallPkg.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"extract package names and install them — extractInstallPkg","text":"","code":"extractInstallPkg(code)"},{"path":"/reference/extractInstallPkg.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"extract package names and install them — extractInstallPkg","text":"code code block returned agent.","code":""},{"path":"/reference/extractInstallPkg.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"extract package names and install them — extractInstallPkg","text":"final status packages logical vector, TRUE packages already installed installed. FALSE package install.","code":""},{"path":"/reference/extractInstallPkg.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"extract package names and install them — extractInstallPkg","text":"","code":"# \\donttest{ # Check code for packages that need installing code <- \"library(devtools)\\n x<-5\" extractInstallPkg(code) #> Loading required package: devtools #> Loading required package: usethis #> devtools #> TRUE # }"},{"path":"/reference/fileHeaderPrompt.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract file headers from files in prompt — fileHeaderPrompt","title":"Extract file headers from files in prompt — fileHeaderPrompt","text":"function extracts file headers files. Recommended use function results extractFilenames","code":""},{"path":"/reference/fileHeaderPrompt.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract file headers from files in prompt — fileHeaderPrompt","text":"","code":"fileHeaderPrompt(filenames)"},{"path":"/reference/fileHeaderPrompt.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract file headers from files in prompt — fileHeaderPrompt","text":"filenames list containing file names.","code":""},{"path":"/reference/fileHeaderPrompt.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract file headers from files in prompt — fileHeaderPrompt","text":"string containing file headers files \"filenames\" list","code":""},{"path":"/reference/fileHeaderPrompt.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract file headers from files in prompt — fileHeaderPrompt","text":"","code":"if (FALSE) { prompt <- \"how do I perform PCA on data in a file called test.txt?\" filenames <- extractFilenames(prompt) fileHeaderPrompt(filenames) }"},{"path":"/reference/promptContext.html","id":null,"dir":"Reference","previous_headings":"","what":"Predefined prompt contexts for prompt engineering — promptContext","title":"Predefined prompt contexts for prompt engineering — promptContext","text":"function holds various predefined prompt contexts can used prompt engineering.","code":""},{"path":"/reference/promptContext.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Predefined prompt contexts for prompt engineering — promptContext","text":"","code":"promptContext(type = \"simple\")"},{"path":"/reference/promptContext.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Predefined prompt contexts for prompt engineering — promptContext","text":"type specifies type context wish returned. Valid options \"simple\", \"actAs\", \"CoT\" \"rbionfoExp\"","code":""},{"path":"/reference/promptContext.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Predefined prompt contexts for prompt engineering — promptContext","text":"string holding predefined context.","code":""},{"path":"/reference/selfcorrect.html","id":null,"dir":"Reference","previous_headings":"","what":"Self correct the code returned by the agent — selfcorrect","title":"Self correct the code returned by the agent — selfcorrect","text":"function attempts correct code returned agent re-feeding agent error message. error messages function returns original response.","code":""},{"path":"/reference/selfcorrect.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Self correct the code returned by the agent — selfcorrect","text":"","code":"selfcorrect( agent, prompt, context = rbionfoExp, attempts = 3, output.file = NULL, ... )"},{"path":"/reference/selfcorrect.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Self correct the code returned by the agent — selfcorrect","text":"agent object containing agent's information (e.g., type model). prompt prompt text send language model. context Optional context provide alongside prompt (default rbionfoExp). attempts Numeric value denoting many times code sent back fixing. output.file Optional output file created holding parsed code ... Additional arguments passed sendPrompt function.","code":""},{"path":"/reference/selfcorrect.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Self correct the code returned by the agent — selfcorrect","text":"list containing following elements: init.response character vector representing initial prompt response. init.blocks list initial blocks. final.blocks list final blocks. code.works boolean value indicating whether code works. exec.result character string representing execution results. tried.attempts integer representing number attempts.","code":""},{"path":[]},{"path":"/reference/selfcorrect.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Self correct the code returned by the agent — selfcorrect","text":"","code":"if (FALSE) { response <- selfcorrect(agent,prompt,context=rbionfoExp, max_tokens = 500) }"},{"path":"/reference/sendPrompt.html","id":null,"dir":"Reference","previous_headings":"","what":"Send a prompt to a specified language model agent and return the response. — sendPrompt","title":"Send a prompt to a specified language model agent and return the response. — sendPrompt","text":"Send prompt specified language model agent return response.","code":""},{"path":"/reference/sendPrompt.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Send a prompt to a specified language model agent and return the response. — sendPrompt","text":"","code":"sendPrompt( agent, prompt, context = rbionfoExp, return.type = c(\"text\", \"object\"), ... )"},{"path":"/reference/sendPrompt.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Send a prompt to a specified language model agent and return the response. — sendPrompt","text":"agent object containing agent's information (e.g., type model etc.). prompt prompt text send language model. context Optional context provide alongside prompt (default rbionfoExp). return.type type output return, either text response (\"text\") entire response object (\"object\"). ... Additional arguments passed prompt function.","code":""},{"path":"/reference/sendPrompt.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Send a prompt to a specified language model agent and return the response. — sendPrompt","text":"text response entire response object, based specified return type.","code":""},{"path":[]},{"path":"/reference/sendPrompt.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Send a prompt to a specified language model agent and return the response. — sendPrompt","text":"","code":"if (FALSE) { agent <- setupAgent(name=\"openai\",type=\"chat\",model=\"gpt-4\", ai_api_key=Sys.getenv(\"OPENAI_API_KEY\")) prompt <- \"tell me a joke\" response <- sendPrompt(agent, prompt) response <- sendPrompt(agent,prompt,context=rbionfoExp,return.type=\"text\", max_tokens = 500) }"},{"path":"/reference/setupAgent.html","id":null,"dir":"Reference","previous_headings":"","what":"set up an online LLM API for subsequent tasks — setupAgent","title":"set up an online LLM API for subsequent tasks — setupAgent","text":"function sets large language model API tasks.","code":""},{"path":"/reference/setupAgent.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"set up an online LLM API for subsequent tasks — setupAgent","text":"","code":"setupAgent( name = c(\"openai\", \"replicate\", \"generic\"), type = NULL, model = NULL, url = NULL, ai_api_key = Sys.getenv(\"AI_API_KEY\") )"},{"path":"/reference/setupAgent.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"set up an online LLM API for subsequent tasks — setupAgent","text":"name string name API, one \"openai\", \"replicate\" \"generic\". Currently supported APIs \"openai\" \"replicate\". user wishes use another API similar syntax openai API also supported via \"generic\" option. case, user also provide url API using type Specify type model (chat completion). parameter needs specified using 'openai model LLM model wish use. openAI chat model examples : 'gtp-3-5-turbo' 'gtp-4' openAI completion models examples : 'text-curie-001' 'text-davinci-002' replicate models examples : llama-2-70b-chat ( '02e509c789964a7ea8736978a43525956ef40397be9033abf9fd2badfe68c9e3') llama-2-13b-chat ( 'f4e2de70d66816a838a89eeeb621910adffb0dd0baba3976c96980970978018d') full list openAI models click . full list Replicate models, click . url url API case API \"generic\" selected. (Default: NULL) ai_api_key personal API key accessing LLM","code":""},{"path":"/reference/setupAgent.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"set up an online LLM API for subsequent tasks — setupAgent","text":"list holding agent information.","code":""},{"path":"/reference/setupAgent.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"set up an online LLM API for subsequent tasks — setupAgent","text":"","code":"{ myAgent <- setupAgent(name=\"openai\",type=\"chat\",model=\"gpt-4\",ai_api_key=\"my_key\") myAgent <- setupAgent(name=\"replicate\",type=NULL, model=\"02e509c789964a7ea8736978a43525956ef40397be9033abf9fd2badfe68c9e3\", ai_api_key=\"my_key\") }"},{"path":"/news/index.html","id":"mergen-version-011-2023-12-29","dir":"Changelog","previous_headings":"","what":"mergen Version 0.1.1 2023-12-29","title":"mergen Version 0.1.1 2023-12-29","text":"URLs DESCRIPTION added new feature: now users can specify openai-like APIs providing url setting agent name “generic” setupAgent() function new feature: clean_code_blocks() now automatically runs extractCode() called fix: typos setupAgent fixed fix: sendPrompt fixed broken due openai API changes fix: extractInstallPkg can now deal require() calls code blocks","code":""}]