Skip to content

Latest commit

 

History

History
245 lines (171 loc) · 12.4 KB

README.md

File metadata and controls

245 lines (171 loc) · 12.4 KB

chatAI4R: Chat-Based Interactive Artificial Intelligence for R

CRAN CRAN_latest_release_date CRAN :total status badge chatAI4R status badge

GitHub/chatAI4R

Description

chatAI4R, Chat-based Interactive Artificial Intelligence for R, is an R package designed to integrate the OpenAI API and other APIs for artificial intelligence (AI) applications. This package leverages large language model (LLM)-based AI techniques, enabling efficient knowledge discovery and data analysis. chatAI4R provides basic R functions for using LLM and a set of R functions to support the creation of prompts for using LLM. The LLMs allow us to extend the world of R. Additionally, I strongly believe that the LLM is becoming so generalized that "Are you searching Google?" is likely to evolve into "Are you LLMing?".

chatAI4R is an experimental project aimed at developing and implementing various LLM applications in R. Furthermore, the package is under continuous development with a focus on extending its capabilities for bioinformatics analysis.

About this project and future developments

  • AI integration with R

    • OpenAI API (ChatGPT, GPT-3.5, GPT-4, text embeddings)
  • LLM-assisted R Package Development

    • Package design, create R function, proofread English text, etc.
  • LLM-Based Data Analysis and Integration (future developments)

    • Automated Analysis: Analysis Design, Statistics, Data Visualization, Discussion, Question Answering
    • Highly-technical texts modeling and natural language question answering
    • Bioinformatics analysis

The functionality for interlanguage translation using DeepL has been separated as the 'deepRstudio' package. Functions related to text-to-image generation were separated as the 'stableDiffusion4R' package.

Installation of the chatAI4R package

1. Start R / RStudio console.

2. Run the following commands in the R console:

CRAN-version installation

# CRAN-version installation
install.packages("chatAI4R")
library(chatAI4R)

Dev-version installation (Recommended)

# Dev-version installation
devtools::install_github("kumeS/chatAI4R")
library(chatAI4R)

# Release v0.2.3
devtools::install_github("kumeS/chatAI4R", ref = "v0.2.3")
library(chatAI4R)

Installation from source

#For MacOS X, installation from source
system("wget https://github.com/kumeS/chatAI4R/archive/refs/tags/v0.2.3.tar.gz")
#or system("wget https://github.com/kumeS/chatAI4R/archive/refs/tags/v0.2.3.tar.gz --no-check-certificate")
system("R CMD INSTALL v0.2.3.tar.gz")

3. Set the API key according to each Web API.

