chatgpt-demo: invalid_api_key Incorrect API key provided: undefined.
Describe the bug
我根据md描述,依照Netlify和docker都搭建了应用,但是应用内报了以下错误: invalid_api_key Incorrect API key provided: undefined. You can find your API key at https://platform.openai.com/account/api-keys. 希望作者可以出一个更加详细的教程 可以解决这些问题,尤其是根据docker,感谢!
Reproduction
key undefined
System Info
deploy machine:centos7
deploy Docker and Netlify
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guide.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
- The provided reproduction is a minimal reproducible of the bug.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 42 (16 by maintainers)
Commits related to this issue
- fix: remove .* files from dockerignore, fix #297 — committed to amrice/chatgpt-demo by yzh990918 a year ago
@coo1kid1412 I reproduced the problem using your steps. You can temporarily try to trigger deploy manually in the netlify ui. Then it will get your environment variables.
@mufanGuo @kingsh2012 Try https://github.com/ddiu8081/chatgpt-demo#deploy-with-docker
我在reddit上找到了解决方法 执行
docker run --privileged --rm tonistiigi/binfmt --install all
命令后再执行docker run --name=chatgpt-demo -e OPENAI_API_KEY=YOUR_OPEN_API_KEY -e SITE_PASSWORD=YOUR_SITE_PASSWORD -p 3000:3000 -d fightingsj/chatgpt-demo:container-fix-v2
现在AI已经正常运行了I’ve tested it, and it’s supportive.
-e
can be used multiple times in docker run command to declare multiple environment variables.Docker run command should be like:
docker run --name=chatgpt-demo -e OPENAI_API_KEY=YOUR_OPEN_API_KEY -e SITE_PASSWORD=YOUR_SITE_PASSWORD -p 3000:3000 -d fightingsj/chatgpt-demo:container-fix-v2
Hi @yzh990918 :
I’ve submitted a pull request that should fix this issue. You can find the PR here. Please take a look and let me know if there’s anything else I can do to help. I’d be happy to make any necessary changes to get this merged as soon as possible.
PS: Anyone who encounters this problem can temporarily replace the container image with
fightingsj/chatgpt-demo:container-fix
.Docker run command should be like:
docker run --name=chatgpt-demo -e OPENAI_API_KEY=YOUR_OPEN_API_KEY -p 3000:3000 -d fightingsj/chatgpt-demo:container-fix
So, I pulled the image through the command on this link again:https://github.com/ddiu8081/chatgpt-demo/pkgs/container/chatgpt-demo , succeed! In addition, the “- d” background execution parameter was not added to the Direct run command in the .md document.
@ddiu8081 直接拉去你的镜像确实有这样的问题 docker pull ghcr.io/ddiu8081/chatgpt-demo:main。 能不能将 读取变量的地方新建一个读取系统环境变量? import.meta.env.OPENAI_API_KEY 这种方式在docker中读不到环境变量 希望能够将/src/pages/api/generate.ts文件 读取变量改成以下形式 const apiKey = process.env.OPENAI_API_KEY || import.meta.env.OPENAI_API_KEY 这样 docker run -e OPENAI_API_KEY=xxx -p 3000:3000 ghcr.io/ddiu8081/chatgpt-demo:main 就可以生效了