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

Bug: Cannot read properties of undefined (reading '0') #5

Closed
graup opened this issue Feb 14, 2023 · 8 comments
Closed

Bug: Cannot read properties of undefined (reading '0') #5

graup opened this issue Feb 14, 2023 · 8 comments

Comments

@graup
Copy link

graup commented Feb 14, 2023

Getting this error. (I have added a new API key from https://platform.openai.com/account/api-keys to my env.)

aicommits
▲ Welcome to AICommits!
▲ Generating your AI commit message...

/Users/graup/.nvm/versions/node/v18.13.0/lib/node_modules/aicommits/bin/aicommits.js:98
        const aiCommit = json.choices[0].text;
                                     ^

TypeError: Cannot read properties of undefined (reading '0')
    at /Users/graup/.nvm/versions/node/v18.13.0/lib/node_modules/aicommits/bin/aicommits.js:98:38
    at Generator.next (<anonymous>)
    at fulfilled (/Users/graup/.nvm/versions/node/v18.13.0/lib/node_modules/aicommits/bin/aicommits.js:6:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.13.0
@Nutlope
Copy link
Owner

Nutlope commented Feb 14, 2023

Hey @graup, thanks for opening this issue! This error typically happens when you don't have the correct value for the OpenAI env variable. I recommend you do a printenv OPENAI_API_KEY to see what value you have it set to and verify that it matches an API key that's on your OpenAI API dashboard that you linked.

The API key should have no whitespaces and should be in the shape of sk-xxxxxxxxxxxxxxx. Could you verify you have the correct value for the env variable, open a brand new terminal, try it out again, then let me know if the problem is still there?

@graup
Copy link
Author

graup commented Feb 14, 2023

Thanks for your reply! I tried that, same problem. If you have no idea, I'll try checking out your repo and digging into the API response.

@Nutlope
Copy link
Owner

Nutlope commented Feb 14, 2023

@graup I may try to add a debugging flag to the CLI soon that shows detailed console messages so folks can debug in situations like this. In the meantime, mind trying one more thing for me?

I have a feeling it may be extra whitespace so could you do a unset OPENAI_API_KEY to remove the env var, go directly to your .zshrc by going to your root cd ~ then code .zshrc to open it up, and add export OPENAI_API_KEY="sk---" to the .zshrc somewhere.

After all of that, open up a fresh terminal and try it one more time. If it works, then it was whitespace and I should just trim extra whitespace.

@iamshabell
Copy link
Contributor

Hi, I understand that you're facing the same issue that I did before. But I was able to fix it by simply restarting my terminal. Sometimes, when the terminal has been running for a while, it can start to experience some glitches or issues with its processes. So, try restarting your terminal and see if that resolves the problem for you too.

@ivorpad
Copy link

ivorpad commented Feb 14, 2023

@Nutlope The error appears to be insufficient_quota. I had to console.log the json response from const json = yield response.json(); and got this:

{
  json: {
    error: {
      message: 'You exceeded your current quota, please check your plan and billing details.',
      type: 'insufficient_quota',
      param: null,
      code: null
    }
  }
}

But you need to handle this (or any other) error(s).

Stack trace:

/usr/local/lib/node_modules/aicommits/bin/aicommits.js:99
        const aiCommit = json.choices[0].text;
                                     ^

TypeError: Cannot read properties of undefined (reading '0')
    at /usr/local/lib/node_modules/aicommits/bin/aicommits.js:99:38
    at Generator.next (<anonymous>)
    at fulfilled (/usr/local/lib/node_modules/aicommits/bin/aicommits.js:6:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

I tried with another OpenAI account where I have billing setup and got a server_error

{
  json: {
    error: {
      message: 'The server had an error while processing your request. Sorry about that!',
      type: 'server_error',
      param: null,
      code: null
    }
  }
}

I tried several times until I got a successful response, so it could be the OpenAI API having issues right now.

@alexduros
Copy link

In my case, I had to set up a payment method in my OpenAI account, and regenerate an new API Key. It worked right after.

@privatenumber
Copy link
Collaborator

The latest release should log the specific error from OpenAI

@kejianlin
Copy link

kejianlin commented Aug 30, 2023

OCO_OPENAI_BASE_PATH=https://api.aikey.one/v1,
Add /v1 after the API.
Source code:

...
createChatCompletion: (createChatCompletionRequest, options = {}) => __awaiter(this, void 0, void 0, function* () {
          const localVarPath = `/chat/completions`;
          const localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
        }),
...

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

7 participants