Skip to content

Commit

Permalink
minor UX improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
timkmecl committed Dec 8, 2022
1 parent ef96cce commit 81fc42a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Please note that this extension is currently a proof of concept and may have som

## Credits

- This wouldn't be possible without OpenAI's [ChtGPT](https://chat.openai.com/chat)
- This wouldn't be possible without OpenAI's [ChatGPT](https://chat.openai.com/chat)
- The extension makes use of [chatgpt-api](https://github.com/transitive-bullshit/chatgpt-api) (by [Travis Fischer](https://github.com/transitive-bullshit)), which uses ChatGPT unofficial API in order to login and communicate with it.
- It is built on top of [mpociot/chatgpt-vscode](https://github.com/mpociot/chatgpt-vscode), which started this project
- `v0.3` inspired and based on [barnesoir/chatgpt-vscode-plugin](https://github.com/barnesoir/chatgpt-vscode-plugin) and [gencay/vscode-chatgpt](https://github.com/gencay/vscode-chatgpt)
37 changes: 15 additions & 22 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,25 +168,13 @@ class ChatGPTViewProvider implements vscode.WebviewViewProvider {
if (!this._view) {
await vscode.commands.executeCommand('chatgpt.chatView.focus');
} else {
this._view?.show?.(true);
this._view?.show?.(true);
}


let response = '';

// Check if the ChatGPTAPI instance is signed in
let isSignedIn = false;
try {
this._chatGPTAPI && await this._chatGPTAPI.ensureAuth();
isSignedIn = true;
} catch (e) {
console.error(e);
}



if (!isSignedIn || !this._chatGPTAPI) {
response = '[ERROR] Please enter a valid API key in the extension settings';
if (!this._chatGPTAPI) {
response = '[ERROR] Please enter an API key in the extension settings';
} else {
// If successfully signed in
if (this._view) {
Expand Down Expand Up @@ -215,14 +203,19 @@ class ChatGPTViewProvider implements vscode.WebviewViewProvider {
// Make sure the prompt is shown
this._view?.webview.postMessage({ type: 'setPrompt', value: this._prompt });

// Send the search prompt to the ChatGPTAPI instance and store the response
response = await this._chatGPTAPI.sendMessage(searchPrompt, {
onProgress: (partialResponse) => {
if (this._view && this._view.visible) {
this._view.webview.postMessage({ type: 'addResponse', value: partialResponse });
try {
// Send the search prompt to the ChatGPTAPI instance and store the response
response = await this._chatGPTAPI.sendMessage(searchPrompt, {
onProgress: (partialResponse) => {
if (this._view && this._view.visible) {
this._view.webview.postMessage({ type: 'addResponse', value: partialResponse });
}
}
}
});
});
} catch (e) {
console.error(e);
response = `[ERROR] ${e}`;
}
}

// Saves the response
Expand Down

0 comments on commit 81fc42a

Please sign in to comment.