From 94f4ff4f2e6d46b283684f6406c04b2dfa1e4f82 Mon Sep 17 00:00:00 2001 From: Christopher Date: Wed, 21 Jun 2023 22:24:19 -0400 Subject: [PATCH 01/14] feature(tags): associate project with relative keywords --- package.json | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 6b42a3d..a5fba6e 100644 --- a/package.json +++ b/package.json @@ -2,13 +2,27 @@ "name": "gpt-contextfiles", "displayName": "GPT-ContextFiles", "description": "Choose the files to pass into GPT to provide a question with multiple files (doesn't check context)", - "version": "0.1.1", + "version": "0.1.2", "engines": { "vscode": "^1.79.0" }, "categories": [ "Machine Learning" ], + "tags": [ + "16k", + "GPT", + "ai", + "testing", + "debugging", + "files", + "api" + ], + "relatedTags": [ + "Artificial Intelligence", + "Natural Language Processing", + "Code editor" + ], "activationEvents": [ "onCommand:extension.addFilesToGPTContext", "onCommand:extension.openGPTContextPanel" From 2a6c28550f480c17c8e2347f097e6ba6f5ee0a42 Mon Sep 17 00:00:00 2001 From: Christopher Date: Wed, 21 Jun 2023 23:07:27 -0400 Subject: [PATCH 02/14] feature(categories): Expand into other categories related to this program --- package.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index a5fba6e..6d7adb3 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,13 @@ "vscode": "^1.79.0" }, "categories": [ - "Machine Learning" + "Machine Learning", + "Debuggers", + "Formatters", + "Linters", + "Programming Languages", + "Testing", + "Snippets" ], "tags": [ "16k", From b104bed2dd9e11b77489552e14dfd5757cd854df Mon Sep 17 00:00:00 2001 From: Iheuzio <97270760+Iheuzio@users.noreply.github.com> Date: Thu, 22 Jun 2023 11:53:36 -0400 Subject: [PATCH 03/14] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 31 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 +++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..e501cf8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,31 @@ +--- +name: Bug report +about: Create a report to help us improve +title: "[BUG]" +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. Linux, Windows] + - VSCode version + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..a5b62af --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: "[FEAT]" +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. From 338c83c1042df398118dd60e83b46fe0ef7106a5 Mon Sep 17 00:00:00 2001 From: Iheuzio <97270760+Iheuzio@users.noreply.github.com> Date: Thu, 22 Jun 2023 12:20:58 -0400 Subject: [PATCH 04/14] Create CONTRIBUTING.md Update the contribution guide --- CONTRIBUTING.md | 147 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..1bca7d8 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,147 @@ +# Contributing to gpt-contextfiles + +Thanks for taking an interest in the project! + +All types of contributions are encouraged and valued. See the [Table of Contents](#table-of-contents) for different ways to help and details about how this project handles them. Please make sure to read the relevant section before making your contribution. It will make it a lot easier for us maintainers and smooth out the experience for all involved. The community looks forward to your contributions. + +> And if you like the project, but just don't have time to contribute, that's fine. There are other easy ways to support the project and show your appreciation, which we would also be very happy about: +> - Star the project +> - Share it online +> - Refer this project in your project's readme + + +## Table of Contents + +- [Code of Conduct](#code-of-conduct) +- [I Have a Question](#i-have-a-question) +- [I Want To Contribute](#i-want-to-contribute) + - [Reporting Bugs](#reporting-bugs) + - [Suggesting Enhancements](#suggesting-enhancements) + - [Your First Code Contribution](#your-first-code-contribution) + - [Improving The Documentation](#improving-the-documentation) +- [Styleguides](#styleguides) + - [Commit Messages](#commit-messages) +- [Join The Project Team](#join-the-project-team) + + +## Code of Conduct + +This project and everyone participating in it is governed by the +[gpt-contextfiles Code of Conduct](https://github.com/Iheuzio/gpt-contextfiles/blob/master/CODE_OF_CONDUCT.md). +By participating, you are expected to uphold this code. Please report unacceptable behavior +to any of the maintainers. + + +## I Have a Question + +> If you want to ask a question, we assume that you have read the available [Documentation](). + +Before you ask a question, it is best to search for existing [Issues](https://github.com/Iheuzio/gpt-contextfiles//issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue. It is also advisable to search the internet for answers first. + +If you then still feel the need to ask a question and need clarification, we recommend the following: + +- Open an [Issue](https://github.com/Iheuzio/gpt-contextfiles//issues/new). +- Provide as much context as you can about what you're running into. +- Provide project and platform versions (nodejs, npm, etc), depending on what seems relevant. + +Just remember to add the relevant tags and keep discussions specific to that category. + +## I Want To Contribute + +> When contributing to this project, you must agree that you have authored 100% of the content, that you have the necessary rights to the content and that the content you contribute may be provided under the project license. + +### Reporting Bugs + + +#### Before Submitting a Bug Report + +A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. Please complete the following steps in advance to help us fix any potential bug as fast as possible. + +- Make sure that you are using the latest version. +- Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions (Make sure that you have read the [documentation](). If you are looking for support, you might want to check [this section](#i-have-a-question)). +- To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [bug tracker](https://github.com/Iheuzio/gpt-contextfiles/issues?q=label%3Abug). +- Collect information about the bug: + - Stack trace (Traceback) + - OS, Platform and Version (Windows, Linux, macOS, x86, ARM) + - Version of the interpreter, compiler, VSCode version, runtime environment, package manager, depending on what seems relevant. + - Possibly your input and the output + - Can you reliably reproduce the issue? And can you also reproduce it with older versions? + + +#### How Do I Submit a Good Bug Report? + +> You must never report security related issues, vulnerabilities or bugs including sensitive information to the issue tracker, or elsewhere in public. Instead sensitive bugs must be sent to any of the maintainers. +> You must encrypt any senseitive information found. + +We use GitHub issues to track bugs and errors. If you run into an issue with the project: + +- Open an [Issue](https://github.com/Iheuzio/gpt-contextfiles//issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.) +- Explain the behavior you would expect and the actual behavior. +- Please provide as much context as possible and describe the *reproduction steps* that someone else can follow to recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem and create a reduced test case. +- Provide the information you collected in the previous section. + +Once it's filed: + +- The project team will label the issue accordingly. +- A team member will try to reproduce the issue with your provided steps. If there are no reproduction steps or no obvious way to reproduce the issue, the team will ask you for those steps and mark the issue as `needs-repro`. Bugs with the `needs-repro` tag will not be addressed until they are reproduced. +- If the team is able to reproduce the issue, it will be marked `needs-fix`, as well as possibly other tags (such as `critical`), and the issue will be left to be [implemented by someone](#your-first-code-contribution). + + +### Suggesting Enhancements + +This section guides you through submitting an enhancement suggestion for gpt-contextfiles, **including completely new features and minor improvements to existing functionality**. Following these guidelines will help maintainers and the community to understand your suggestion and find related suggestions. + +#### Before Submitting an Enhancement + +- Make sure that you are using the latest version. +- Read the [documentation]() carefully and find out if the functionality is already covered, maybe by an individual configuration. +- Perform a [search](https://github.com/Iheuzio/gpt-contextfiles//issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one. +- Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. + + +#### How Do I Submit a Good Enhancement Suggestion? + +Enhancement suggestions are tracked as [GitHub issues](https://github.com/Iheuzio/gpt-contextfiles//issues). + +- Use a **clear and descriptive title** for the issue to identify the suggestion. +- Provide a **step-by-step description of the suggested enhancement** in as many details as possible. +- **Describe the current behavior** and **explain which behavior you expected to see instead** and why. At this point you can also tell which alternatives do not work for you. +- You may want to **include screenshots and animated GIFs** which help you demonstrate the steps or point out the part which the suggestion is related to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on macOS and Windows, and [this tool](https://github.com/colinkeenan/silentcast) or [this tool](https://github.com/GNOME/byzanz) on Linux. +- **Explain why this enhancement would be useful** to most gpt-contextfiles users. You may also want to point out the other projects that solved it better and which could serve as inspiration. + + + +### Your First Code Contribution + +You can test natively in your specific IDE and require little time to intialize a test of your contribution. + +1. Open VSCode, clone into your forked version +2. Edit your change, if it is a feature use feature/, if it is a fix use fix/ +3. Add a proper commit message feature():short description, or if it is a fix: fix(): short description +4. Issue a Pull Request with the same structure as your commit message +5. Wait for another contributor or user to approve the request after it is proved to be working +6. Merge it into the `dev` branch + +### Improving The Documentation + +If you notice the documentation lacking, you can start a PR and add a `fix` branch to update it + +## Styleguides + + Use the `prettier` extension to format the code + +### Commit Messages + +Features: +> feature(): short description + +Fixes: +> fix(): short description + +## Join The Project Team + +Upon contributing, you will be under the contributors in the next update for the version. + + +## Attribution +This guide is based on the **contributing-gen**. [Make your own](https://github.com/bttger/contributing-gen)! From 773eac6325efe5b16b314418b95aa4cde7d0a639 Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 22 Jun 2023 12:35:24 -0400 Subject: [PATCH 05/14] Updated changelog to reflect releases --- CHANGELOG.md | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14838a3..40367e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,45 @@ # Change Log -All notable changes to the "gpt-contextfiles" extension will be documented in this file. - -Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. +Version History ## [Unreleased] -- Initial release \ No newline at end of file +## [Release 0.1.1] + +Swapped category from `other` to `Machine Learning` to better reflect use-case + +## What's Changed +* fix(context-16k): model uses 16k tokens now by @Iheuzio in https://github.com/Iheuzio/gpt-contextfiles/pull/7 +* Fix/id not selected by @Iheuzio in https://github.com/Iheuzio/gpt-contextfiles/pull/8 +* Minor Fixes by @Iheuzio in https://github.com/Iheuzio/gpt-contextfiles/pull/9 +* fix(category): swapped category by @Iheuzio in https://github.com/Iheuzio/gpt-contextfiles/pull/10 + + +**Full Changelog**: https://github.com/Iheuzio/gpt-contextfiles/compare/0.0.1...0.1.1 + +## [Release 0.1.0] + +## What's Changed +* fix(context-16k): model uses 16k tokens now by @Iheuzio in https://github.com/Iheuzio/gpt-contextfiles/pull/7 +* Fix/id not selected by @Iheuzio in https://github.com/Iheuzio/gpt-contextfiles/pull/8 +* Minor Fixes by @Iheuzio in https://github.com/Iheuzio/gpt-contextfiles/pull/9 + + +**Full Changelog**: https://github.com/Iheuzio/gpt-contextfiles/compare/0.0.1...0.1 + +## [Release 0.0.1] + +Still in development, requires a bit of testing. + +## What's Changed +* fix(gpt-context): Fixes the layout and the options with the selected by @Iheuzio in https://github.com/Iheuzio/gpt-contextfiles/pull/1 +* fix(queries): Fixes the queries formatting by @Iheuzio in https://github.com/Iheuzio/gpt-contextfiles/pull/2 +* fix(selected-files): User can now select individual files to pass into the context using the checkboxes by @Iheuzio in https://github.com/Iheuzio/gpt-contextfiles/pull/3 +* Feature/openai api by @Iheuzio in https://github.com/Iheuzio/gpt-contextfiles/pull/4 +* fix(formatting): Files now formatted like it was previously when passed through by @Iheuzio in https://github.com/Iheuzio/gpt-contextfiles/pull/5 +* Release v1 by @Iheuzio in https://github.com/Iheuzio/gpt-contextfiles/pull/6 + +## New Contributors +* @Iheuzio made their first contribution in https://github.com/Iheuzio/gpt-contextfiles/pull/1 + +**Full Changelog**: https://github.com/Iheuzio/gpt-contextfiles/commits/0.0.1 \ No newline at end of file From fc7a69869f2c9e874f25a440d8b9eb64c6cc7ca9 Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 22 Jun 2023 12:40:10 -0400 Subject: [PATCH 06/14] Code of conduct relative to Contributor Covenant --- CODE_OF_CONDUCT.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..555c6d5 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,46 @@ +# Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +- The use of sexualized language or imagery and unwelcome sexual attention or advances +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or electronic address, without explicit permission +- Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team maintainers. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at [https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0]. + +[homepage]: https://www.contributor-covenant.org +[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html \ No newline at end of file From 4e0531d1cb0c9f8cc2edbcd3a4630ca3c6e42afe Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 22 Jun 2023 12:42:53 -0400 Subject: [PATCH 07/14] Update contribution guide, readme is documentation --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1bca7d8..113ee86 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,7 +34,7 @@ to any of the maintainers. ## I Have a Question -> If you want to ask a question, we assume that you have read the available [Documentation](). +> If you want to ask a question, we assume that you have read the available [Documentation](https://github.com/Iheuzio/gpt-contextfiles/blob/main/README.md). Before you ask a question, it is best to search for existing [Issues](https://github.com/Iheuzio/gpt-contextfiles//issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue. It is also advisable to search the internet for answers first. @@ -58,7 +58,7 @@ Just remember to add the relevant tags and keep discussions specific to that cat A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. Please complete the following steps in advance to help us fix any potential bug as fast as possible. - Make sure that you are using the latest version. -- Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions (Make sure that you have read the [documentation](). If you are looking for support, you might want to check [this section](#i-have-a-question)). +- Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions (Make sure that you have read the [documentation](https://github.com/Iheuzio/gpt-contextfiles/blob/main/README.md). If you are looking for support, you might want to check [this section](#i-have-a-question)). - To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [bug tracker](https://github.com/Iheuzio/gpt-contextfiles/issues?q=label%3Abug). - Collect information about the bug: - Stack trace (Traceback) @@ -94,7 +94,7 @@ This section guides you through submitting an enhancement suggestion for gpt-con #### Before Submitting an Enhancement - Make sure that you are using the latest version. -- Read the [documentation]() carefully and find out if the functionality is already covered, maybe by an individual configuration. +- Read the [documentation](https://github.com/Iheuzio/gpt-contextfiles/blob/main/README.md) carefully and find out if the functionality is already covered, maybe by an individual configuration. - Perform a [search](https://github.com/Iheuzio/gpt-contextfiles//issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one. - Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. From 1fb3674bf0d87ead5390c5eb0bbd8fde5bbbe999 Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 22 Jun 2023 12:47:11 -0400 Subject: [PATCH 08/14] Update readme to disclose model used --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 217ec50..b4d5691 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,16 @@ I was annoyed with copying responses into chatgpt and other LLMs for debugging m 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. +This extension uses the openai api, there are many models avaliable: + +https://openai.com/pricing + +> However, being orientated with managing files this project defaults to the 16k context with GPT-3.5-turbo-16k + +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 + # Installation Add your api key to `OPENAI_API_KEY` for your windows/linux environment variable (tested with system variable) From d7c938d18263d2ddc5fe6e556ef12eaa56424684 Mon Sep 17 00:00:00 2001 From: Iheuzio <97270760+Iheuzio@users.noreply.github.com> Date: Thu, 22 Jun 2023 12:59:06 -0400 Subject: [PATCH 09/14] Update LICENSE.txt --- LICENSE.txt | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 261eeb9..a1c6987 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -174,19 +174,7 @@ of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] + Copyright [2023] [Christopher Bartos] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From 572b4a39f763c86c1c1425edfe4eab2b5475a485 Mon Sep 17 00:00:00 2001 From: Iheuzio Date: Fri, 23 Jun 2023 14:27:57 -0400 Subject: [PATCH 10/14] feature(sidebar): Renders webpanel on the side --- extension.js | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ images/files.svg | 1 + package.json | 23 ++++++++++++-- 3 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 images/files.svg diff --git a/extension.js b/extension.js index 8a9c867..48021b3 100644 --- a/extension.js +++ b/extension.js @@ -260,6 +260,84 @@ function activate(context) { context.subscriptions.push(clearSelectedFilesCommand); context.subscriptions.push(refreshFilesCommand); vscode.window.registerTreeDataProvider('selectedFiles', fileDataProvider); + + const provider = { + resolveWebviewView(webviewView) { + webviewView.webview.options = { + enableScripts: true + }; + webviewView.webview.html = getWebviewContent(); + webviewView.webview.onDidReceiveMessage(async message => { + if (message.command === 'submitQuestion') { + const question = message.text; + const selectedUris = message.selectedUris; + + // Update the selectedFiles array based on the selectedUris + selectedFiles.forEach(file => { + file.selected = selectedUris.includes(file.uri.fsPath); + }); + + fileDataProvider.refresh(); + + const fileContents = selectedFiles + .filter(file => file.selected) + .map(file => { + const document = vscode.workspace.textDocuments.find(doc => doc.uri.fsPath === file.uri.fsPath); + if (document) { + const lines = document.getText().split('\n'); + const formattedLines = lines.map(line => `\t${line}`).join('\n'); + return `${file.uri.fsPath}:\n\`\`\`\n${formattedLines}\n\`\`\``; + } + return ''; + }) + .join('\n\n'); + + // Call OpenAI API with the question and file contents + try { + const chatCompletion = await openai.createChatCompletion({ + model: "gpt-3.5-turbo-16k", + messages: [ + { role: "system", content: "Answer the coding questions, only provide the code and documentation, explaining the solution after providing the code." }, + { role: "user", content: question }, + { role: "assistant", content: fileContents } + ], + }); + + // Extract the answer from the OpenAI response + const answer = chatCompletion.data.choices[0].message.content; + + // Update the webview content to display only the OpenAI response + webviewView.webview.html = getWebviewContent(answer, question); + } catch (error) { + // Handle any errors from the OpenAI API + console.error("Failed to get OpenAI response:", error); + webviewView.webview.html = getWebviewContent(`Failed to get response from OpenAI API. Error: ${error.message}`, question); + } + } else if (message.command === 'toggleFileSelection') { + const uri = message.uri; + const file = selectedFiles.find(file => file.uri.fsPath === uri); + if (file) { + file.toggleSelected(); + fileDataProvider.refresh(); + } + } else if (message.command === 'clearSelectedFiles') { + const clearedFiles = selectedFiles.filter(file => file.selected === false); + selectedFiles.length = 0; // Clear the array + clearedFiles.forEach(file => { + fileDataProvider.refresh(); + }); + webviewView.webview.html = getWebviewContent(); + } else if (message.command === 'refreshFiles') { + fileDataProvider.refresh(); + webviewView.webview.html = getWebviewContent(); + } + }); + } + }; + + context.subscriptions.push(vscode.window.registerWebviewViewProvider('gpt-context-sidebar', provider)); + } + exports.activate = activate; diff --git a/images/files.svg b/images/files.svg new file mode 100644 index 0000000..08261df --- /dev/null +++ b/images/files.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/package.json b/package.json index 6d7adb3..6880558 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ ], "activationEvents": [ "onCommand:extension.addFilesToGPTContext", - "onCommand:extension.openGPTContextPanel" + "onCommand:extension.openGPTContextPanel", + "onCommand:extension.gpt-context-sidebar" ], "main": "./extension.js", "contributes": { @@ -54,6 +55,15 @@ "title": "Clear Selected Files" } ], + "viewsContainers" : { + "activitybar": [ + { + "id": "gpt-contextfiles-sidebar-view", + "title": "GPT Context", + "icon": "images/files.svg" + } + ] + }, "menus": { "explorer/context": [ { @@ -70,8 +80,17 @@ "name": "Selected Files", "when": "explorerResourceIsFolder && explorerViewletVisible" } + ], + "gpt-contextfiles-sidebar-view": [ + { + "type": "webview", + "id": "gpt-context-sidebar", + "name": "GPTContextFiles", + "icon": "images/files.svg", + "contextualTitle": "GPTContext" + } ] - } + } }, "scripts": { "lint": "eslint .", From b756de10e470f8abb453569afa93bd6f46bc0211 Mon Sep 17 00:00:00 2001 From: Iheuzio Date: Fri, 23 Jun 2023 14:43:58 -0400 Subject: [PATCH 11/14] fix(redundant-code): Fixing redundant code --- extension.js | 148 +++++++++++++++++++++++++-------------------------- 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/extension.js b/extension.js index 48021b3..1d69106 100644 --- a/extension.js +++ b/extension.js @@ -261,82 +261,82 @@ function activate(context) { context.subscriptions.push(refreshFilesCommand); vscode.window.registerTreeDataProvider('selectedFiles', fileDataProvider); - const provider = { - resolveWebviewView(webviewView) { - webviewView.webview.options = { - enableScripts: true - }; - webviewView.webview.html = getWebviewContent(); - webviewView.webview.onDidReceiveMessage(async message => { - if (message.command === 'submitQuestion') { - const question = message.text; - const selectedUris = message.selectedUris; - - // Update the selectedFiles array based on the selectedUris - selectedFiles.forEach(file => { - file.selected = selectedUris.includes(file.uri.fsPath); - }); - +const provider = { + resolveWebviewView(webviewView) { + webviewView.webview.options = { + enableScripts: true + }; + webviewView.webview.html = getWebviewContent(); + webviewView.webview.onDidReceiveMessage(async message => { + if (message.command === 'toggleFileSelection') { + const uri = message.uri; + const file = selectedFiles.find(file => file.uri.fsPath === uri); + if (file) { + file.toggleSelected(); fileDataProvider.refresh(); - - const fileContents = selectedFiles - .filter(file => file.selected) - .map(file => { - const document = vscode.workspace.textDocuments.find(doc => doc.uri.fsPath === file.uri.fsPath); - if (document) { - const lines = document.getText().split('\n'); - const formattedLines = lines.map(line => `\t${line}`).join('\n'); - return `${file.uri.fsPath}:\n\`\`\`\n${formattedLines}\n\`\`\``; - } - return ''; - }) - .join('\n\n'); - - // Call OpenAI API with the question and file contents - try { - const chatCompletion = await openai.createChatCompletion({ - model: "gpt-3.5-turbo-16k", - messages: [ - { role: "system", content: "Answer the coding questions, only provide the code and documentation, explaining the solution after providing the code." }, - { role: "user", content: question }, - { role: "assistant", content: fileContents } - ], - }); - - // Extract the answer from the OpenAI response - const answer = chatCompletion.data.choices[0].message.content; - - // Update the webview content to display only the OpenAI response - webviewView.webview.html = getWebviewContent(answer, question); - } catch (error) { - // Handle any errors from the OpenAI API - console.error("Failed to get OpenAI response:", error); - webviewView.webview.html = getWebviewContent(`Failed to get response from OpenAI API. Error: ${error.message}`, question); - } - } else if (message.command === 'toggleFileSelection') { - const uri = message.uri; - const file = selectedFiles.find(file => file.uri.fsPath === uri); - if (file) { - file.toggleSelected(); - fileDataProvider.refresh(); - } - } else if (message.command === 'clearSelectedFiles') { - const clearedFiles = selectedFiles.filter(file => file.selected === false); - selectedFiles.length = 0; // Clear the array - clearedFiles.forEach(file => { - fileDataProvider.refresh(); - }); - webviewView.webview.html = getWebviewContent(); - } else if (message.command === 'refreshFiles') { - fileDataProvider.refresh(); - webviewView.webview.html = getWebviewContent(); } - }); - } - }; - - context.subscriptions.push(vscode.window.registerWebviewViewProvider('gpt-context-sidebar', provider)); - + } else if (message.command === 'clearSelectedFiles') { + const clearedFiles = selectedFiles.filter(file => file.selected === false); + selectedFiles.length = 0; // Clear the array + clearedFiles.forEach(file => { + fileDataProvider.refresh(); + }); + webviewView.webview.html = getWebviewContent(); + } else if (message.command === 'refreshFiles') { + fileDataProvider.refresh(); + webviewView.webview.html = getWebviewContent(); + } else if (message.command === 'submitQuestion') { + const question = message.text; + const selectedUris = message.selectedUris; + + // Update the selectedFiles array based on the selectedUris + selectedFiles.forEach(file => { + file.selected = selectedUris.includes(file.uri.fsPath); + }); + + fileDataProvider.refresh(); + + const fileContents = selectedFiles + .filter(file => file.selected) + .map(file => { + const document = vscode.workspace.textDocuments.find(doc => doc.uri.fsPath === file.uri.fsPath); + if (document) { + const lines = document.getText().split('\n'); + const formattedLines = lines.map(line => `\t${line}`).join('\n'); + return `${file.uri.fsPath}:\n\`\`\`\n${formattedLines}\n\`\`\``; + } + return ''; + }) + .join('\n\n'); + + // Call OpenAI API with the question and file contents + try { + const chatCompletion = await openai.createChatCompletion({ + model: "gpt-3.5-turbo-16k", + messages: [ + { role: "system", content: "Answer the coding questions, only provide the code and documentation, explaining the solution after providing the code." }, + { role: "user", content: question }, + { role: "assistant", content: fileContents } + ], + }); + + // Extract the answer from the OpenAI response + const answer = chatCompletion.data.choices[0].message.content; + + // Update the webview content to display only the OpenAI response + webviewView.webview.html = getWebviewContent(answer, question); + } catch (error) { + // Handle any errors from the OpenAI API + console.error("Failed to get OpenAI response:", error); + webviewView.webview.html = getWebviewContent(`Failed to get response from OpenAI API. Error: ${error.message}`, question); + } + } + }); + } +}; + +context.subscriptions.push(vscode.window.registerWebviewViewProvider('gpt-context-sidebar', provider)); + } From 0ec8dc8ac40db011f4f7ece6748ffd8cfe1cd93f Mon Sep 17 00:00:00 2001 From: Iheuzio Date: Fri, 23 Jun 2023 15:05:45 -0400 Subject: [PATCH 12/14] fix(redudant-code): Removed redundancy --- extension.js | 135 ++++++++++++++++++--------------------------------- 1 file changed, 47 insertions(+), 88 deletions(-) diff --git a/extension.js b/extension.js index 1d69106..2deab94 100644 --- a/extension.js +++ b/extension.js @@ -73,6 +73,51 @@ const addFilesCommand = vscode.commands.registerCommand('extension.addFilesToGPT const fileDataProvider = new FileDataProvider(); +// Function to handle question submission +async function handleQuestionSubmission(panel, question, selectedUris) { + // Update the selectedFiles array based on the selectedUris + selectedFiles.forEach(file => { + file.selected = selectedUris.includes(file.uri.fsPath); + }); + + fileDataProvider.refresh(); + + const fileContents = selectedFiles + .filter(file => file.selected) + .map(file => { + const document = vscode.workspace.textDocuments.find(doc => doc.uri.fsPath === file.uri.fsPath); + if (document) { + const lines = document.getText().split('\n'); + const formattedLines = lines.map(line => `\t${line}`).join('\n'); + return `${file.uri.fsPath}:\n\`\`\`\n${formattedLines}\n\`\`\``; + } + return ''; + }) + .join('\n\n'); + + // Call OpenAI API with the question and file contents + try { + const chatCompletion = await openai.createChatCompletion({ + model: "gpt-3.5-turbo-16k", + messages: [ + { role: "system", content: "Answer the coding questions, only provide the code and documentation, explaining the solution after providing the code." }, + { role: "user", content: question }, + { role: "assistant", content: fileContents } + ], + }); + + // Extract the answer from the OpenAI response + const answer = chatCompletion.data.choices[0].message.content; + + // Update the webview content to display only the OpenAI response + panel.webview.html = getWebviewContent(answer, question); + } catch (error) { + // Handle any errors from the OpenAI API + console.error("Failed to get OpenAI response:", error); + panel.webview.html = getWebviewContent(`Failed to get response from OpenAI API. Error: ${error.message}`, question); + } +} + // Command for displaying the webview panel const openGPTContextPanelCommand = vscode.commands.registerCommand('extension.openGPTContextPanel', () => { const panel = vscode.window.createWebviewPanel( @@ -88,50 +133,7 @@ const openGPTContextPanelCommand = vscode.commands.registerCommand('extension.op panel.webview.onDidReceiveMessage(async message => { if (message.command === 'submitQuestion') { - const question = message.text; - const selectedUris = message.selectedUris; - - // Update the selectedFiles array based on the selectedUris - selectedFiles.forEach(file => { - file.selected = selectedUris.includes(file.uri.fsPath); - }); - - fileDataProvider.refresh(); - - const fileContents = selectedFiles - .filter(file => file.selected) - .map(file => { - const document = vscode.workspace.textDocuments.find(doc => doc.uri.fsPath === file.uri.fsPath); - if (document) { - const lines = document.getText().split('\n'); - const formattedLines = lines.map(line => `\t${line}`).join('\n'); - return `${file.uri.fsPath}:\n\`\`\`\n${formattedLines}\n\`\`\``; - } - return ''; - }) - .join('\n\n'); - - // Call OpenAI API with the question and file contents - try { - const chatCompletion = await openai.createChatCompletion({ - model: "gpt-3.5-turbo-16k", - messages: [ - { role: "system", content: "Answer the coding questions, only provide the code and documentation, explaining the solution after providing the code." }, - { role: "user", content: question }, - { role: "assistant", content: fileContents } - ], - }); - - // Extract the answer from the OpenAI response - const answer = chatCompletion.data.choices[0].message.content; - - // Update the webview content to display only the OpenAI response - panel.webview.html = getWebviewContent(answer, question); - } catch (error) { - // Handle any errors from the OpenAI API - console.error("Failed to get OpenAI response:", error); - panel.webview.html = getWebviewContent(`Failed to get response from OpenAI API. Error: ${error.message}`, question); - } + await handleQuestionSubmission(panel, message.text, message.selectedUris); } else if (message.command === 'toggleFileSelection') { const uri = message.uri; const file = selectedFiles.find(file => file.uri.fsPath === uri); @@ -286,50 +288,7 @@ const provider = { fileDataProvider.refresh(); webviewView.webview.html = getWebviewContent(); } else if (message.command === 'submitQuestion') { - const question = message.text; - const selectedUris = message.selectedUris; - - // Update the selectedFiles array based on the selectedUris - selectedFiles.forEach(file => { - file.selected = selectedUris.includes(file.uri.fsPath); - }); - - fileDataProvider.refresh(); - - const fileContents = selectedFiles - .filter(file => file.selected) - .map(file => { - const document = vscode.workspace.textDocuments.find(doc => doc.uri.fsPath === file.uri.fsPath); - if (document) { - const lines = document.getText().split('\n'); - const formattedLines = lines.map(line => `\t${line}`).join('\n'); - return `${file.uri.fsPath}:\n\`\`\`\n${formattedLines}\n\`\`\``; - } - return ''; - }) - .join('\n\n'); - - // Call OpenAI API with the question and file contents - try { - const chatCompletion = await openai.createChatCompletion({ - model: "gpt-3.5-turbo-16k", - messages: [ - { role: "system", content: "Answer the coding questions, only provide the code and documentation, explaining the solution after providing the code." }, - { role: "user", content: question }, - { role: "assistant", content: fileContents } - ], - }); - - // Extract the answer from the OpenAI response - const answer = chatCompletion.data.choices[0].message.content; - - // Update the webview content to display only the OpenAI response - webviewView.webview.html = getWebviewContent(answer, question); - } catch (error) { - // Handle any errors from the OpenAI API - console.error("Failed to get OpenAI response:", error); - webviewView.webview.html = getWebviewContent(`Failed to get response from OpenAI API. Error: ${error.message}`, question); - } + await handleQuestionSubmission(webviewView, message.text, message.selectedUris); } }); } From 54cb7530f7df9f3387eff66f345ec87dfc75302b Mon Sep 17 00:00:00 2001 From: Iheuzio Date: Fri, 23 Jun 2023 18:13:47 -0400 Subject: [PATCH 13/14] fix(css): sidebar now has css --- extension.js | 356 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 311 insertions(+), 45 deletions(-) diff --git a/extension.js b/extension.js index 2deab94..7ddc229 100644 --- a/extension.js +++ b/extension.js @@ -179,33 +179,283 @@ function getWebviewContent(apiResponse = '', question = '') { const fileList = selectedFiles .map( file => - `
${file.uri.fsPath}
` ) .join(''); return ` - + + + +

GPT Context

-
+
- - - - + +
+ + + +
-
-
${question ? question : ''}
- ${ - apiResponse ? `
${apiResponse}
` : '' - } +
+
+ API Response
-
-

Selected Files:

- ${fileList} +
+
+

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

+
+ ${ + apiResponse ? ` +
+

${apiResponse}

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

No files selected

'} +