ben-aaron188 | 3818e7c | 2022-09-08 17:49:01 +0200 | [diff] [blame^] | 1 | #' Set up the authentication with your API key |
| 2 | #' |
| 3 | #' @description |
| 4 | #' Access to GPT-3's functions requires an API key that you obtain from [https://openai.com/api/](https://openai.com/api/). `gpt3.authenticate()` accepts your API key and ensures that you can connect to the models. `gpt3.endsession()` overwrites your API key _for this session_ (it is recommended that you run this when you are done). `check_apikey_form()` is a simple check if any information has been provided at all. |
| 5 | #' @param apikey A character vector that is your personal API key |
| 6 | #' @return A confirmation message |
| 7 | #' @examples |
| 8 | #' # Starting a session: |
| 9 | #' gpt3.authenticate(apikey = 'REPLACE_THIS_WITH_YOUR_KEY') |
| 10 | # ' |
| 11 | #' # After you are finished: |
| 12 | #' gpt3.endsession() |
| 13 | #' @export |
| 14 | gpt3.authenticate = function(apikey){ |
| 15 | api_key <<- apikey |
| 16 | print(paste0("Will use --> ", api_key, " for authentication.")) |
| 17 | } |
| 18 | |
| 19 | gpt3.endsession = function(){ |
| 20 | api_key = "---" |
| 21 | print('-- session ended: you need to re-authenticate again next time.') |
| 22 | } |
| 23 | |
| 24 | check_apikey_form = function(){ |
| 25 | |
| 26 | if(exists(x = 'api_key') == F){ |
| 27 | warning("Use gpt3.authenticate() to set your API key") |
| 28 | } else if(nchar(api_key) < 10){ |
| 29 | |
| 30 | warning("Use gpt3.authenticate() to set your API key") |
| 31 | |
| 32 | } |
| 33 | } |