Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for ChatGPT 3.5 #8

Closed
sebastian-c opened this issue Mar 2, 2023 · 2 comments
Closed

Support for ChatGPT 3.5 #8

sebastian-c opened this issue Mar 2, 2023 · 2 comments

Comments

@sebastian-c
Copy link

sebastian-c commented Mar 2, 2023

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
Copy link
Contributor

I just put in a pull request to incorporate my own attempt at this. Feel free to test drive it.

@jcrodriguez1989
Copy link
Owner

Closed by #9
Thanks for your contribution @sebastian-c and @shaynweidner !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants