Returns character(0) when querying too quickly (e.g. in a loop)
dohdoubleg opened this issue · 4 comments
When calling ask_chatgpt
in a for
loop, I get maybe 3 returns with answers, but after that it will return "character(0)" which just seems to be a null character object. When this occurs in the loop, it stops operation with an error about "...replacement has length 0."
I used this workaround, which was effective for my use: insert sys.sleep(x)
into the loop, where x is a number of seconds to temporarily suspend operation. 5 wasn't enough and 15 worked, but it appears as if more complex queries and/or higher numbers of loop iterations requires higher times; I had to move to 20 to get a loop to run 121 times.
I'm not sure what's causing the null response and this workaround suits me fine, but would be interested to learn why it occurs in case faster loops are possible.
Hi @dohdoubleg , thanks for finding and submitting this issue.
Unfortunately, I am not being able to reproduce your bug. Would you provide me with a reproducible example? Probably my testing example is too simple for ChatGPT to solve (gpt_replies <- lapply(1:10, function(i) chatgpt::ask_chatgpt(paste0(i, " ** ", i)))
.
Also, which version of the package are you using?
Thanks!
I'm getting character(0)
on my first query as well, without looping. I tried re-installing the latest from Github but no luck.
chatgpt::ask_chatgpt(question = "What is 2+2?")
Here's my sessionInfo()
> sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.5.1
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] chatgpt_0.2.3
loaded via a namespace (and not attached):
[1] Rcpp_1.0.10 rstudioapi_0.14 magrittr_2.0.3 xtable_1.8-4
[5] R6_2.5.1 rlang_1.1.1 fastmap_1.1.1 httr_1.4.5
[9] tools_4.1.1 pkgbuild_1.3.1 miniUI_0.1.1.1 cli_3.6.1
[13] withr_2.5.0 htmltools_0.5.5 ellipsis_0.3.2 remotes_2.4.2
[17] rprojroot_2.0.3 digest_0.6.31 lifecycle_1.0.3 crayon_1.5.2
[21] processx_3.8.0 shiny_1.7.4 callr_3.7.3 later_1.3.1
[25] promises_1.2.0.1 ps_1.7.2 curl_5.0.0 mime_0.12
[29] compiler_4.1.1 prettyunits_1.1.1 jsonlite_1.8.4 httpuv_1.6.9
Once I upgraded to the dev branch I got an error message about billing. Added a credit card and used a new secret key but still getting this message. Any ideas?
Error in gpt_get_completions(question, messages = chat_session_messages) :
list(message = "You exceeded your current quota, please check your plan and billing details.", type = "insufficient_quota", param = NULL, code = NULL)
Hi @dohdoubleg , thanks for finding and submitting this issue.
Unfortunately, I am not being able to reproduce your bug. Would you provide me with a reproducible example? Probably my testing example is too simple for ChatGPT to solve (
gpt_replies <- lapply(1:10, function(i) chatgpt::ask_chatgpt(paste0(i, " ** ", i)))
. Also, which version of the package are you using? Thanks!
Thank you. I believe this may have been an error on my side. Early on, I was using code from RBloggers to run CGPT: https://www.r-bloggers.com/2023/03/call-chatgpt-or-really-any-other-api-from-r/
That defines a function ask_chatgpt. I later installed and thought I was using your package, but I think I was actually calling that first function. I was also using my free credits, and now I'm on a paid account.
In any case, your code works nicely and I no longer get that error when testing. If something occurs during longer loops, I'll update, but I think this can be closed. Thank you!