Support for ChatGPT 3.5
sebastian-c opened this issue · 2 comments
sebastian-c commented
A new model for chatGPT has been released, but it uses a different endpoint. Here's some example code to get a result:
library(chatgpt)
library(httr)
library(jsonlite)
Sys.setenv(OPENAI_MODEL = "gpt-3.5-turbo")
Sys.setenv(OPENAI_API_KEY = readLines("~/api_keys/openapi.txt"))
openai_api_key = Sys.getenv("OPENAI_API_KEY")
gpt_model = Sys.getenv("OPENAI_MODEL")
messages = list(
list(role="system", content= "You are a helpful assistant."),
list(role="user", content= "Who won the world series in 2020?"),
list(role="assistant", content= "The Los Angeles Dodgers won the World Series in 2020."),
list(role="user", content= "Where was it played?")
)
params = list(model = gpt_model,
messages = messages)
response <- content(
POST(
"https://api.openai.com/v1/chat/completions",
add_headers(Authorization = paste("Bearer",
openai_api_key)),
content_type_json(),
body = toJSON(params, auto_unbox = TRUE)
)
)
shaynweidner commented
I just put in a pull request to incorporate my own attempt at this. Feel free to test drive it.
jcrodriguez1989 commented
Closed by #9
Thanks for your contribution @sebastian-c and @shaynweidner !!