blob: bfd8836dc9a9371216da4ad066a72a7ee99a8864 [file] [log] [blame]
ben-aaron1883818e7c2022-09-08 17:49:01 +02001#' Make a test request to the GPT-3 API
2#'
3#' @description
ben-aaron188718e3a62022-10-24 14:28:51 +02004#' `gpt3_test_completion()` 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-aaron188718e3a62022-10-24 14:28:51 +02008#' gpt3_test_completion()
ben-aaron1883818e7c2022-09-08 17:49:01 +02009#' @export
ben-aaron188718e3a62022-10-24 14:28:51 +020010gpt3_test_completion = function(verbose=T){
ben-aaron1883818e7c2022-09-08 17:49:01 +020011
12 check_apikey_form()
13
ben-aaron188718e3a62022-10-24 14:28:51 +020014 test_prompt = 'Write a story about R Studio: '
15 test_output = gpt3_single_completion(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}