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

Handle Whitespace in KEY to Prevent Misleading Connection Error #310

Closed runjinz closed 5 months ago

runjinz commented 5 months ago

Issue Description: When a KEY contains spaces, it triggers the error h11._util.LocalProtocolError: Illegal header value. However, the openai library, upon encountering this exception, rethrows it as openai.APIConnectionError: Connection error., which can mislead users into thinking there is a problem with their network connection. To prevent this misunderstanding and avoid such exceptions, it would be prudent to implement a preprocessing step that trims whitespace from the beginning and end of the KEY before any operations are executed.

Suggested Solution: Implement a trim operation on the KEY value to remove any leading or trailing spaces before it is used in operations. This can help in ensuring that users do not encounter the misleading connection error and understand the actual issue at hand without confusion.