Merge pull request #17 from Iheuzio/dev

Release 0.1.2
This commit is contained in:
Iheuzio 2023-06-23 18:18:15 -04:00 committed by GitHub
commit 15283f04bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 702 additions and 81 deletions

31
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@ -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.

View File

@ -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.

View File

@ -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
## [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

46
CODE_OF_CONDUCT.md Normal file
View File

@ -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

147
CONTRIBUTING.md Normal file
View File

@ -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
<!-- omit in toc -->
## 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](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.
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
<!-- omit in toc -->
#### 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](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)
- 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?
<!-- omit in toc -->
#### 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.
<!-- omit in toc -->
#### Before Submitting an Enhancement
- Make sure that you are using the latest version.
- 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.
<!-- omit in toc -->
#### 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. <!-- this should only be included if the project has a GUI -->
- **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.
<!-- You might want to create an issue template for enhancement suggestions that can be used as a guide and that defines the structure of the information to be included. If you do so, reference it here in the description. -->
### 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/<Your feature>, if it is a fix use fix/<Your fix>
3. Add a proper commit message feature(<Your feature>):short description, or if it is a fix: fix(<Your 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(<Your feature>): short description
Fixes:
> fix(<Your fix>): short description
## Join The Project Team
Upon contributing, you will be under the contributors in the next update for the version.
<!-- omit in toc -->
## Attribution
This guide is based on the **contributing-gen**. [Make your own](https://github.com/bttger/contributing-gen)!

View File

@ -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.

View File

@ -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)

View File

@ -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);
@ -177,33 +179,283 @@ function getWebviewContent(apiResponse = '', question = '') {
const fileList = selectedFiles
.map(
file =>
`<div><input type="checkbox" data-uri="${file.uri.fsPath}" ${
file.selected ? 'checked' : ''
`<div><input type="checkbox" data-uri="${file.uri.fsPath}" ${file.selected ? 'checked' : ''
} onchange="toggleFileSelection('${file.uri.fsPath}')" /> ${file.uri.fsPath}</div>`
)
.join('');
return `
<html>
<body>
<head>
<style>
.panel {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 50%;
height: 100%;
margin: 0 auto;
background-color: #1e1e1e;
color: #d4d4d4;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.textbox {
width: 100%;
height: 200px;
resize: both;
padding: 10px;
}
.buttons {
display: flex;
justify-content: space-between;
width: 50%;
}
.button {
flex-grow: 1;
background-color: #007acc;
color: #fff;
padding: 10px;
text-align: center;
cursor: pointer;
border: none;
outline: none;
font-size: 14px;
}
#response {
border: 1px solid #000;
background-color: #e0e0e0;
padding: 10px;
margin-top: 20px;
overflow-wrap: break-word;
}
#file-list {
margin-top: 20px;
border
}
.form-group {
display: flex;
flex-direction: column;
margin-bottom: 20px;
width: 100%;
}
.form-group label {
margin-bottom: 5px;
font-size: 14px;
}
.form-group input[type="text"] {
padding: 10px;
font-size: 14px;
border: none;
outline: none;
background-color: #2d2d2d;
color: #d4d4d4;
}
.form-group input[type="text"]::placeholder {
color: #d4d4d4;
}
.form-group .button-options {
display: flex;
justify-content: space-between;
margin-top: 10px;
}
.form-group .button-options button {
padding: 10px;
font-size: 14px;
border: none;
outline: none;
cursor: pointer;
background-color: #007acc;
color: #fff;
}
.form-group .button-options button:hover {
background-color: #005f8c;
}
.form-group .button-options button:active {
background-color: #004d73;
}
.form-group .button-options button:focus {
box-shadow: 0 0 0 2px rgba(0, 122, 204, 0.5);
}
.file-list {
margin-top: 20px;
width: 100%;
}
.file-list h2 {
margin-bottom: 10px;
font-size: 14px;
}
.file-list .file-item {
display: flex;
align-items: center;
margin-bottom: 5px;
font-size: 14px;
}
.file-list .file-item input[type="checkbox"] {
margin-right: 5px;
}
.file-list .file-item label {
margin-bottom: 0;
}
.file-list .file-item .file-path {
overflow-wrap: break-word;
}
.file-list .file-item .file-path:hover {
text-decoration: underline;
cursor: pointer;
}
.file-list .file-item .file-path:active {
color: #007acc;
}
.file-list .file-item .file-path:focus {
box-shadow: 0 0 0 2px rgba(0, 122, 204, 0.5);
}
.collapsible {
background-color: #2d2d2d;
color: #d4d4d4;
cursor: pointer;
padding: 10px;
width: 100%;
border: none;
outline: none;
text-align: left;
font-size: 14px;
}
.collapsible:hover {
background-color: #3c3c3c;
}
.collapsible:active {
background-color: #4c4c4c;
}
.collapsible:focus {
box-shadow: 0 0 0 2px rgba(0, 122, 204, 0.5);
}
.content {
padding: 0 10px;
display: none;
overflow: hidden;
background-color: #f1f1f1;
width:100%;
}
.content p {
margin-top: 0;
font-size: 14px;
}
.active, .collapsible:hover {
background-color: #555;
}
.active:after {
content: "\\2212";
}
.collapsible:after {
content: "\\002B";
color: #d4d4d4;
font-weight: bold;
float: right;
margin-left: 5px;
}
.active:after {
content: "\\2212";
}
.collapsible:after {
content: "\\002B";
color: #d4d4d4;
font-weight: bold;
float: right;
margin-left: 5px;
}
#rendered {
background-color: #2d2d2d;
word-wrap: wrap;
margin-top: 20px;
border: 1px solid white;
border-radius: 5px;
padding: 10px;
}
#question-rep {
font-weight: bold;
background-color: #2d2d2d;
word-wrap: wrap;
border: 1px solid white;
border-radius: 5px;
}
div#api-response.content.active {
background-color: #313131;
}
</style>
</head>
<body class="panel">
<h1>GPT Context</h1>
<form id="questionForm">
<div>
<div class="form-group">
<label for="question">Enter your question:</label>
<input type="text" id="question" name="question" required>
<button type="submit">Submit</button>
<button type="button" onclick="clearSelectedFiles()">Clear</button>
<button type="button" onclick="refreshSelectedFiles()">Refresh</button>
<input type="text" id="question" name="question" placeholder="Enter your question" required>
<div class="button-options">
<button type="submit">Submit</button>
<button type="button" onclick="clearSelectedFiles()">Clear</button>
<button type="button" onclick="refreshSelectedFiles()">Refresh</button>
</div>
</div>
<div>
<div><pre>${question ? question : ''}</pre></div>
${
apiResponse ? `<div><pre>${apiResponse}</pre></div>` : ''
}
<div class="form-group">
<div class="collapsible" onclick="toggleApiResponse()">
API Response
</div>
<div>
<h2>Selected Files:</h2>
${fileList}
<div class="content" id="api-response">
<div id="question-rep">
<p>${question ? '> ' + question : null}</p>
</div>
${
apiResponse ? `
<div id="rendered">
<p>${apiResponse}</p>
</div>
` : null
}
</div>
</div>
<div class="form-group">
<label for="selected-files">Selected Files:</label>
<div class="file-list">
${fileList ? fileList : '<p class="no-files">No files selected</p>'}
</div>
</div>
<script>
const vscode = acquireVsCodeApi();
@ -227,6 +479,21 @@ function getWebviewContent(apiResponse = '', question = '') {
});
}
function toggleApiResponse() {
const apiResponse = document.getElementById('api-response');
apiResponse.classList.toggle('active');
const content = apiResponse;
const collapsible = apiResponse.previousElementSibling;
if (content.style.display === 'block') {
content.style.display = 'none';
collapsible.classList.remove('active');
} else {
content.style.display = 'block';
collapsible.classList.add('active');
}
}
const form = document.getElementById('questionForm');
form.addEventListener('submit', event => {
event.preventDefault();
@ -252,6 +519,7 @@ function getWebviewContent(apiResponse = '', question = '') {
}
// Activates the extension
function activate(context) {
context.subscriptions.push(addFilesCommand);
@ -260,6 +528,41 @@ 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 === '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();
} else if (message.command === 'submitQuestion') {
await handleQuestionSubmission(webviewView, message.text, message.selectedUris);
}
});
}
};
context.subscriptions.push(vscode.window.registerWebviewViewProvider('gpt-context-sidebar', provider));
}
exports.activate = activate;

