irudnyts / openai

An R package-wrapper around OpenAI API
https://irudnyts.github.io/openai/
Other
164 stars 28 forks source link

Error in paste("OpenAI API probably has been changed. If you see this, please", : OpenAI API probably has been changed. #52

Open reillysteel opened 9 months ago

reillysteel commented 9 months ago

I've been trying to loop create_chat_completion() over different message lists, and I got the following error on the third entry on the list:


Error in paste("OpenAI API probably has been changed. If you see this, please",  : 
  OpenAI API probably has been changed. If you see this, please rise an issue at: https://github.com/irudnyts/openai/issues

Per the instruction, I'm rising an issue here. Any help would be appreciated!

EDIT: I've found a workaround using the retry() function from the retry package, where I substitute the following for the function call in the loop:

retry(
    expr = create_chat_completion(text),
    when = "502|API",
    max_tries = 3,
    interval = runif(1, 6, 10)
  )

Still not entirely sure what the source of the error is, but this seems to work. It might be worth making a more informative error for the future.

irudnyts commented 9 months ago

Thanks for that! I'm currently doing a major revision, and I will have a look in the coming days.

irudnyts commented 9 months ago

@reillysteel, I'm developing now a new version which you can install via remotes::install_github("irudnyts/openai", ref = "r6"). Here is the code for the updated version:

library(openai)
client <- OpenAI(max_retries = 3) # one sets number of retries here
completion <- client$chat$completions$create(
    model = "gpt-3.5-turbo",
    messages = list(list("role" = "user", "content" = "What's up?"))
)
irudnyts commented 9 months ago

@reillysteel my bad, did not read carefully. If this error happens, can you please write down a reprex, e.g., specifying particular messages that fail?

reillysteel commented 9 months ago

Hard to write down a reprex because the error came up inconsistently (e.g., the error might arise for a chat completion, but it would work fine upon running the exact same chat completion again). The retry() method that I previously used allowed me to get around the issue by retrying the chat completion whenever the error popped up, though. If I encounter the error again, I will try writing down a reprex.

tyner commented 6 months ago

I encountered an error when trying to run the client$chat$completion$create(...) command...

Error in httr2::req_perform(): ! HTTP 503 Service Unavailable. Run ]8;;rstudio:run:rlang::last_trace()rlang::last_trace()]8;; to see where the error occurred.

rlang::last_trace(drop = FALSE)

says

\<error/httr2_http_503> Error in `httr2::req_perform()`: ! HTTP 503 Service Unavailable. --- Backtrace: x 1. \-client$chat$completions$create(...) 2. \-openai:::chat_completions_create(...) 3. \-httr2::req_perform(...) 4. \-httr2:::handle_resp(req, resp, error_call = error_call) 5. \-httr2:::resp_abort(resp, req, body, call = error_call) 6. \-rlang::abort(...)

here is my

sessionInfo()

R version 4.1.3 (2022-03-10) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C LC_TIME=English_United States.1252

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] openai_0.4.1

loaded via a namespace (and not attached): [1] httr_1.4.7 compiler_4.1.3 R6_2.5.1 assertthat_0.2.1 magrittr_2.0.3 cli_3.4.0 tools_4.1.3 httr2_1.0.0 glue_1.6.2 rappdirs_0.3.3
[11] curl_5.0.0 remotes_2.4.2 valentine_2024.2.14 jsonlite_1.8.0 lifecycle_1.0.3 rlang_1.1.0