devchat-ai / devchat

Automate your dev tasks with AI-powered scripts, from your IDE's chat panel.
https://www.devchat.ai
Apache License 2.0
342 stars 39 forks source link

Trim white spaces in KEY to prevent misleading 'APIConnectionError' #265

Closed yangbobo2021 closed 7 months ago

yangbobo2021 commented 7 months ago

Issue Description

When a KEY contains spaces, it triggers a h11._util.LocalProtocolError: Illegal header value error. The openai library, in handling this exception, rethrows an openai.APIConnectionError: Connection error., which can mislead users into thinking there's a problem with the network connection. However, the real issue lies in the KEY containing spaces.

Suggested Solution

It would be beneficial to preprocess the KEY by trimming any leading or trailing white spaces. This step should occur before any network requests are made to ensure that the KEY is in a valid format, preventing the aforementioned exception and misleading errors.

Expected Outcome

By implementing a trimming process for the KEY, users will no longer encounter the openai.APIConnectionError due to spaces in the KEY. This enhancement will improve error clarity and ensure users are not misled into diagnosing connection issues when the problem is actually with the KEY's format.

I believe this improvement will greatly enhance the user experience by eliminating a common source of confusion and ensuring errors are accurately reported and diagnosed.