Title: | Interface to 'ChatGPT' from R |
---|---|
Description: | 'OpenAI's 'ChatGPT' <https://chat.openai.com/> coding assistant for 'RStudio'. A set of functions and 'RStudio' addins that aim to help the R developer in tedious coding tasks. |
Authors: | Juan Cruz Rodriguez [aut, cre] |
Maintainer: | Juan Cruz Rodriguez <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.2.4 |
Built: | 2024-10-31 04:51:00 UTC |
Source: | https://github.com/jcrodriguez1989/chatgpt |
'OpenAI's 'ChatGPT' https://chat.openai.com/ coding assistant for 'RStudio'. A set of functions and 'RStudio' addins that aim to help the R developer in tedious coding tasks.
Maintainer: Juan Cruz Rodriguez [email protected]
Useful links:
Report bugs at https://github.com/jcrodriguez1989/chatgpt/issues
Note: See also 'reset_chat_session'.
ask_chatgpt(question)
ask_chatgpt(question)
question |
The question to ask ChatGPT. |
A character value with the response generated by ChatGPT.
## Not run: cat(ask_chatgpt("What do you think about R language?")) ## End(Not run)
## Not run: cat(ask_chatgpt("What do you think about R language?")) ## End(Not run)
ChatGPT: Comment Code
comment_code(code = clipr::read_clip(allow_non_interactive = TRUE))
comment_code(code = clipr::read_clip(allow_non_interactive = TRUE))
code |
The code to be commented by ChatGPT. If not provided, it will use what's copied on the clipboard. |
A character value with the response generated by ChatGPT.
## Not run: cat(comment_code("for (i in 1:10) {\n print(i ** 2)\n}")) ## End(Not run)
## Not run: cat(comment_code("for (i in 1:10) {\n print(i ** 2)\n}")) ## End(Not run)
ChatGPT: Complete Code
complete_code(code = clipr::read_clip(allow_non_interactive = TRUE))
complete_code(code = clipr::read_clip(allow_non_interactive = TRUE))
code |
The code to be completed by ChatGPT. If not provided, it will use what's copied on the clipboard. |
A character value with the response generated by ChatGPT.
## Not run: cat(complete_code("# A function to square each element of a vector\nsquare_each <- function(")) ## End(Not run)
## Not run: cat(complete_code("# A function to square each element of a vector\nsquare_each <- function(")) ## End(Not run)
Create 'testthat' test cases for the code.
create_unit_tests(code = clipr::read_clip(allow_non_interactive = TRUE))
create_unit_tests(code = clipr::read_clip(allow_non_interactive = TRUE))
code |
The code for which to create unit tests by ChatGPT. If not provided, it will use what's copied on the clipboard. |
A character value with the response generated by ChatGPT.
## Not run: cat(create_unit_tests("squared_numbers <- function(numbers) {\n numbers ^ 2\n}")) ## End(Not run)
## Not run: cat(create_unit_tests("squared_numbers <- function(numbers) {\n numbers ^ 2\n}")) ## End(Not run)
ChatGPT: Create Variable Name
create_variable_name(code = clipr::read_clip(allow_non_interactive = TRUE))
create_variable_name(code = clipr::read_clip(allow_non_interactive = TRUE))
code |
The code for which to give a variable name to its result. If not provided, it will use what's copied on the clipboard. |
A character value with the response generated by ChatGPT.
## Not run: cat(create_variable_name("sapply(1:10, function(i) i ** 2)")) ## End(Not run)
## Not run: cat(create_variable_name("sapply(1:10, function(i) i ** 2)")) ## End(Not run)
ChatGPT: Document Code (in roxygen2 format)
document_code(code = clipr::read_clip(allow_non_interactive = TRUE))
document_code(code = clipr::read_clip(allow_non_interactive = TRUE))
code |
The code to be documented by ChatGPT. If not provided, it will use what's copied on the clipboard. |
A character value with the response generated by ChatGPT.
## Not run: cat(document_code("square_numbers <- function(numbers) numbers ** 2")) ## End(Not run)
## Not run: cat(document_code("square_numbers <- function(numbers) numbers ** 2")) ## End(Not run)
ChatGPT: Explain Code
explain_code(code = clipr::read_clip(allow_non_interactive = TRUE))
explain_code(code = clipr::read_clip(allow_non_interactive = TRUE))
code |
The code to be explained by ChatGPT. If not provided, it will use what's copied on the clipboard. |
A character value with the response generated by ChatGPT.
## Not run: cat(explain_code("for (i in 1:10) {\n print(i ** 2)\n}")) ## End(Not run)
## Not run: cat(explain_code("for (i in 1:10) {\n print(i ** 2)\n}")) ## End(Not run)
ChatGPT: Find Issues in Code
find_issues_in_code(code = clipr::read_clip(allow_non_interactive = TRUE))
find_issues_in_code(code = clipr::read_clip(allow_non_interactive = TRUE))
code |
The code to be analyzed by ChatGPT. If not provided, it will use what's copied on the clipboard. |
A character value with the response generated by ChatGPT.
## Not run: cat(find_issues_in_code("i <- 0\nwhile (i < 0) {\n i <- i - 1\n}")) ## End(Not run)
## Not run: cat(find_issues_in_code("i <- 0\nwhile (i < 0) {\n i <- i - 1\n}")) ## End(Not run)
Get GPT Completions Endpoint
gpt_get_completions( prompt, openai_api_key = Sys.getenv("OPENAI_API_KEY"), messages = NULL )
gpt_get_completions( prompt, openai_api_key = Sys.getenv("OPENAI_API_KEY"), messages = NULL )
prompt |
The prompt to generate completions for. |
openai_api_key |
OpenAI's API key. |
messages |
Available variable, to send the needed messages list to ChatGPT. |
ChatGPT: Optimize Code
optimize_code(code = clipr::read_clip(allow_non_interactive = TRUE))
optimize_code(code = clipr::read_clip(allow_non_interactive = TRUE))
code |
The code to be optimized by ChatGPT. If not provided, it will use what's copied on the clipboard. |
A character value with the response generated by ChatGPT.
## Not run: cat(optimize_code("i <- 10\nwhile (i > 0) {\n i <- i - 1\n print(i)\n}")) ## End(Not run)
## Not run: cat(optimize_code("i <- 10\nwhile (i > 0) {\n i <- i - 1\n print(i)\n}")) ## End(Not run)
Takes the raw response from the OpenAI API and extracts the text content from it.
parse_response(raw_responses, verbosity = get_verbosity())
parse_response(raw_responses, verbosity = get_verbosity())
raw_responses |
The raw response object returned by the OpenAI API. |
verbosity |
The verbosity level for this function. |
Returns a character vector containing the text content of the response.
ChatGPT: Refactor Code
refactor_code(code = clipr::read_clip(allow_non_interactive = TRUE))
refactor_code(code = clipr::read_clip(allow_non_interactive = TRUE))
code |
The code to be refactored by ChatGPT. If not provided, it will use what's copied on the clipboard. |
A character value with the response generated by ChatGPT.
## Not run: cat(refactor_code("i <- 10\nwhile (i > 0) {\n i <- i - 1\n print(i)\n}")) ## End(Not run)
## Not run: cat(refactor_code("i <- 10\nwhile (i > 0) {\n i <- i - 1\n print(i)\n}")) ## End(Not run)
This function is intended to be used with 'ask_chatgpt'. If we are using 'ask_chatgpt' to chat with ChatGPT, and we want to start a new conversation, we must call 'reset_chat_session'.
reset_chat_session(system_role = "You are a helpful assistant.")
reset_chat_session(system_role = "You are a helpful assistant.")
system_role |
ChatGPT's role as an AI assistant. |
Run a ChatGPT RStudio Addin
run_addin(addin_name)
run_addin(addin_name)
addin_name |
The name of the adding to execute. |
Opens an interactive chat session with ChatGPT
run_addin_ask_chatgpt()
run_addin_ask_chatgpt()