Skip to content

Commit

Permalink
3rd version
Browse files Browse the repository at this point in the history
  • Loading branch information
kumeS committed Feb 18, 2024
1 parent 868524d commit c3e90a7
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: chatAI4R
Type: Package
Title: Chat-Based Interactive Artificial Intelligence for R
Version: 0.2.12
Date: 2023-09-30
Version: 0.3.1
Date: 2024-02-18
Authors@R: c(
person (given = "Satoshi", family = "Kume",
role = c("aut", "cre"),
Expand Down
4 changes: 2 additions & 2 deletions R/chat4R.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' @examples
#' \dontrun{
#' Sys.setenv(OPENAI_API_KEY = "Your API key")
#' response <- chat4R("What is the capital of France?")
#' response <- chat4R(content = "What is the capital of France?")
#' response
#' }

Expand Down Expand Up @@ -49,7 +49,7 @@ chat4R <- function(content,

# Extract and return the response content
if(simple){
return(data.frame(httr::content(response, "parsed"))$choices.message.content)
return(data.frame(content=httr::content(response, "parsed")$choices[[1]]$message$content))
}else{
if(fromJSON_parsed){
raw_content <- httr::content(response, "raw")
Expand Down
3 changes: 2 additions & 1 deletion R/chat4R_history.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ chat4R_history <- function(history,
encode = "json", config = headers)

# Parsing the result
return(data.frame(httr::content(response, "parsed"))$choices.message.content)
return(data.frame(content=httr::content(response, "parsed")$choices[[1]]$message$content))
}



7 changes: 4 additions & 3 deletions R/completions4R.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' to generate text based on the provided prompt and parameters.
#' @param prompt A string. The initial text that the model responds to.
#' @param api_key A string. The API key for OpenAI. Defaults to the value of the environment variable "OPENAI_API_KEY".
#' @param Model A string. The model ID to use, such as "text-davinci-003".
#' @param Model A string. The model ID to use, such as "davinci-002".
#' @param max_tokens Integer. The maximum number of tokens to generate.
#' @param temperature A numeric value to control the randomness of the generated text.
#' A value close to 0 produces more deterministic output, while a higher value (up to 2) produces more random output.
Expand All @@ -15,6 +15,7 @@
#' @author Satoshi Kume
#' @examples
#' \dontrun{
#' #This is a legacy function
#' Sys.setenv(OPENAI_API_KEY = "Your API key")
#'
#' prompt <- "Translate the following English text to French: 'Hello, world!'"
Expand All @@ -25,10 +26,10 @@

completions4R <- function(prompt,
api_key = Sys.getenv("OPENAI_API_KEY"),
Model = "text-davinci-003",
Model = "davinci-002",
max_tokens = 50,
temperature = 1,
simple=TRUE){
simple = TRUE){

# Define parameters
api_url <- "https://api.openai.com/v1/completions"
Expand Down
2 changes: 1 addition & 1 deletion R/proofreadEnglishText.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#' proofreadEnglishText(Model = "gpt-4-0613", SelectedCode = FALSE)
#' }

proofreadEnglishText <- function(Model = "gpt-4-0613",
proofreadEnglishText <- function(Model = "gpt-4",
SelectedCode = TRUE,
verbose = TRUE) {

Expand Down
2 changes: 1 addition & 1 deletion R/textEmbedding.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ textEmbedding <- function(text,
# Request body (set text data)
body <- list(
"input" = text,
"model" = "text-embedding-ada-002"
"model" = "text-embedding-ada-002" # text-embedding-3-large or text-embedding-3-small
)

# Send POST request to the server
Expand Down

0 comments on commit c3e90a7

Please sign in to comment.