Closed cqlzliang closed 1 year ago
thanks @cqlzliang! just so I understand, what use case does this solve for? and should we add a note in the README about when and how to use this?
✖ Request to OpenAI failed with status 400:
"<html>\r\n<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>\r\n<body>\r\n<center><h1>400 Bad Request</h1></center>\r\n<center>The plain HTTP request was sent to HTTPS port</center>\r\n<hr><center>cloudflare</center>\r\n</body>\r\n</html>\r\n"
An error happens when I use a local proxy with v2ray client.
I try this PR can resolve this error. But, I don't understand why?
Because ai-shell worked fine when I used ClashX as my proxy without this PR.
Due to well-known reasons, accessing api.openai.com from mainland China requires the use of a proxy. The common way to set a proxy in a shell environment is to set the http_proxy and https_proxy environment variables. My modification is to support network requests using these two environment variables as the network proxy. Actually, the latest version of axios already supports this feature, but the lower version of axios that openai package depends on does not.
As I mentioned above, setting a network proxy through http_proxy and https_proxy is a common practice, so I think no additional explanation is needed. However, if there is any, it would be better.
@saltbo Are sure ai-shell will use the system proxy when you used ClashX?I use clashxpro on mac and setting it as system proxy, and ai-shell doesn't use proxy when reqeust api.openai.com
@saltbo Are sure ai-shell will use the system proxy when you used ClashX?I use clashxpro on mac and setting it as system proxy, and ai-shell doesn't use proxy when reqeust api.openai.com
I'm not using the system proxy, I set the env http_proxy and https_proxy as below:
# proxy
PROXY_ADDR="http://docker.for.mac.localhost:6666"
export http_proxy=$PROXY_ADDR
export https_proxy=$PROXY_ADDR
export all_proxy=$PROXY_ADDR
export no_proxy="localtest.rs,localtest.me,localtest,localhost,127.0.0.1"
@saltbo I tried your setting, and ai-shell used the proxy setting. So the issue is my proxy setting, ai-shell support the proxy setting without this PR. For the error happens when you use a local proxy with v2ray client, you can submmit another issue.
@steve8708 I'm so sorry for my mistake, I wiil close this PR.
@saltbo I tried your setting, and ai-shell used the proxy setting. So the issue is my proxy setting, ai-shell support the proxy setting without this PR. For the error happens when you use a local proxy with v2ray client, you can submmit another issue.
@steve8708 I'm so sorry for my mistake, I wiil close this PR.
I don't understand what happens with the v2ray client, Please tell me if anyone knows something...
I found this issue, but I don't know why closed. https://github.com/axios/axios/issues/3384
The errors happen with https_proxy=http://example.com
I debug in the v2ray-client, and I found axios used the plain HTTP request, and the curl used CONNECT tunnel
The curl works fine, I prefer to think it's axios's problem.
As for the fact that Clash can work properly, I guess it may have done some special treatment.
there is a solution proposed here: https://github.com/openai/openai-node/issues/85#issuecomment-1454359657
I found this issue, but I don't know why closed. axios/axios#3384
The errors happen with
https_proxy=http://example.com
I debug in the v2ray-client, and I found axios used the plain HTTP request, and the curl used CONNECT tunnel
The curl works fine, I prefer to think it's axios's problem.
I have reproduced this problem, but I have not yet identified the root cause of the problem.
@saltbo Are sure ai-shell will use the system proxy when you used ClashX?I use clashxpro on mac and setting it as system proxy, and ai-shell doesn't use proxy when reqeust api.openai.com
I'm not using the system proxy, I set the env http_proxy and https_proxy as below:
# proxy PROXY_ADDR="http://docker.for.mac.localhost:6666" export http_proxy=$PROXY_ADDR export https_proxy=$PROXY_ADDR export all_proxy=$PROXY_ADDR export no_proxy="localtest.rs,localtest.me,localtest,localhost,127.0.0.1"
I got this error when i use this setting:
┌ AI Shell
│
◐ Loading.
✖ Request to OpenAI failed with status 403:
{
"error": {
"message": "The OpenAI API can only be accessed over HTTPS. You should access https://api.openai.com rather than the current URL.",
"type": "invalid_request_error"
}
}
@JaysonAlbert same as me. are you using v2ray-client too?
Support handle proxy settings for http requests.