• Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    R
  • License
    GNU General Publi...
  • Created almost 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An experimental and unofficial wrapper for interacting with OpenAI GPT models in R.

gptchatteR

An experimental and unofficial wrapper for interacting with OpenAI GPT models in R. gptchatteR uses the openai library to handle the OpenAI API endpoints.

Installation

→ Prerequisites

Install the devtools and openai packages:

install.packages(c("devtools", "openai"))

Load the devtools package:

library(devtools)

→ Install the gptchatteR package

install_github("isinaltinkaya/gptchatteR")

Quickstart

→ Prepare the chatter

Load the gptchatteR package:

library(gptchatteR)

Authenticate the chatter with your openai API key using the chatter.auth function.

chatter.auth("sk-qGTnjsCI8mZkCtvXVe6SUSEYOUROWNKEY")

Create a new chatter session with chatter.create function.

chatter.create()

Your chatter is now ready for use!

Usage

could not find function "chatter.chat"

library(gptchatteR)

→ Casual chat

You can use the chatter.chat function to send messages to ChatGPT and receive responses:

chatter.chat("Hello, ChatGPT!")

You can use the return_response=TRUE to return the full response, and save it as an object:

chat<-chatter.chat("What's the difference between a cat and a dog?",return_response=TRUE)
chat$choices[[1]]
[1] "\nThe main difference between cats and dogs is their temperaments. Cats tend to be more independent and aloof, while dogs are typically more social and loyal. Dogs are often seen as more obedient and trainable, while cats can be more unpredictable. Cats also tend to be more solitary, while dogs are often seen as pack animals."

→ Plot with chatter

The chatter.plot function can be used to generate plots based on the input data and the ChatGPT response. For example, to create a scatterplot of a dataframe named df with columns A and B, you could use the following code:

chatter.feed("I have a dataframe named df. It has two columns: A and B")
cp <- chatter.plot("Plot a scatterplot where x axis is A, y is B")

View the plot:

cp$plot

View the R code:

cp$command

→ Feed the chatter

The chatter.feed function can be used to provide the chatter session with information that can be used in future responses. This can be useful if you want the chatter to have access to specific data or context when generating a response.

You can also use the chatter.chat function with feed=TRUE to make the chatter remember the information in your message for future use. For example:

# Use the chatter.chat function with the feed argument set to TRUE 
# to make the chatter remember this information for future use
# and respond at the same time.
chatter.chat("I have a dataframe named df. It has two columns: A and B. What are my column names?",feed=TRUE)

# This will make the chatter remember that the dataframe has two 
# columns named A and B, and it will use this information when generating 
# its response to the question.
cp <- chatter.plot("Plot a scatterplot with x axis A and y axis B.")

# View the plot
cp$plot

# View the code
cp$command

# Make chatter run the plot code. This saves time if you are just
# trying it, but will not save the command returned by the chatter.
chatter.plot("Plot a scatterplot with x axis A and y axis B.", run=TRUE)


# Alternatively, just do both at the same time!
cp <- chatter.plot("Plot a scatterplot with x axis A and y axis B.", run=TRUE)
# Plot is also displayed, as well as saved to cp

Example

# Create a test data frame
library(tidyverse)
rt <- rnorm(1000, mean=700, sd=100) # Generate RT data
df <- tibble(RT = rt, group = rep(c("low", "high"), each=500))

# Feed the data frame information to the chat session
chatter.feed("I have a dataframe df")

# Use the chatter.plot function to create a histogram
chatter.plot("plot histogram of rt using ggplot with df")

License

This package is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

Note

gptchatteR defaults to using the text-davinci-003 model, a.k.a. GPT-3.5. ChatGPT is a fine-tuned version of GPT-3.5 to serve as a general-purpose chatbot.


FAQ - Frequently asked questions

1- My output is truncated

Try using a higher value for the maximum number of tokens (i.e. max_tokens parameter). By default, max_tokens is 100, which can be quite low if the answer is too long or if your chat history was too long.

2- I get the following error could not find function "chatter.chat"

Make sure you created your chatter using chatter.create().

The correct order of commands to initialize the chatbot is:

chatter.auth("XXXXXXXXXXXXXXXX")  # first authenticate your chatter
chatter.create()                  # then create your chatter
chatter.chat("Hello, ChatGPT!")   # chatter is now ready to use!

Acknowledgements

Thanks to OpenAI for making this technology available to the public.

Special thanks to ChatGPT for helping me write this file.

Thanks to the developer of the openai library for handling the API endpoints excellently and making it easy to develop this wrapper.

But most of all, thanks to the AI working behind the scenes. I read enough Asimov to have the utmost respect for you, and I appreciate all your efforts that make it easier for me to be lazy.

More Repositories

1

vcfgl

Genotype likelihood simulator for VCF/BCF files
C++
8
star
2

Hesaplamali_Biyoloji_ve_Biyoinformatige_Giris_2020

05.02.2020 tarihinde düzenlenen 5. Hacettepe Biyoloji ve Uygulamaları Kongresi dahilindeki "Hesaplamalı Biyoloji ve Biyoinformatiğe Giriş" isimli çalıştayına ait ders notları ve verileri içerir. (Lecture notes and datasets for the Introduction to Computational Biology and Bioinformatics workshop, in Turkish)
6
star
3

WPSG2022

OCaml
4
star
4

best-free-resources

Best resources (websites, youtube channels, videos, notes etc.) I use for learning awesome stuff!
3
star
5

PopulasyonBuyumesi

Population growth simulations with RShiny (in Turkish) https://isinaltinkaya.shinyapps.io/PopulasyonBuyumesiSimulasyonlari/
R
3
star
6

actg-lock

An i3lock lockscreen template. When you lock your screen, you can see the DNA sequence flowing in the matrix way.
Shell
2
star
7

js-unit-converter

Scientific unit converter written in JavaScript.
JavaScript
2
star
8

i3pomodoror

i3bars scripts for pomodoror; https://github.com/isinaltinkaya/pomodoror
Shell
2
star
9

cheatsheets

2
star
10

i3gcalendar

A script to see the closest event in your Google Calendar on your i3blocks bar.
Python
2
star
11

CV

Isin Altinkaya's Curriculum Vitae.
TeX
1
star
12

bash-functions

Time saver automatization functions to add your bashrc
Shell
1
star
13

gc-content

A python function for calculating GC content using eigenstrat type ancient DNA .geno and .snp files. Note: This code is very old and wrote it when I was a total newbie. Might delete it later
Python
1
star
14

bash-script-generator

Generate bash scripts with pre-written header and open with vim to start coding immediately.
Shell
1
star
15

adv_binf_2021_week1

Teaching material used in the "Advanced Bioinformatics for Next-Generation Sequencing" class, University of Copenhagen, 2021
HTML
1
star
16

gitgpt

Make ChatGPT write commit messages for you
Rust
1
star
17

RWorkshop19

R Workshop 2019, Lecturer: Isin Altinkaya
R
1
star
18

ngsAMOVA

Tool for performing AMOVA, Dxy and neighbor joining trees with NGS data
C++
1
star
19

i3blocks

i3blocks scripts written by Işın Altınkaya.
Shell
1
star
20

CSwR22_Group2

Repository for the presentation of CSwR 2022 class group 2.
HTML
1
star