-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from restlessronin/send-files-as-context
Add all open workspace files as context for request
- Loading branch information
Showing
6 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as vscode from "vscode"; | ||
import { getActiveEditor } from "../../vscode/getActiveEditor"; | ||
|
||
export const getOpenFiles = async () => { | ||
const contextDocuments = vscode.workspace.textDocuments.filter( | ||
(document) => document.uri.scheme === "file" | ||
); | ||
|
||
return contextDocuments.map((document) => { | ||
return { | ||
name: document.fileName, | ||
language: document.languageId, | ||
content: document.getText(), | ||
}; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
# Explain Code | ||
|
||
Explain the selected code. | ||
|
||
## Template | ||
|
||
### Configuration | ||
|
||
```json conversation-template | ||
{ | ||
"id": "explain-code-with-context", | ||
"engineVersion": 0, | ||
"label": "Explain Code with Context", | ||
"description": "Explain the selected code in context of all the open files.", | ||
"tags": ["debug", "understand"], | ||
"header": { | ||
"title": "Explain Code ({{location}}) in context", | ||
"icon": { | ||
"type": "codicon", | ||
"value": "book" | ||
} | ||
}, | ||
"variables": [ | ||
{ | ||
"name": "openFiles", | ||
"time": "conversation-start", | ||
"type": "context" | ||
}, | ||
{ | ||
"name": "selectedText", | ||
"time": "conversation-start", | ||
"type": "selected-text", | ||
"constraints": [{ "type": "text-length", "min": 1 }] | ||
}, | ||
{ | ||
"name": "location", | ||
"time": "conversation-start", | ||
"type": "selected-location-text" | ||
}, | ||
{ | ||
"name": "firstMessage", | ||
"time": "message", | ||
"type": "message", | ||
"property": "content", | ||
"index": 0 | ||
}, | ||
{ | ||
"name": "lastMessage", | ||
"time": "message", | ||
"type": "message", | ||
"property": "content", | ||
"index": -1 | ||
} | ||
], | ||
"initialMessage": { | ||
"placeholder": "Generating explanation", | ||
"maxTokens": 2048 | ||
}, | ||
"response": { | ||
"maxTokens": 2048, | ||
"stop": ["Bot:", "Developer:"] | ||
} | ||
} | ||
``` | ||
|
||
### Initial Message Prompt | ||
|
||
```template-initial-message | ||
## Instructions | ||
Summarize the code below (emphasizing its key functionality) using the contents of the open files as context. | ||
## Selected Code | ||
\`\`\`{{language}} | ||
{{selectedText}} | ||
\`\`\` | ||
## Open Files | ||
{{#each openFiles}} | ||
### File: {{name}} | ||
\`\`\`{{language}} | ||
{{content}} | ||
\`\`\` | ||
{{/each}} | ||
## Task | ||
Summarize the code at a high level (including goal and purpose) with an emphasis on its key functionality. Use the contents of the open files as context. | ||
## Response | ||
``` | ||
|
||
### Response Prompt | ||
|
||
```template-response | ||
## Instructions | ||
Continue the conversation below. | ||
Pay special attention to the current developer request. | ||
## Current Request | ||
Developer: {{lastMessage}} | ||
{{#if selectedText}} | ||
## Selected Code | ||
\`\`\`{{language}} | ||
{{selectedText}} | ||
\`\`\` | ||
{{/if}} | ||
## Code Summary | ||
{{firstMessage}} | ||
## Conversation | ||
{{#each messages}} | ||
{{#if (neq @index 0)}} | ||
{{#if (eq author "bot")}} | ||
Bot: {{content}} | ||
{{else}} | ||
Developer: {{content}} | ||
{{/if}} | ||
{{/if}} | ||
{{/each}} | ||
## Task | ||
Write a response that continues the conversation. | ||
Stay focused on current developer request. | ||
Consider the possibility that there might not be a solution. | ||
Ask for clarification if the message does not make sense or more input is needed. | ||
Use the style of a documentation article. | ||
Omit any links. | ||
Include code snippets (using Markdown) and examples where appropriate. | ||
## Response | ||
Bot: | ||
``` |