For example, to obtain an OpenAI API key, please register as a member on the OpenAI website (https://platform.openai.com/account/api-keys) and obtain your API key.

#Set your key for the OpenAI API
Sys.setenv(OPENAI_API_KEY = "Your API key")

Create an .Rprofile file in your home directory and add your API key (using the code above) into it.

# Create a file
file.create("~/.Rprofile") 

# [MacOS X] Open the file and edit it
system(paste("open ~/.Rprofile"))

Note: Please be aware of newline character inconsistencies across different operating systems.

Tutorial

Basic usage

Applied usage of the chatAI4R package

  • AI-based chatting loaded with highly-technical documents (RIKEN Pressrelease text)

Prompts for chatGPT / GPT-4

File Description Prompt
create_flowcharts A prompt to create a flowchart Prompt
create_roxygen2_v01 A prompt to create a roxygen2 description Prompt
create_roxygen2_v02 A prompt to create a roxygen2 description Prompt
edit_DESCRIPTION A prompt to edit DESCRIPTION Prompt
Img2txt_prompt_v01 A prompt to create a i2i prompt Prompt
Img2txt_prompt_v02 A prompt to create a i2i prompt Prompt

R functions

Flowcharts of the R functions were created by GPT-4 + Skrive plugin.

Basic functions

Function Description Script Flowchart
chat4R Chat4R: Interact with GPT-3.5 (default) using OpenAI API (One-shot) Script Flowchart
chat4R_history Use chat history for OpenAI's GPT model Script Flowchart
completions4R Generate text using OpenAI completions API (One-shot) Script Flowchart
textEmbedding Text Embedding from OpenAI Embeddings API (model: text-embedding-ada-002) Script Flowchart
slow_print_v2 Slowly Print Text Script
ngsub Remove Extra Spaces and Newline Characters Script
removeQuotations Remove All Types of Quotations from Text Script

Basic Secondary Layer Functions

Function Description Script Flowchart
conversation4R Manage a conversation using a chatting history Script Flowchart
autocreateFunction4R Generate and Improve R Functions (experimental) Script
revisedText Revision for a scientific text Script

Functions for R package developments

Function Description Script Flowchart
designPackage Design Package for R Script
supportIdeaGeneration Support Idea Generation from Selected Text or Clipboard Input Script
enrichTextContent Enrich Text Content Script
createSpecifications4R Create Specifications for R Function Script
createRcode Create R Code from Clipboard Content and Output into the R Console Script
createRfunction Create R Function from Selected Text or Clipboard Content Script
convertRscript2Function Convert Selected R Script to R Function Script
OptimizeRcode Optimize and Complete R Code Script
addCommentCode Add Comments to R Code Script
addRoxygenDescription Add Roxygen Description to R Function Script
proofreadEnglishText Proofread English Text During R Package Development via RStudio API Script
checkErrorDet Check Error Details Script
checkErrorDet_JP Check Error Details in Japanese via RStudio API Script
convertScientificLiterature Convert to Scientific Literature Script
searchFunction Search the R function based on the provided text Script

Functions for Text Summary

Function Description Script Flowchart
TextSummary Summarize a long text (experimental) Script
summaryWebScrapingText Summarize Text via Web Scraping of Google Search Script
TextSummaryAsBullet Summarize Selected Text into Bullet Points Script
convertBullet2Sentence Convert Bullet Points to Sentences Script
chatAI4pdf Summarize PDF Text via LLM Script
extractKeywords Extract Keywords from Text Script

Interactions and Flow Control Between LLM-based Bots (LLBs)

Function Description Script Flowchart
discussion_flow_v1 Simulates interactions and flow control between three different roles of LLM-based bots (LLBs) Script

Functions for RIKEN press release (future developments)

  • get_riken_pressrelease_urls: Get URLs of RIKEN Press Releases
  • riken_pressrelease_text_jpn: Extract text from RIKEN press-release (Japanese)
  • riken_pressrelease_textEmbedding: Extract text and perform text embedding from RIKEN press-release

Simple usage

One-Shot Chatting

All runs using the chat4R function are One-Shot Chatting. Conversation history is not carried over to the next conversation.

#API: "https://api.openai.com/v1/chat/completions"
chat4R("Hello")

#API: "https://api.openai.com/v1/completions"
completions4R("Hello")

Few-Shots/Chain-Shots Chatting

Executions using the conversation4R function will keep a history of conversations. The number of previous messages to keep in memory defaults to 2.

#First shot
conversation4R("Hello")

#Second shot
conversation4R("Hello")

Text Embedding

Converts input text to a numeric vector. The model text-embedding-ada-002 results in a vector of 1536 floats.

#Embedding
textEmbedding("Hello, world!")

License

Copyright (c) 2023 Satoshi Kume. Released under the Artistic License 2.0.

Cite

Kume S. (2023) chatAI4R: Chat-based Interactive Artificial Intelligence for R.

#BibTeX
@misc{Kume2023chatAI4R,
  title={chatAI4R: Chat-Based Interactive Artificial Intelligence for R},
  author={Kume, Satoshi}, year={2023},
  publisher={GitHub}, note={R Package},
  howpublished={\url{https://github.com/kumeS/chatAI4R}},
}

Contributors

  • Satoshi Kume