Hello
When I try to run the following R-code to call chatGPT:
library(httr)
library(stringr)
api_key ← “…”
response ← POST(
url = “https://api.openai.com/v1/chat/completions”,
add_headers(Authorization = paste(“Bearer”, api_key)),
content_type_json(),
encode = “json”,
body = list(
model = “gpt-3.5-turbo”,
messages = list(
list(
role = “user”,
content = “What is ChatGPT?”
)
)
)
)
content(response)
I get an error:
Error in UseMethod(“content”, x) :
no applicable method for ‘content’ applied to an object of class “response”
Any ideas what’s wrong?