diff --git a/README.md b/README.md index fea0b0b..cbba0dd 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,6 @@ # gpt-contextfiles -** currently in development, if you'll like to contribute or provide any feedback check out the [link](https://github.com/Iheuzio/gpt-contextfiles/issues) ** - -I was annoyed with copying responses into chatgpt and other LLMs for debugging my code across files, so I decided to make an extension that will do that. - -You simply right click each file you want to pass through, check or uncheck the checkbox, then enter your question and pass along the response over the api to your LLM. +> if you'll like to contribute or provide any feedback check out the [link](https://github.com/Iheuzio/gpt-contextfiles/issues) This extension uses the openai api, there are many models avaliable: @@ -14,7 +10,11 @@ https://openai.com/pricing If you wish to change the model, you must change the model in the extension.js file -https://platform.openai.com/docs/models/gpt-3-5 +# Examples + +Demo of how to use the extension: +![](./images/demo-program.gif) + # Installation @@ -31,13 +31,8 @@ Refresh -> refreshes the window so that all new files will be available for that - Right click to add files to the context window - Click on the extension addon to open the context window, refresh to update the files to check. - Select the files uses checkboxes -- After submit is pressed, wait until the question disappears, this means the query is processed by openai and was fully sent -- Click `API Response` to view your query - -# Examples - -Demo of how to use the extension: -![](./images/demo-program.gif) +- Wait for response to be returned +- Copy the code (orange portion) and paste it into your code editor # How it works diff --git a/extension.js b/extension.js index cec389d..7302d59 100644 --- a/extension.js +++ b/extension.js @@ -184,302 +184,341 @@ function getWebviewContent(apiResponse = '', question = '') { .join(''); return ` - - - - - -

GPT Context

-
-
- - -
- + + + + + +

GPT Context

+ +
+ +
+
-
-
-
- API Response -
-
-
-

${question ? '> ' + question : null}

-
- ${ - apiResponse ? ` -
-

-

${apiResponse.replace(/```([^```]+)```/g, '$1')}
-

-
- ` : null - } -
-
+
+
+ API Response +
+
+
+

${question ? '> ' + question : null}

+
+ ${ + apiResponse ? ` +
+

+

${apiResponse.replace(/```([^```]+)```/g, '')}
+

+
+ ` : null + } +
+
+
${fileList ? fileList : '

No files selected

'}
-
- - - - `; + + const form = document.getElementById('questionForm'); + function submitQuestionApi() { + event.preventDefault(); + if (document.getElementById('question').value === '' || document.getElementById('question').value === null) { + return; + } + const question = document.getElementById('question').value; + const checkboxes = document.querySelectorAll('input[type="checkbox"]'); + const selectedUris = []; + checkboxes.forEach(checkbox => { + if (checkbox.checked) { + const uri = checkbox.getAttribute('data-uri'); + selectedUris.push(uri); + } + }); + vscode.postMessage({ + command: 'submitQuestion', + text: question, + selectedUris: selectedUris + }); + } + + + + + `; } @@ -556,6 +598,8 @@ function activate(context) { webviewView.webview.html = getWebviewContent(); } else if (message.command === 'submitQuestion') { await handleQuestionSubmission(webviewView, message.text, message.selectedUris); + } else if (message.command === 'codeCopied') { + vscode.window.showInformationMessage('Code copied to clipboard'); } }); } diff --git a/images/demo-program.gif b/images/demo-program.gif index ee22db6..41dfa93 100644 Binary files a/images/demo-program.gif and b/images/demo-program.gif differ