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

OPENAI_API_KEY configuration error: Issues during GitHub Action execution #67

Open
HyoJeong1019 opened this issue Apr 9, 2023 · 11 comments

Comments

@HyoJeong1019
Copy link

I have a problem with OPENAI_API_KEY not being recognized.

Screenshot 2023-04-10 at 00 30 56

  • In the first attempt, I set the OPENAI_API_KEY variable in the Variables tab. The GitHub Action runs, but OPENAI_API_KEY is empty, and the error message says it cannot be found.
    Screenshot 2023-04-10 at 00 31 39

  • In the second attempt, I set up the YAML file like this and pushed it, but OPENAI_API_KEY is still empty.

  • Despite setting up the OPENAI_API_KEY in Actions secrets and variables, you are still encountering an issue where the OPENAI_API_KEY value is not being recognized.

name: Code Review

permissions:
  contents: read
  pull-requests: write

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: anc95/ChatGPT-CodeReview@main
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

Screenshot 2023-04-10 at 00 50 09

Screenshot 2023-04-10 at 00 33 36

Please tell me how to solve the problem.🥲

@anc95
Copy link
Owner

anc95 commented Apr 10, 2023

@julian-jeong is your pull request from one forked repo to the main repo?

@HyoJeong1019
Copy link
Author

@anc95 This is pull request for the "a branch" that originated from the "main branch". Please refer to the attached image.

Screenshot 2023-04-10 at 12 25 44

@anc95
Copy link
Owner

anc95 commented Apr 10, 2023

@julian-jeong Your setup should be fine, I suggest creating a simple GitHub action demo to test it out, such as https://docs.github.com/en/actions/security-guides/encrypted-secrets#example-using-bash.

@XiaoRIGE
Copy link

Have you solved this problem? I seem to have encountered the same situation

@anc95
Copy link
Owner

anc95 commented Apr 23, 2023

@XiaoRIGE It may not be a code bug, but rather some restrictions on the use of GitHub secrets. I am unable to reproduce it, so at the moment I have no idea how to assist with this.

@mralexandernickel
Copy link

@anc95 it looks like here is the problem:

'GET /repos/{owner}/{repo}/actions/variables/{name}',

🔝 this code is executed even though it seems to be not needed. when this variable is added inside the repository, then the error is gone... no matter which value the variable has (does not need to be an api key)

@anc95
Copy link
Owner

anc95 commented Apr 27, 2023

@mralexandernickel

if (process.env.OPENAI_API_KEY) {
return new Chat(process.env.OPENAI_API_KEY);
}
const repo = context.repo();
try {
const { data } = (await context.octokit.request(
'GET /repos/{owner}/{repo}/actions/variables/{name}',
{

If OPEN_API_KEY is properly set, the code should go into the first if statement. However, it seems that the secret was not successfully injected to the environment when running the GitHub action. This has resulted in falling back to querying the OPENAI_API_KEY in the variable. Setting the key in the variable when using GitHub action integration is not recommended. This is because GitHub displays the variable in the action running log, which compromises security.

@mralexandernickel
Copy link

@anc95 yeah i have seen that, but the interesting part is, that our OPENAI_API_KEY in fact is set up correctly, and we also get responses/comments from chatgpt in our pul requests afterwards. 🤷

so in fact "it is working", but we get that strange comment that the variable is not set. for us we have set up the OPENAI_API_KEY as an organization secret, even though I can not see a reason why that should be a problem...escpecially since it is working. really strange. 🤔

@mralexandernickel
Copy link

@anc95

This could also be a hint to the problem:

the comment about "api key variable not set up" seem to be created via default GITHUB_TOKEN (commet is made by user "cr-gpt"), even though we have added a PAT in the yaml to be used. and the comment after that, with the response coming from chatgpt is then made by using the PAT we have set via yaml. maybe that information could be helping...

@anc95
Copy link
Owner

anc95 commented Apr 27, 2023

@mralexandernickel it seems that you setup both GitHub action and GitHub app integrations. The warning comment is sent by GitHub app. So try to remove the GitHub app from your repo to see if it will be no warning in comment.

@mralexandernickel
Copy link

@anc95

🤦 exactly that has been the problem, thank you very much! I have removed the github app from our organization and instead only use the github action. now we got the behaviour we'd like to have 😊

sorry for my misunderstanding of setting up the integration, and thank you for your support and great work here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants