Skip to content

Instantly share code, notes, and snippets.

View bquilty25's full-sized avatar

Billy Quilty bquilty25

  • London, UK
View GitHub Profile
@bquilty25
bquilty25 / gist:1cb5c352a25a9af253646d1fc745cb4b
Created January 29, 2024 10:51
Accessing OpenAI API from R
library(httr)
library(jsonlite)
api_key <- "sk-XXX" # Set your OpenAI API key (don't publish anywhere public!)
base_url_openai <- "https://api.openai.com/v1"
openai_call <- function(prompt) {
request_url <- paste0(base_url_openai, "/chat/completions")