Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSL/TLS connection timeout on complex queries to OpenAI from R #318

Open
CorradoLanera opened this issue Feb 11, 2025 · 0 comments
Open

Comments

@CorradoLanera
Copy link

CorradoLanera commented Feb 11, 2025

This is related to #213 , #300 , and the recent #315

Here is an example (with some details I think could be helpful) of a "complex" query I cannot send and which fails much earlier than the 10-minute timeout limit I have set. (it is not a reprex, but it isn't very easy for me to make it with that kind of data and info, which I cannot share; if you need more information, please tell me)

In summary, even if I set 600 seconds of timeout, the OpenAI query returns a timeout error after less than 30 seconds. As with my experience (see #213 (comment) for more details), this is (very!!) strangely related to R itself and would not happen with the official Python API.

Note: the model used is gpt-4o-mini (same effect with gpt-4o as well)

code

query_gpt_w_pdf <- function(chat, png_content, chat_type) {
  withr::local_options(ellmer_timeout_s = 600)
  chat$extract_data(png_content, type = chat_type)
}

chatGPT$get_system_prompt() |>
  nchar()

str(ContentImgPdf, 1)
object.size(ContentImgPdf) |>
  prettyunits::pretty_bytes()

str(chatOutputType@properties, 0)

tic <- Sys.time()
query_gpt_w_pdf(chatGPT, ContentImgPdf, chatOutputType)
toc <- Sys.time()
toc - tic

res

> chatGPT$get_system_prompt() |>
+   nchar()
[1] 74429
> str(ContentImgPdf, 1)
<ellmer::ContentImageInline>
 @ type: chr "image/png"
 @ data: chr "iVBORw0KGgoAAAANSUhEUgAAANYAAAfQCAYAAAC+HaG9AAAAIGNIUk0AAHomAACAhAAA+gAAAIDoAAB1MAAA6mAAADqYAAAXcJy6UTwAAAAGYkt"| __truncated__
> object.size(ContentImgPdf) |>
+   prettyunits::pretty_bytes()
[1] "647.94 kB"
> str(chatOutputType@properties, 0)
List of 45
> tic <- Sys.time()
> query_gpt_w_pdf(chatGPT, ContentImgPdf, chatOutputType)
Error in `req_perform()`:
! Failed to perform HTTP request.
Caused by error in `curl::curl_fetch_memory()`:
! Timeout was reached [api.openai.com]: SSL/TLS connection timeout
Run `rlang::last_trace()` to see where the error occurred.
> toc <- Sys.time()
> toc - tic
Time difference of 27.38147 secs

trace

> rlang::last_trace()
<error/httr2_failure>
Error in `req_perform()`:
! Failed to perform HTTP request.
Caused by error in `curl::curl_fetch_memory()`:
! Timeout was reached [api.openai.com]: SSL/TLS connection timeout
---
Backtrace:1. └─global query_gpt_w_pdf(chatGPT, ContentImgPdf, chatOutputType)
  2.   └─chat$extract_data(png_content, type = chat_type) at R/query_gpt_w_pdf.R:3:3
  3.     └─coro::collect(...)
  4.       └─coro:::reduce_steps(x, steps, along_builder(list()))
  5.         └─coro:::reduce(x, reducer, .init = identity)
  6.           └─coro:::reduce_impl(.x, .f, ..., .init = .init)
  7.             └─coro:::iter_reduce_impl(.x, .f, ..., .left = .left)
  8.               ├─coro::is_exhausted(new <- .x())
  9.               └─coro (local) .x()
 10.                 └─base::evalq(...)
 11.                   └─base::evalq(...)
 12.                     ├─base::evalq(...)
 13.                     │ └─base::evalq(...)
 14.                     │   └─coro (local) user(...)
 15.                     │     ├─.last_value <<- eval_bare(substitute(expr), user_env)
 16.                     │     │ └─rlang::env_poke(env, lhs, value, inherit = TRUE, create = FALSE)
 17.                     │     └─rlang::eval_bare(substitute(expr), user_env)
 18.                     └─ellmer:::chat_perform(...)
 19.                       └─ellmer:::chat_perform_value(provider, req)
 20.                         ├─httr2::resp_body_json(req_perform(req))
 21.                         │ └─httr2:::check_response(resp)
 22.                         │   └─httr2:::is_response(resp)
 23.                         └─httr2::req_perform(req)
 24.                           └─base::tryCatch(...)
 25.                             └─base (local) tryCatchList(expr, classes, parentenv, handlers)
 26.                               └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
 27.                                 └─value[[3L]](cond)

Session Info

Session info
> devtools::session_info()
─ Session info ────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.4.2 (2024-10-31 ucrt)
 os       Windows 11 x64 (build 26100)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  English_United States.utf8
 ctype    English_United States.utf8
 tz       Europe/Rome
 date     2025-02-11
 rstudio  2024.12.0+467.pro1 Kousa Dogwood (desktop)
 pandoc   NA
 quarto   ERROR: Unknown command "TMPDIR=C:/Users/corra/AppData/Local/Temp/RtmpmaykEM/filea3c291a5942". Did you mean command "create"? @ C:\\PROGRA~1\\Quarto\\bin\\quarto.exePackages ────────────────────────────────────────────────────────────────────────────────────────────────────────────
 !  package      * version date (UTC) lib source
 P  backports      1.5.0   2024-05-23 [?] CRAN (R 4.4.0)
 P  base64url      1.4     2018-05-14 [?] CRAN (R 4.4.1)
 P  brio           1.1.5   2024-04-24 [?] CRAN (R 4.4.1)
 P  cachem         1.1.0   2024-05-16 [?] CRAN (R 4.4.1)
 P  callr          3.7.6   2024-03-25 [?] CRAN (R 4.4.1)
 P  checkmate    * 2.3.2   2024-07-29 [?] CRAN (R 4.4.1)
 P  cli            3.6.3   2024-06-21 [?] CRAN (R 4.4.1)
 P  codetools      0.2-20  2024-03-31 [?] CRAN (R 4.4.2)
 P  coro           1.1.0   2024-11-05 [?] CRAN (R 4.4.2)
 P  crayon         1.5.3   2024-06-20 [?] CRAN (R 4.4.1)
 P  crew           1.0.0   2025-02-03 [?] CRAN (R 4.4.2)
 P  curl           6.2.0   2025-01-23 [?] CRAN (R 4.4.2)
 P  data.table     1.16.4  2024-12-06 [?] CRAN (R 4.4.2)
 P  devtools     * 2.4.5   2022-10-11 [?] CRAN (R 4.4.1)
 P  digest         0.6.37  2024-08-19 [?] CRAN (R 4.4.1)
 P  dplyr          1.1.4   2023-11-17 [?] CRAN (R 4.4.1)
 P  ellipsis       0.3.2   2021-04-29 [?] CRAN (R 4.4.1)
 P  ellmer         0.1.1   2025-02-07 [?] CRAN (R 4.4.2)
 P  evaluate       1.0.3   2025-01-10 [?] CRAN (R 4.4.2)
 P  fastmap        1.2.0   2024-05-15 [?] CRAN (R 4.4.1)
 P  fs             1.6.5   2024-10-30 [?] RSPM
 P  generics       0.1.3   2022-07-05 [?] CRAN (R 4.4.1)
 P  getip          0.1-4   2023-12-10 [?] CRAN (R 4.4.0)
 P  glue           1.8.0   2024-09-30 [?] CRAN (R 4.4.1)
 P  here           1.0.1   2020-12-13 [?] CRAN (R 4.4.1)
 P  htmltools      0.5.8.1 2024-04-04 [?] CRAN (R 4.4.1)
 P  htmlwidgets    1.6.4   2023-12-06 [?] CRAN (R 4.4.1)
 P  httpuv         1.6.15  2024-03-26 [?] CRAN (R 4.4.1)
 P  httr2          1.1.0   2025-01-18 [?] CRAN (R 4.4.2)
 P  igraph         2.1.4   2025-01-23 [?] CRAN (R 4.4.2)
 P  jsonlite       1.8.9   2024-09-20 [?] RSPM
 P  knitr          1.49    2024-11-08 [?] RSPM
 P  later          1.4.1   2024-11-27 [?] CRAN (R 4.4.2)
 P  lifecycle      1.0.4   2023-11-07 [?] CRAN (R 4.4.1)
 P  lubridate      1.9.4   2024-12-08 [?] CRAN (R 4.4.2)
 P  magrittr       2.0.3   2022-03-30 [?] CRAN (R 4.4.1)
 P  memoise        2.0.1   2021-11-26 [?] CRAN (R 4.4.1)
 P  mime           0.12    2021-09-28 [?] CRAN (R 4.4.0)
 P  miniUI         0.1.1.1 2018-05-18 [?] CRAN (R 4.4.1)
 P  mirai          2.1.0   2025-02-07 [?] CRAN (R 4.4.2)
 P  nanonext       1.5.0   2025-01-28 [?] CRAN (R 4.4.2)
 P  pillar         1.10.1  2025-01-07 [?] CRAN (R 4.4.2)
 P  pkgbuild       1.4.6   2025-01-16 [?] CRAN (R 4.4.2)
 P  pkgconfig      2.0.3   2019-09-22 [?] CRAN (R 4.4.1)
 P  pkgload        1.4.0   2024-06-28 [?] CRAN (R 4.4.1)
 P  prettyunits    1.2.0   2023-09-24 [?] CRAN (R 4.4.1)
 P  processx       3.8.5   2025-01-08 [?] CRAN (R 4.4.2)
 P  profvis        0.4.0   2024-09-20 [?] RSPM
 P  promises       1.3.2   2024-11-28 [?] CRAN (R 4.4.2)
 P  ps             1.8.1   2024-10-28 [?] RSPM (R 4.4.0)
 P  purrr          1.0.4   2025-02-05 [?] CRAN (R 4.4.2)
 P  qs2            0.1.4   2024-12-12 [?] RSPM
 P  R6             2.5.1   2021-08-19 [?] CRAN (R 4.4.1)
 P  rappdirs       0.3.3   2021-01-31 [?] CRAN (R 4.4.1)
 P  Rcpp           1.0.14  2025-01-12 [?] CRAN (R 4.4.2)
 PD RcppParallel   5.1.10  2025-01-24 [?] CRAN (R 4.4.2)
 P  remotes        2.5.0   2024-03-17 [?] CRAN (R 4.4.1)
    renv           1.1.0   2025-01-29 [1] CRAN (R 4.4.2)
 P  rlang          1.1.5   2025-01-17 [?] CRAN (R 4.4.2)
 P  rprojroot      2.0.4   2023-11-05 [?] CRAN (R 4.4.1)
 P  rstudioapi     0.17.1  2024-10-22 [?] RSPM
 P  S7             0.2.0   2024-11-07 [?] CRAN (R 4.4.2)
 P  secretbase     1.0.4   2025-01-16 [?] CRAN (R 4.4.2)
 P  sessioninfo    1.2.3   2025-02-05 [?] CRAN (R 4.4.2)
 P  shiny          1.10.0  2024-12-14 [?] CRAN (R 4.4.2)
 P  stringfish     0.16.0  2023-11-28 [?] CRAN (R 4.4.1)
 P  stringi        1.8.4   2024-05-06 [?] CRAN (R 4.4.0)
 P  stringr        1.5.1   2023-11-14 [?] CRAN (R 4.4.1)
 P  tarchetypes  * 0.12.0  2025-01-31 [?] CRAN (R 4.4.2)
 P  targets      * 1.10.1  2025-01-31 [?] CRAN (R 4.4.2)
 P  testthat     * 3.2.3   2025-01-13 [?] CRAN (R 4.4.2)
 P  tibble         3.2.1   2023-03-20 [?] CRAN (R 4.4.1)
 P  tidyselect     1.2.1   2024-03-11 [?] CRAN (R 4.4.1)
 P  timechange     0.3.0   2024-01-18 [?] CRAN (R 4.4.1)
 P  urlchecker     1.0.1   2021-11-30 [?] CRAN (R 4.4.1)
 P  usethis      * 3.1.0   2024-11-26 [?] CRAN (R 4.4.2)
 P  vctrs          0.6.5   2023-12-01 [?] CRAN (R 4.4.1)
 P  visNetwork     2.1.2   2022-09-29 [?] CRAN (R 4.4.1)
 P  withr          3.0.2   2024-10-28 [?] CRAN (R 4.4.1)
 P  xfun           0.50    2025-01-07 [?] CRAN (R 4.4.2)
 P  xtable         1.8-4   2019-04-21 [?] CRAN (R 4.4.1)
 P  yaml           2.3.10  2024-07-26 [?] CRAN (R 4.4.1)

 [1] C:/Users/corra/AppData/Local/R/cache/R/renv/library/repertor.io-f659809b/windows/R-4.4/x86_64-w64-mingw32
 [2] C:/Users/corra/AppData/Local/R/cache/R/renv/sandbox/windows/R-4.4/x86_64-w64-mingw32/6698a5f3

 * ── Packages attached to the search path.
 P ── Loaded and on-disk path mismatch.
 D ── DLL MD5 mismatch, broken installation.

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant