blob: 515abc2b63d80307f60e6ec6f57f88eba9877cb7 [file] [log] [blame]
ben-aaron1883818e7c2022-09-08 17:49:01 +02001#' Make a test request to the GPT-3 API
2#'
3#' @description
ben-aaron1885bcd9112022-09-10 21:33:50 +02004#' `gpt3_test_request()` sends a basic [completion request](https://beta.openai.com/docs/api-reference/completions) to the Open AI GPT-3 API.
ben-aaron188b4ed9422022-09-22 15:22:23 +02005#' @param verbose (boolean) if TRUE prints the actual prompt and GPT-3 completion of the test request (default: TRUE).
ben-aaron1883818e7c2022-09-08 17:49:01 +02006#' @return A message of success or failure of the connection.
7#' @examples
ben-aaron1885bcd9112022-09-10 21:33:50 +02008#' gpt3_test_request()
ben-aaron1883818e7c2022-09-08 17:49:01 +02009#' @export
ben-aaron188b4ed9422022-09-22 15:22:23 +020010gpt3_test_request = function(verbose=T){
ben-aaron1883818e7c2022-09-08 17:49:01 +020011
12 check_apikey_form()
13
14 test_prompt = 'Write a story about R Studio:'
ben-aaron188b4ed9422022-09-22 15:22:23 +020015 test_output = gpt3_single_request(prompt_ = test_prompt
ben-aaron1883818e7c2022-09-08 17:49:01 +020016 , max_tokens = 100)
17 print(paste0('.. test successful ..'))
18
19 if(verbose==T){
ben-aaron188b4ed9422022-09-22 15:22:23 +020020 # print(paste0('Requested completion for this prompt --> ', test_prompt))
21 # print(paste0('GPT-3 completed --> ', test_output))
22 test_output
ben-aaron1883818e7c2022-09-08 17:49:01 +020023 }
24
25}