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

Docker 运行时,OPENAI_API_KEY环境变量无效 #265

Closed
zinohome opened this issue Mar 31, 2023 · 18 comments
Closed

Docker 运行时,OPENAI_API_KEY环境变量无效 #265

zinohome opened this issue Mar 31, 2023 · 18 comments
Labels
faq Most asked questions question Further information is requested

Comments

@zinohome
Copy link

docker 运行时,即使输入了OPENAI_API_KEY环境变量,在web端仍然提示需要输入OPENAI_API_KEY,如何解决?

@Yidadaa
Copy link
Collaborator

Yidadaa commented Mar 31, 2023

请提供执行的 docker 命令。

@Yidadaa Yidadaa added the question Further information is requested label Mar 31, 2023
@lialosiu
Copy link

我这里也可以确认这个问题

docker compose.yaml

services:
  chatgpt:
    image: yidadaa/chatgpt-next-web
    environment:
      - OPENAI_API_KEY="sk-****"
      - CODE="****"
    ports:
      - 8083:3000

exec进入docker容器中,env查看环境变量

/app # env
NODE_VERSION=18.15.0
HOSTNAME=522b836f3f18
YARN_VERSION=1.22.19
SHLVL=1
HOME=/root
OLDPWD=/app/public
OPENAI_API_KEY="sk-****"
TERM=xterm
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
CODE="****"
PWD=/app

环境变量本身是存在的,但是应用并没有读取到

@lialosiu
Copy link

Snipaste_2023-03-31_11-55-02

这是日志

@Yidadaa Yidadaa added the help wanted Extra attention is needed label Mar 31, 2023
@LancerComet
Copy link

我还没有更新最新版,但之前的版本是界面上提示受限,只要在界面填入 Code 就可以用了

@hugoyue
Copy link

hugoyue commented Mar 31, 2023

我这里也可以确认这个问题

docker compose.yaml

services:
  chatgpt:
    image: yidadaa/chatgpt-next-web
    environment:
      - OPENAI_API_KEY="sk-****"
      - CODE="****"
    ports:
      - 8083:3000

exec进入docker容器中,env查看环境变量

/app # env
NODE_VERSION=18.15.0
HOSTNAME=522b836f3f18
YARN_VERSION=1.22.19
SHLVL=1
HOME=/root
OLDPWD=/app/public
OPENAI_API_KEY="sk-****"
TERM=xterm
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
CODE="****"
PWD=/app

环境变量本身是存在的,但是应用并没有读取到

我刚测试了一下,使用 docker-compose 部署, docker-compose.yml 文件中需要把所有变量后面的 "" 双引号全部删除,只保留值,才可以。

@SparkleBo
Copy link

去掉双引号。。。

@zinohome
Copy link
Author

Docker 环境变量 |
CODE=******
OPENAI_API_KEY=sk-*******N
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
NODE_VERSION=18.15.0
YARN_VERSION=1.22.19
-- | --

日志:
docker logs chatgpt
Listening on port 3000 url: http://chatgpt:3000

容器内env:
/app # env
NODE_VERSION=18.15.0
HOSTNAME=chatgpt
YARN_VERSION=1.22.19
SHLVL=1
HOME=/root
OPENAI_API_KEY=sk-N
TERM=xterm
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
CODE=
**
PWD=/app

docker运行没问题,但是web应用无法获取OPENAI_API_KEY和CODE,仍然提示:“现在是未授权状态,请在设置页填写授权码。”

应该是node应用配置部分无法通过环境变量设置OPENAI_API_KEY和CODE

@hugoyue
Copy link

hugoyue commented Mar 31, 2023

开启一个新聊天试试

@lialosiu
Copy link

我这里也可以确认这个问题
docker compose.yaml

services:
  chatgpt:
    image: yidadaa/chatgpt-next-web
    environment:
      - OPENAI_API_KEY="sk-****"
      - CODE="****"
    ports:
      - 8083:3000

exec进入docker容器中,env查看环境变量

/app # env
NODE_VERSION=18.15.0
HOSTNAME=522b836f3f18
YARN_VERSION=1.22.19
SHLVL=1
HOME=/root
OLDPWD=/app/public
OPENAI_API_KEY="sk-****"
TERM=xterm
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
CODE="****"
PWD=/app

环境变量本身是存在的,但是应用并没有读取到

我刚测试了一下,使用 docker-compose 部署, docker-compose.yml 文件中需要把所有变量后面的 "" 双引号全部删除,只保留值,才可以。

确实,去掉双引号可以了

环境变量中不要双引号,提示 现在是未授权状态,请在设置页填写授权码。 然后设置界面填上CODE,APIKEY留空,回到聊天界面就正常了

@zinohome
Copy link
Author

环境变量中不要双引号,提示 现在是未授权状态,请在设置页填写授权码。 然后设置界面填上CODE,APIKEY留空,回到聊天界面就正常了

果真是,那么这个CODE的作用是web界面防止未授权访问使用的了? 这下方便了

@Kosette
Copy link
Contributor

Kosette commented Mar 31, 2023

compose file中的环境变量有两种写法,一种是dict,一种是array。

environment:
  key: "value"

或者

environment:
  - key=value

其中引号可以保证某些值被解释成字面量,很多时候也是不用加的,yaml的坑很多。

@wonsikin
Copy link

wonsikin commented Apr 2, 2023

某些值被解释成字面量,很多时候也是不用加的,yaml的坑很多。

用第一种模式搞定这个问题。我实在 树莓派上跑docker的

@hqwuzhaoyi
Copy link

#570
I added default values in the setting and get them from env

@Yidadaa Yidadaa closed this as completed Apr 6, 2023
@hqzh
Copy link

hqzh commented May 4, 2023

去掉双引号还是没有设置进去

@Yidadaa
Copy link
Collaborator

Yidadaa commented Jun 23, 2023

收集至 #2105

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Collected to #2105

@flyou
Copy link

flyou commented Nov 6, 2023

真垃圾啊,这就关了

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


That's rubbish, shut it down now

ryiann pushed a commit to ryiann/ChatGPT that referenced this issue Feb 19, 2024
- [+] feat(chat.tsx): add TODO comment about fixing UNFINISHED_INPUT overwriting issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
faq Most asked questions question Further information is requested
Projects
None yet
Development

No branches or pull requests