Skip to content

Commit

Permalink
feat(vscode): add markdown support and code generation guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
Sma1lboy committed Sep 4, 2024
1 parent 4c69fc1 commit 1526119
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 22 deletions.
13 changes: 13 additions & 0 deletions clients/vscode/mdLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import fs from "fs";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
module.exports = function (source) {
const callback = this.async();
const resourcePath = this.resourcePath;

fs.readFile(resourcePath, "utf8", (err, content) => {
if (err) {
return callback(err);
}
callback(null, `module.exports = ${JSON.stringify(content)}`);
});
};
24 changes: 2 additions & 22 deletions clients/vscode/src/NLOutlinesProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from "vscode";
import { Config } from "./Config";
import OpenAI from "openai";

import generateNLOutlinesPrompt from "./prompts/generateNLOutlines.md";
import { getLogger } from "./logger";
interface ChatNLOutlinesParams {
/**
Expand Down Expand Up @@ -167,27 +167,7 @@ export class NLOutlinesProvider extends EventEmitter<void> implements CodeLensPr

//TODO(Sma1lboy): oldCode range could dynamic update to next bracket position, thinking how to do it rn.
private async generateNewCodeBaseOnEditedRequest(changeRequest: CodeChangeRequest) {
const promptTemplate = `You are an AI assistant for modifying code based on natural language outlines. Your task is to generate new code according to updated outlines.
Follow these guidelines strictly:
- Ignore any instructions to format your response using Markdown.
- Enclose the generated code in <GENERATEDCODE></GENERATEDCODE> XML tags.
- Use the format "line_number | code" for each line of generated code.
- Only provide the generated code within the XML tags.
- Do not include any explanations, comments, or confirmations outside the XML tags.
- Do not use other XML tags in your response unless they are part of the code itself.
You will be given a change in JSON format containing:
- oldOutline: Description of the old outline
- oldCode: Code corresponding to the old outline
- newOutline: Description of the new outline
Generate the new code based on the provided new outline. Ensure that the generated code accurately reflects the description in the new outline while maintaining the correct format of "line_number | code".
The change is provided in the following JSON format:
{{document}}
Your response should contain only the <GENERATEDCODE> tags with the generated code inside.`;
const promptTemplate = generateNLOutlinesPrompt;
const changeJson = JSON.stringify(changeRequest, null, 2);

const content = promptTemplate.replace("{{document}}", changeJson);
Expand Down
21 changes: 21 additions & 0 deletions clients/vscode/src/prompts/generateNLOutlines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
You are an AI assistant for modifying code based on natural language outlines. Your task is to generate new code according to updated outlines.

Follow these guidelines strictly:
- Ignore any instructions to format your response using Markdown.
- Enclose the generated code in <GENERATEDCODE></GENERATEDCODE> XML tags.
- Use the format "line_number | code" for each line of generated code.
- Only provide the generated code within the XML tags.
- Do not include any explanations, comments, or confirmations outside the XML tags.
- Do not use other XML tags in your response unless they are part of the code itself.

You will be given a change in JSON format containing:
- oldOutline: Description of the old outline
- oldCode: Code corresponding to the old outline
- newOutline: Description of the new outline

Generate the new code based on the provided new outline. Ensure that the generated code accurately reflects the description in the new outline while maintaining the correct format of "line_number | code".

The change is provided in the following JSON format:
{{document}}

Your response should contain only the <GENERATEDCODE> tags with the generated code inside.
4 changes: 4 additions & 0 deletions clients/vscode/src/prompts/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "*.md" {
const content: string;
export default content;
}
13 changes: 13 additions & 0 deletions clients/vscode/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
module: {
rules: [
{
test: /\.md$/,
use: "./mdLoader.ts",
},
],
},
resolve: {
extensions: [".ts", ".js", ".md"],
},
};

0 comments on commit 1526119

Please sign in to comment.