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,感谢! image

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

Most upvoted comments

hi, I deploy it with Netlify: Reproduction:

  1. fork the repository to my own
  2. open the https://app.netlify.com/start and import my GitHub account
  3. intall the netlify for my all repositories
  4. select the [chatgpt-demo] and all selection is default
  5. click the “show advanced” and select “New variables” then input “OPENAI_API_KEY“ and the key-value
  6. click ”Deploy site“
  7. test still failed:
  8. even delete my own repository many times,it doesn’t help

@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.

ScreenShot 2023-03-22 at 21 39 08@2x

你好@yzh990918: 我提交了一个pull request应该可以解决这个问题。您可以在此处找到 PR 。请看一看,如果还有什么我可以帮忙的,请告诉我。我很乐意做出任何必要的更改以尽快将其合并。 PS:遇到这个问题的可以暂时把容器镜像换成fightingsj/chatgpt-demo:container-fix. Docker 运行命令应该是这样的:docker run --name=chatgpt-demo -e OPENAI_API_KEY=YOUR_OPEN_API_KEY -p 3000:3000 -d fightingsj/chatgpt-demo:container-fix

这个修改会导致本地报错,上面说了。Astro 不支持process.env.

你好@yzh990918dist,我找到了另一种方法来解决这个问题,在应用启动前根据环境变量动态替换里面的文件内容,详见这个PR 。 PS:遇到这个问题的可以暂时把容器镜像换成fightingsj/chatgpt-demo:container-fix-v2. Docker 运行命令应该是这样的:docker run --name=chatgpt-demo -e OPENAI_API_KEY=YOUR_OPEN_API_KEY -p 3000:3000 -d fightingsj/chatgpt-demo:container-fix-v2

@yzh990918 : 我已经提交了一个pull request,应该可以解决这个问题。你可以找到PR 这里.请看一下,如果还有什么我能帮忙的,请告诉我。我很乐意做任何必要的修改,以尽快合并。 PS:遇到这个问题的人可以暂时用fightingsj/chatgpt-demo:container-fix替换容器镜像。 Docker run命令应该像这样:docker run --name=chatgpt-demo -e OPENAI_API_KEY=YOUR_OPEN_API_KEY -p 3000:3000 -d fightingsj/chatgpt-demo:container-fix

如上所述,此修改将导致本地错误。Astro不支持process.env的语法。

嗨@yzh990918 ,我找到了另一个解决这个问题的方法,在应用启动前根据环境变量动态替换dist中的文件内容,看到这个 PR 了解详情。 PS: 遇到此问题的任何人都可以暂时将容器映像替换为fightingsj/chatgpt-demo:container-fix-v2。 Docker run命令应该像这样: docker run --name=chatgpt-demo -e OPENAI_API_KEY=YOUR_OPEN_API_KEY -p 3000:3000 -d fightingsj/chatgpt-demo:container-fix-v2

但是 env “SITE_PASSWORD” 变量仍然没有生效。

我已经测试过了,它是支持的。-e可以在 docker run 命令中多次使用,声明多个环境变量。 Docker 运行命令应该是这样的: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

你好,我运行了这个docker命令 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 到这一步有个warning报错 Status: Downloaded newer image for fightingsj/chatgpt-demo:container-fix-v2 WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested 然后status一直是Exited (1) ,运行 docker run chatgpt-demo也无法启动 服务器是oralce cloud的免费服务器 arm的处理器 系统环境:Ubuntu 20.04.5 LTS 对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已经正常运行了

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

This modification will cause an error locally, as mentioned above. Astro not support the syntax of process.env.

Hi @yzh990918 ,I found another way to solve this problem, dynamically replace the file content in dist according to the environment variable before the application starts, see this PR for details. PS: Anyone who encounters this problem can temporarily replace the container image with fightingsj/chatgpt-demo:container-fix-v2. 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-v2

@yzh990918 : 我已经提交了一个pull request,应该可以解决这个问题。你可以找到PR 这里.请看一下,如果还有什么我能帮忙的,请告诉我。我很乐意做任何必要的修改,以尽快合并。 PS:遇到这个问题的人可以暂时用fightingsj/chatgpt-demo:container-fix替换容器镜像。 Docker run命令应该像这样:docker run --name=chatgpt-demo -e OPENAI_API_KEY=YOUR_OPEN_API_KEY -p 3000:3000 -d fightingsj/chatgpt-demo:container-fix

如上所述,此修改将导致本地错误。Astro不支持process.env的语法。

@yzh990918 ,我找到了另一个解决这个问题的方法,在应用启动前根据环境变量动态替换dist中的文件内容,看到这个 PR 了解详情。 PS: 遇到此问题的任何人都可以暂时将容器映像替换为fightingsj/chatgpt-demo:container-fix-v2。 Docker run命令应该像这样: docker run --name=chatgpt-demo -e OPENAI_API_KEY=YOUR_OPEN_API_KEY -p 3000:3000 -d fightingsj/chatgpt-demo:container-fix-v2

But the env “SITE_PASSWORD” variable still doesn’t take effect.

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

@mufanGuo @kingsh2012 Try https://github.com/ddiu8081/chatgpt-demo#deploy-with-docker @yzh990918 I tried, but when I pull image through this link https://hub.docker.com/r/ddiu8081/chatgpt-demo, it error not found. image

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. image

@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 就可以生效了