Created
July 11, 2023 21:35
-
-
Save seandavi/36ae69cd15aa9b9d98f3fee0d96166d0 to your computer and use it in GitHub Desktop.
Small play function for interacting with Azure openai playground (chatgpt)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(httr2) | |
| ChatGPT <- function(prompt='Tell me about Bioconductor') { | |
| base_request = httr2::request('https://openai-playground-asdf.openai.azure.com/openai/deployments/gpt-4/chat/completions?api-version=2023-03-15-preview') | |
| res = base_request |> | |
| httr2::req_headers('api-key'=Sys.getenv('API_KEY')) |> | |
| httr2::req_body_json(list( | |
| messages= | |
| list( | |
| list(role="system",content="You are a helpful AI assistant"), | |
| list(role="user", content=prompt) | |
| ) | |
| )) | |
| resp = req_perform(res) | |
| lresp = resp_body_json(resp) | |
| rawresp = resp_body_string(resp) | |
| return(list(resp=lresp, rawresp=rawresp, content=lresp$choices[[1]]$message$content)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment