ben-aaron188 | 3818e7c | 2022-09-08 17:49:01 +0200 | [diff] [blame] | 1 | #' Make a test request to the GPT-3 API |
| 2 | #' |
| 3 | #' @description |
ben-aaron188 | 718e3a6 | 2022-10-24 14:28:51 +0200 | [diff] [blame^] | 4 | #' `gpt3_test_completion()` sends a basic [completion request](https://beta.openai.com/docs/api-reference/completions) to the Open AI GPT-3 API. |
ben-aaron188 | b4ed942 | 2022-09-22 15:22:23 +0200 | [diff] [blame] | 5 | #' @param verbose (boolean) if TRUE prints the actual prompt and GPT-3 completion of the test request (default: TRUE). |
ben-aaron188 | 3818e7c | 2022-09-08 17:49:01 +0200 | [diff] [blame] | 6 | #' @return A message of success or failure of the connection. |
| 7 | #' @examples |
ben-aaron188 | 718e3a6 | 2022-10-24 14:28:51 +0200 | [diff] [blame^] | 8 | #' gpt3_test_completion() |
ben-aaron188 | 3818e7c | 2022-09-08 17:49:01 +0200 | [diff] [blame] | 9 | #' @export |
ben-aaron188 | 718e3a6 | 2022-10-24 14:28:51 +0200 | [diff] [blame^] | 10 | gpt3_test_completion = function(verbose=T){ |
ben-aaron188 | 3818e7c | 2022-09-08 17:49:01 +0200 | [diff] [blame] | 11 | |
| 12 | check_apikey_form() |
| 13 | |
ben-aaron188 | 718e3a6 | 2022-10-24 14:28:51 +0200 | [diff] [blame^] | 14 | test_prompt = 'Write a story about R Studio: ' |
| 15 | test_output = gpt3_single_completion(prompt_ = test_prompt |
ben-aaron188 | 3818e7c | 2022-09-08 17:49:01 +0200 | [diff] [blame] | 16 | , max_tokens = 100) |
| 17 | print(paste0('.. test successful ..')) |
| 18 | |
| 19 | if(verbose==T){ |
ben-aaron188 | b4ed942 | 2022-09-22 15:22:23 +0200 | [diff] [blame] | 20 | # print(paste0('Requested completion for this prompt --> ', test_prompt)) |
| 21 | # print(paste0('GPT-3 completed --> ', test_output)) |
| 22 | test_output |
ben-aaron188 | 3818e7c | 2022-09-08 17:49:01 +0200 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | } |