library(httr)
library(rvest)
#library(tidyr)
#library(xml2)
library(jsonlite)
library (RSelenium)
setwd(dir = "/Users/arunamalla/Documents/Chatgpt_ora_forums")
OPENAI_API_KEY = "<<insert your new secret key here>>"
# read the file urls_txt.txt and feed this to chatgpt 3.5 using an API KEY
prompt <- "Write a simple linear regression program in R" #text prompt
make_req_gpt <- function(prompt){
headers <- c(
'Content-Type' = 'application/json',
'Authorization' = paste0('Bearer ', OPENAI_API_KEY)
)
data <- list(
'model' = 'gpt-3.5-turbo',
'messages' = list(
list('role' = 'system', 'content' = 'You are a helpful assistant.'),
list('role' = 'user', 'content' = prompt)
),
'temperature' = 0.0
)
json_data <- toJSON(data, auto_unbox = TRUE)
response <- POST(
url = 'https://api.openai.com/v1/chat/completions',
body = json_data,
add_headers(.headers = headers),
encode = "json"
)
return (response)
}
# go to each url and get the post details
#urls <- content(h_target, as = "text") %>% read_html %>% html_nodes(".rw-ListItem-primaryText a") %>% html_attr(name = "href")
get_url_data <- function(url){
r <- httr::GET(url, config = user_agent(agent = "mozilla"))
return (r)
}My Experiments with ChatGpt
ChatGpt is the AI sensation of the year. Like everyone else, I was curious to try using it to simplify day to day activities. Here’s a simple project I did in R, to collect data and answer as many questions from Oracle Forums, using ChatGpt.
Project
Answer as many questions in selected communities from Oracle Forums (https://forums.oracle.com/ords/apexds/user/user-ndnow)

Solution
ChatGpt limitations -
before discussing solution in details, we need to keep in mind that chatgpt has some limitations -
- Hallucination - may generate a completely made up response, which is irrelevant/incorrect
- we can send only 3 questions per minute, using OpenAI rest API call
- Model used “Chat-gpt-3.5”, which is freely available solution from OpenAI, at the time of writing this article
- ChatGpt 3.5 - is trained till Sep 2021 - So, it knows about Oracle tech stack/releases till Sep 2021
R Limitations -
- Memory limits and size - these are specific to the machine and the R version installed on that machine
Data Collection -
Select topics you are familiar with, to verify and judge whether ChatGpt response is correct or not.
Collected 50 html pages manually, related to topics - Oracle BI Publisher, OBIEE, SQL, REST API, OAUTH, Integration, ML, AI.
Tried automatic data collection, using RSelenium and R; but in vain. Automating this task was tedious and time consuming and also Oracle Forums were recently migrated to Oracle APEX, this migration process caused lot of down time, irrational/unexpected/unavailable functionality in most of Oracle Forums threads.
Data Preparation -
Select questions/posts; wisely based on the post date, post tags. Skim through collected data and remove posts related to latest versions, released after Sep 2021
Prerequisites to use ChatGpt 3.5 -
Create an user account in OpenAI.com, one can login using Google/Apple/Microsoft accounts
Generate OpenAI Key or token - Go to https://platform.openai.com/account/api-keys, to create a new secret key
save this newly generate secret key, this is required for authentication for each API call we are about to make
install libraries, (rvest, httr, jsonlite) to make REST API calls
Running Code
Code is uploaded to github. You can see code snippets here:
You can use the make_req_gpt function to make a API Call to chatgpt 3.5 like this: