-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,934 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
Package: PaLMr | ||
Type: Package | ||
Title: Interface for 'Google Pathways Language Model (PaLM)' | ||
Version: 0.1.4 | ||
Authors@R: c( | ||
person( | ||
given = "Li", family = "Yuan", role = c("aut", "cre"), | ||
email = "lyuan@gd.edu.kg" | ||
) | ||
) | ||
Maintainer: Li Yuan <lyuan@gd.edu.kg> | ||
Description: 'Google's 'PaLM' <https://developers.generativeai.google/> as a coding and writing assistant designed for 'R' and 'RStudio.' With a range of functions, including natural language processing and coding optimization, to assist R developers in simplifying tedious coding tasks and content searching. | ||
License: CC BY 4.0 | ||
URL: https://palmr.r.ly.gd.edu.kg/ | ||
BugReports: https://github.com/lygitdata/PaLMr/issues | ||
Encoding: UTF-8 | ||
LazyData: true | ||
RoxygenNote: 7.2.3 | ||
Imports: | ||
httr, | ||
jsonlite | ||
Package: PaLMr | ||
Type: Package | ||
Title: Interface for 'Google Pathways Language Model 2 (PaLM 2)' | ||
Version: 0.2.0 | ||
Authors@R: c( | ||
person( | ||
given = "Li", | ||
family = "Yuan", | ||
role = c("aut", "cre"), | ||
email = "lyuan@gd.edu.kg", | ||
comment = c(ORCID = "0009-0008-1075-9922") | ||
) | ||
) | ||
Maintainer: Li Yuan <lyuan@gd.edu.kg> | ||
Description: 'Google's 'PaLM 2' <https://developers.generativeai.google/> as a coding and writing assistant designed for 'R' and 'RStudio.' With a range of functions, including natural language processing and coding optimization, to assist R developers in simplifying tedious coding tasks and content searching. | ||
License: CC BY 4.0 | ||
URL: https://palmr.ly.gd.edu.kg/ | ||
BugReports: https://github.com/lygitdata/PaLMr/issues | ||
Encoding: UTF-8 | ||
LazyData: true | ||
RoxygenNote: 7.3.0 | ||
Imports: | ||
httr, | ||
jsonlite |
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,9 +1,13 @@ | ||
export(setupPALM) | ||
export(getTextPALM) | ||
export(getReferencePALM) | ||
export(fixGrammarPALM) | ||
export(explainCodePALM) | ||
export(optimizeCodePALM) | ||
|
||
import(httr) | ||
import(jsonlite) | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(palm.connect) | ||
export(palm.txt) | ||
export(palm.txt.explain.code) | ||
export(palm.txt.fix.grammar) | ||
export(palm.txt.get.reference) | ||
export(palm.txt.optimize.code) | ||
importFrom(httr,GET) | ||
importFrom(httr,POST) | ||
importFrom(httr,add_headers) | ||
importFrom(httr,content) | ||
importFrom(jsonlite,toJSON) |
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,76 @@ | ||
#' Set up and connect to the Google PaLM 2 text model. | ||
#' | ||
#' This function establishes a connection to the Google PaLM text model by specifying the API key, and model version. | ||
#' | ||
#' @param api A character string representing the API key for accessing the Google PaLM 2 text model. | ||
#' The API key should be 39 characters long and must be of the "character" class. | ||
#' @param version A character string representing the model version to use, either \code{"v1beta2"} or \code{"v1beta3"}. | ||
#' @param proxy A boolean value indicating whether to use a proxy for accessing the API | ||
#' URL (default is \code{FALSE}). If your local internet cannot access the APIs, set this | ||
#' parameter to \code{TRUE}. | ||
#' | ||
#' @return If successful, the function returns a character vector containing the API key, model version, and proxy status. | ||
#' If the API response indicates an error, the function stops execution and provides an error message. | ||
#' | ||
#' @details | ||
#' This function performs the necessary setup to connect to the Google PaLM 2 text model. It validates the provided API key and | ||
#' checks the correctness of the model version. If the input is valid, it constructs the API request and sends | ||
#' it to the PaLM 2 API endpoint. | ||
#' | ||
#' If an error occurs during the API request, such as an invalid API key or input parameters, an error message is displayed. | ||
#' If the API request is successful, the function prints the model details to the console and returns a character vector | ||
#' with the API key, model version, and model type. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' # Connect to the model, replace API_KEY with your api key | ||
#' palm.model = palm.connect("v1beta2", | ||
#' "API_KEY", | ||
#' FALSE) | ||
#' palm.model | ||
#' } | ||
#' | ||
#' @seealso | ||
#' \href{https://palmr.ly.gd.edu.kg/documentation/}{PaLMr - Documentation} | ||
#' | ||
#' @export | ||
#' | ||
#' @importFrom jsonlite toJSON | ||
#' @importFrom httr GET POST add_headers content | ||
palm.connect = function(version, | ||
api, | ||
proxy = FALSE) { | ||
version = match.arg(version, c("v1beta2", "v1beta3"), several.ok = FALSE) | ||
|
||
apiURL = ifelse( | ||
proxy, | ||
paste0( | ||
"https://api.genai.gd.edu.kg/google/", | ||
version, | ||
"/models/text-bison-001", | ||
"?key=", | ||
api | ||
), | ||
paste0( | ||
"https://generativelanguage.googleapis.com/", | ||
version, | ||
"/models/text-bison-001", | ||
"?key=", | ||
api | ||
) | ||
) | ||
|
||
response = httr::GET(url = apiURL, | ||
httr::add_headers("Content-Type" = "application/json")) | ||
responseJSON = httr::content(response, "parsed") | ||
|
||
if (!is.null(responseJSON$error)) { | ||
stop(responseJSON$error$message) | ||
} | ||
|
||
return(c( | ||
"version" = version, | ||
"api" = api, | ||
"proxy" = proxy | ||
)) | ||
} |
Oops, something went wrong.