rubberduck-ai / rubberduck-vscode

Use AI-powered code edits, explanations, code generation, error diagnosis, and chat in Visual Studio Code with the official OpenAI API.
https://marketplace.visualstudio.com/items?itemName=Rubberduck.rubberduck-vscode
MIT License
579 stars 70 forks source link

Getting "Error: Unknown error calling OpenAI API (status=undefined)" #86

Open liorchamla opened 1 year ago

liorchamla commented 1 year ago

Just after installation, it is impossible to chat with OpenAI

I just installed the extension on my VSCode (see specifications below), added my OpenAI Api Key and tried to start a conversation, many times, and failed each time.

How to reproduce

Install the extension on this VSCode environment :

Version: 1.76.2
Commit: ee2b180d582a7f601fa6ecfdad8d9fd269ab1884
Date: 2023-03-14T17:54:09.061Z
Electron: 19.1.11
Chromium: 102.0.5005.196
Node.js: 16.14.2
V8: 10.2.154.26-electron.0
OS: Darwin x64 22.3.0
Sandboxed: No

Add OpenAI API key and start a new conversation, and you get this error : `Error: Unknown error calling OpenAI API (status=undefined)``

The Rubberduck Logs shows :

[INFO] --- Start OpenAI prompt ---
[INFO] [{"role":"user","content":"## Instructions\nContinue the conversation below.\nPay special attention to the current developer request.\n\n## Current Request\nDeveloper: How do you manage dates in python ?\n\n## Selected Code\n```\n$userModes = [];\n        if (isset($bodyRequest['modes'])) {\n            $userModes = $bodyRequest['modes'];\n            unset($bodyRequest['modes']);\n        }\n```\n\n## Conversation\nDeveloper: How do you manage dates in python ?\n\n## Task\nWrite a response that continues the conversation.\nStay focused on current developer request.\nConsider the possibility that there might not be a solution.\nAsk for clarification if the message does not make sense or more input is needed.\nUse the style of a documentation article.\nOmit any links.\nInclude code snippets (using Markdown) and examples where appropriate.\n\n## Response\nBot:"}]
[INFO] --- End OpenAI prompt ---
[ERROR] Something went wrong with OpenAI
[ERROR] Unknown error calling OpenAI API (status=undefined)

Expected behavior

We should have a generated answer

Screenshots

Capture d’écran 2023-03-30 à 20 46 57

Additional information

lgrammel commented 1 year ago

This could potentially be a firewall or connectivity issue.

Can you try calling the open ai api with curl to check that the connection works?

E.g. with their example:

curl https://api.openai.com/v1/completions \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -d '{
  "model": "text-davinci-003",
  "prompt": "Say this is a test",
  "max_tokens": 7,
  "temperature": 0
}'
liorchamla commented 1 year ago

It works fine using cURL :'(

jmccreight commented 1 year ago

i have the same but when I select chatGPT4. the curl works fine for me

Hajibey commented 1 year ago

Has anyone found out how to solve this? I suspect it may have something to do with changing API keys? Have any of you changed the API key and then stumbled upon this?

jjaimealeman commented 1 year ago

SOLVED

I too, had this issue.

In my settings.json I previously had "rubberduck.model": "gpt-4".

image


Setting it to "rubberduck.model": "gpt-3.5-turbo", solved the issue.

image


Testing 6 times, three with each model and it failed every time I used gpt-4 😥

To confirm the accuracy of the code, I pasted it into a Quokka JavaScript file and it indeed is accurate 😃

image


SIDENOTE TO THE DEVELOPERS!

It would be nice to have a 'Copy Code' button, in addition to the 'Export Conversation' 👍

I am enjoying this new VS Code extension! Well done!