Hi I have another answer that might work if needed, it worked for me
library(httr)
library(tidyverse)
#########################
##### GPT prompting #####
#########################
# Note: code we are using was adapted by this blog post: https://rpubs.com/nirmal/setting_chat_gpt_R.
# We highly recommend you read over that blog post in detail if you are stuck at any of these steps
# First, you must get your ChatGPT API key from here: https://platform.openai.com/overview
# Then, put your API key in the quotes below:
my_API <- "sk-00000000"
#The "hey_chatGPT function will help you access the API and prompt GPT
hey_DeepSeekGPT <- function(answer_my_question) {
DeepSeekGPT_answer <- POST(
url = "https://api.deepseek.com/chat/completions",
add_headers(Authorization = paste("Bearer", my_API)),
content_type_json(),
encode = "json",
body = list(
model = "deepseek-chat",
temperature = 0,
messages = list(
list(
role = "user",
content = answer_my_question
)
)
)
)
# Parse the response
response_content <- content(DeepSeekGPT_answer)
# Check for errors
if (!is.null(response_content$error)) {
stop(response_content$error$message)
} else {
return(str_trim(response_content$choices[[1]]$message$content))
}
}
# Test the function
hey_DeepSeekGPT("Why is the sky blue?")