1
images/files.svg Normal file
View File

@ -0,0 +1 @@
<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M2 11h1V6.99H2V11zm1-5.01V5.5l.5-.5h4.43l.43.25.43.75h5.71l.5.5v8l-.5.5h-11l-.5-.5V12H1.5l-.5-.5v-9l.5-.5h4.42l.44.25.43.75h5.71l.5.5V6l-1-.03V4H6.5l-.43-.25L5.64 3H2v2.99h1zm5.07.76L7.64 6H4v3h3.15l.41-.74L8 8h6V7H8.5l-.43-.25zM7.45 10H4v4h10V9H8.3l-.41.74-.44.26z"/></svg>

After

Width:  |  Height:  |  Size: 426 B

View File

@ -2,16 +2,37 @@
"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"
"Machine Learning",
"Debuggers",
"Formatters",
"Linters",
"Programming Languages",
"Testing",
"Snippets"
],
"tags": [
"16k",
"GPT",
"ai",
"testing",
"debugging",
"files",
"api"
],
"relatedTags": [
"Artificial Intelligence",
"Natural Language Processing",
"Code editor"
],
"activationEvents": [
"onCommand:extension.addFilesToGPTContext",
"onCommand:extension.openGPTContextPanel"
"onCommand:extension.openGPTContextPanel",
"onCommand:extension.gpt-context-sidebar"
],
"main": "./extension.js",
"contributes": {
@ -34,6 +55,15 @@
"title": "Clear Selected Files"
}
],
"viewsContainers" : {
"activitybar": [
{
"id": "gpt-contextfiles-sidebar-view",
"title": "GPT Context",
"icon": "images/files.svg"
}
]
},
"menus": {
"explorer/context": [
{
@ -50,8 +80,17 @@
"name": "Selected Files",
"when": "explorerResourceIsFolder && explorerViewletVisible"
}
],
"gpt-contextfiles-sidebar-view": [
{
"type": "webview",
"id": "gpt-context-sidebar",
"name": "Process Queries",
"icon": "images/files.svg",
"contextualTitle": "GPTContext"
}
]
}
}
},
"scripts": {
"lint": "eslint .",