chatgpt-web icon indicating copy to clipboard operation
chatgpt-web copied to clipboard

小白询问api部署问题

Open Wallace00V opened this issue 1 year ago • 12 comments

我是小白. 本地服务器已经能直接访问chatgpi网页(用clashx),现在打算用api方式,找到了这个项目. 我尝试用docker部署,命令为:docker run --name chatgpt-web -d -p 127.0.0.1:3002:3002 --env OPENAI_API_KEY=your_api_key chatgpt-web, 运行localhost:3002发现报错了

Wallace00V avatar Apr 25 '23 03:04 Wallace00V

@Wallace00V

你没有使用http/socks5代理,一般是不成功的。 clash的本地代理地址默认是http://127.0.0.1:7890

你可以加上: --env HTTPS_PROXY=http://127.0.0.1:7890 试试看。

huangwb8 avatar Apr 25 '23 05:04 huangwb8

127.0.0.1 删掉 , 改成-p 3002:3002。 你127.0.0.1,只有docker容器内部才能访问了,宿主机不能访问到docker容器内的127.0.0.1

如果你只想让宿主机访问,不想让公网访问,可以监听 172.x.x.x:3002, 这样只有宿主机能访问。

访问的时候也不应该用 localhost,而是用容器的局域网地址 172.x.x.x:3002 来访问

lhbdhr avatar Apr 25 '23 06:04 lhbdhr

@Wallace00V

你没有使用http/socks5代理,一般是不成功的。 clash的本地代理地址默认是http://127.0.0.1:7890

你可以加上: --env HTTPS_PROXY=http://127.0.0.1:7890 试试看。

按你说的加了后,报错:request to https://api.openai.com/v1/chat/completions failed, reason: connect ECONNREFUSED 127.0.0.1:7890

Wallace00V avatar Apr 25 '23 12:04 Wallace00V

127.0.0.1 删掉 , 改成-p 3002:3002。 你127.0.0.1,只有docker容器内部才能访问了,宿主机不能访问到docker容器内的127.0.0.1

如果你只想让宿主机访问,不想让公网访问,可以监听 172.x.x.x:3002, 这样只有宿主机能访问。

访问的时候也不应该用 localhost,而是用容器的局域网地址 172.x.x.x:3002 来访问 172.x.x.x:3002这个具体是多少呢

Wallace00V avatar Apr 25 '23 12:04 Wallace00V

docker 容器的IP是自行分配的,需要你自行查看。 执行下边儿的命令就能知道docker容器的IP了。

#  查看所有网络设置
docker network ls
#  某个网络的详细情况,比如 chatgpt_default  根据你第一步ls 出的结果来填xxxx
docker network inspect  xxxxx

比如docker容器分配的ip是 172.21.0.2,http://172.21.0.2:3002 就能从宿主机访问docker内架设的网站了

lhbdhr avatar Apr 25 '23 12:04 lhbdhr

127.0.0.1,只有docker容器内部才能访问了,宿主机不能访问到docker容器内的127.0.0.1

启动方式为:docker run --name chatgpt-web -d -p 172.17.0.2:3002:3002 --env OPENAI_API_KEY=your_api_key --env HTTPS_PROXY=http://127.0.0.1:7890 chenzhaoyu94/chatgpt-web

报错了: docker: Error response from daemon: driver failed programming external connectivity on endpoint chatgpt-web (de14526b630febdf30d33d5b898cf51eac94e39df53dfbba99cbbbf2a8de3e3d): Error starting userland proxy: listen tcp 172.17.0.2:3002: bind: cannot assign requested address

Wallace00V avatar Apr 25 '23 13:04 Wallace00V

运行时不用指定IP啊,-p 3002:3002运行起来之后,通过 我给你的指令,查看容器IP 然后通过容器IP访问

lhbdhr avatar Apr 25 '23 13:04 lhbdhr

另外你是在国内的机器上部署的?国外的机器不需要加--env HTTPS_PROXY=http://127.0.0.1:7890/ 如果是中国的机器,你这样加也是不对的,如果要加代理自行研究,据我了解很复杂,我没试过。 不推荐你在中国大陆的机器上运行。

lhbdhr avatar Apr 25 '23 13:04 lhbdhr

@Wallace00V

要不你试试另外一个类似的项目——Kerwin1202/chatgpt-web吧,我写过教程,基本上是可以成功的: Docker系列 基于OpenAI API和Access Token自建ChatGPT

主要是不知道你的实际环境,很难推测你失败的真正原因。

huangwb8 avatar Apr 25 '23 13:04 huangwb8

另外你是在国内的机器上部署的?国外的机器不需要加--env HTTPS_PROXY=http://127.0.0.1:7890/ 如果是中国的机器,你这样加也是不对的,如果要加代理自行研究,据我了解很复杂,我没试过。 不推荐你在中国大陆的机器上运行。

-p 3002:3002 --env HTTPS_PROXY=http://127.0.0.1:7890/ 运行起来后,用容器IP:3002方式打不开网页(查看了容器IP,浏览器输入172.17.0.2:3002)

我是国内的机器,已经用clashx能访问chatgpt网页了,这个尝试是希望让docker服务通过本地代理服务器来搭建chatgpt-web

Wallace00V avatar Apr 25 '23 13:04 Wallace00V

国内的机器会很复杂,你试试去掉那串指令,试试能不能打开网页, 如果能打开的话,接下来研究怎么让docker容器使用宿主机的socks或http代理服务。

lhbdhr avatar Apr 25 '23 13:04 lhbdhr

国内使用为啥不用api proxy? 不需要设置魔法上网。 https://github.com/easychen/openai-api-proxy/ 只要支持设置API_BASE_URL的项目都可以用,或者直接用客户端chatbox, 参考:https://mp.weixin.qq.com/s/u8YGaXgJZuLRA-HflGHT8g

jasontips avatar Apr 26 '23 06:04 jasontips

This issue is stale because it has been open for 10 days with no activity.

github-actions[bot] avatar Jun 02 '23 02:06 github-actions[bot]

另外你是在国内的机器上部署的?国外的机器不需要加--env HTTPS_PROXY=http://127.0.0.1:7890/ 如果是中国的机器,你这样加也是不对的,如果要加代理自行研究,据我了解很复杂,我没试过。 不推荐你在中国大陆的机器上运行。

-p 3002:3002 --env HTTPS_PROXY=http://127.0.0.1:7890/ 运行起来后,用容器IP:3002方式打不开网页(查看了容器IP,浏览器输入172.17.0.2:3002)

我是国内的机器,已经用clashx能访问chatgpt网页了,这个尝试是希望让docker服务通过本地代理服务器来搭建chatgpt-web

docker run --net host --name chatgpt-web -p 3002:3002 --env OPENAI_API_KEY=sk-xxxxxxx --env HTTPS_PROXY=http://127.0.0.1:7890/ -d chenzhaoyu94/chatgpt-web --net host 主机模式直接让容器使用宿主机的网络

Hcx-2008 avatar Jun 03 '23 05:06 Hcx-2008

This issue is stale because it has been open for 10 days with no activity.

github-actions[bot] avatar Jun 16 '23 01:06 github-actions[bot]

This issue was closed because it has been inactive for 2 days since being marked as stale.

github-actions[bot] avatar Jun 18 '23 02:06 github-actions[bot]