-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from jcrodriguez1989/develop
Release v0.2.3
- Loading branch information
Showing
16 changed files
with
321 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#' '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. | ||
#' | ||
"_PACKAGE" | ||
|
||
.state <- new.env(parent = emptyenv()) | ||
|
||
# Empty chat session messages at startup. | ||
assign( | ||
"chat_session_messages", | ||
list(list(role = "system", content = "You are a helpful assistant.")), | ||
envir = .state | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
#' Parse OpenAI API Response | ||
#' | ||
#' Takes the raw response from the OpenAI API and extracts the text content from it. | ||
#' This function is currently designed to differentiate between gpt-3.5-turbo and others. | ||
#' | ||
#' @param raw_response The raw response object returned by the OpenAI API. | ||
#' @param raw_responses The raw response object returned by the OpenAI API. | ||
#' | ||
#' @return Returns a character vector containing the text content of the response. | ||
#' | ||
parse_response <- function(raw_response) { | ||
# If the model is from the `gpt-3.5-turbo` family, it parses in a different way. | ||
if (grepl("gpt-3.5-turbo", Sys.getenv("OPENAI_MODEL", "gpt-3.5-turbo"))) { | ||
trimws(sapply(raw_response$choices, function(x) x$message$content)) | ||
} else { | ||
trimws(sapply(raw_response$choices, function(x) x$text)) | ||
} | ||
parse_response <- function(raw_responses) { | ||
# Parse the message content of the list of raw_responses. Trim those message, and paste them. | ||
paste(trimws(sapply(raw_responses, function(response) { | ||
sapply(response$choices, function(x) x$message$content) | ||
})), collapse = "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#' Reset Chat Session | ||
#' | ||
#' 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`. | ||
#' | ||
#' @param system_role ChatGPT's role as an AI assistant. | ||
#' | ||
#' @export | ||
#' | ||
reset_chat_session <- function(system_role = "You are a helpful assistant.") { | ||
assign( | ||
"chat_session_messages", list(list(role = "system", content = system_role)), | ||
envir = .state | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.