JamesHWade / gpttools

gpttools extends gptstudio for package development to help you document code, write tests, or even explain code
https://jameshwade.github.io/gpttools/
Other
291 stars 27 forks source link

Use proxy to access openai for Chinese users? #52

Closed kun-ecology closed 5 months ago

kun-ecology commented 10 months ago

As a Chinese user, I came across this error when using gpttools: ! Timeout was reached: [api.openai.com] Resolving timed out after 10012 milliseconds

I guess it is due to the proxy. I am using Clash and I tried to add the local proxy in .Renviron file following this, but it still gives me the error.

Thanks in advance and looking forward to your reply!

Best regards Kun Guo

JamesHWade commented 10 months ago

Over in gptstudio, it was solved by allowing a different URL in place of the default openai url. Would that be an option for you?

kun-ecology commented 10 months ago

Thanks so much for your reply.

I guess you are referring to these two issues:

However, I did not manage to fix it with them.

Nevertheless, I followed this post accessing github from behind corporate proxy - RStudio IDE - Posit Community and it works now!

The key is to run the following code:

Sys.setenv(http_proxy="http://your_proxy_ip:your_proxy_port")
Sys.setenv(http_proxy_user="http://your_proxy_ip:your_proxy_port")
Sys.setenv(https_proxy="http://your_proxy_ip:your_proxy_port")
Sys.setenv(https_proxy_user="http://your_proxy_ip:your_proxy_port")

I add these codes to the .Rprofile.site file, so I do not need to rerun them for every project.

Perhaps this is not an elegant way to establish the connection via proxy, but it works and I hope it is useful for anyone who comes across the same problem.

Best Kun

JamesHWade commented 5 months ago

@kun-ecology, it looks like you were able to solve the issue, but please reopen if it is not working.

Sorry for the very delayed reply. I've been out on parental leave.