Last updated
devtools::install_github("samterfa/openai")
library(openai)
library(purrr)Sys.setenv(openai_organization_id = "XXXXX")
Sys.setenv(openai_secret_key = "XXXXXX")course_gpt3 <- function(val, temp){
initPrompt <- "Classify each dish by its country of origin"
kw1 <- "Creme Brulée"
Cl1 <- "France"
kw2 <- "Schwarzwälder"
Cl2 <- "Germany"
kw3 <- "Couscous"
Cl3 <- "Morocco"
kw4 <- "Paella"
Cl4 <- "Spain"
kw5 <- "Fish and Chips"
Cl5 <- "England"
catPrompt = paste0("prompt : ", initPrompt,
"\ndish: " , kw1 , ", country :" , Cl1 ,
"\ndish: " , kw2 , ", country :" , Cl2 ,
"\ndish: " , kw3 , ", country :" , Cl3 ,
"\ndish: " , kw4 , ", country :" , Cl4 ,
"\ndish: " , kw5 , ", country :" , Cl5 ,
"\n\ndish: ",val,", country :")
result <- create_completion(
engine_id = 'davinci',
max_tokens = 5,
temperature = temp,
top_p = 1,
n = 1,
stream = F,
prompt = catPrompt) %>%
pluck('choices') %>%
map_chr(~ .x$text)
strsplit(result,"\n")[[1]][1]
}course_gpt3("matcha tea", 0.2)
course_gpt3("pizza", 0.2)
course_gpt3("nyc pizza", 0.2)
course_gpt3("sausage", 0.2)