Skip to content

Commit

Permalink
bug fix due to VSCode 1.75.0 update
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Zhang committed Feb 8, 2023
1 parent bda763d commit 4dfeb47
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ Scribe AI is a ChatGPT-like extension for VS Code. Now you can have an AI chatbo

 

# 📢 v1.1.1 Update: ChatGPT Now Available
You can now choose ChatGPT as the model you want to use by heading to `Code` -> `Preferences` -> `Settings`, find `ScribeAI` under `Extensions` and choose `ChatGPT` as your model.
 
# 📢 v1.1.3 Update
- With latest VSCode 1.75.0 update a bug has been introduced where the highlighted code couldn't be retrieved via vscode API. This bug has now been fixed and "Ask AI" and "AI Edit" extension features should be working now in latest v1.1.3.

- The leaked ChatGPT model has been taken down by OpenAI and it is no longer available. Only the GPT3 models are available for now.

The GPT3 models are also now more performant thanks to experimentation with prompt engineering and tuning additional parameters. You can now expect to get longer and more detailed responses.
- The GPT3 models are also now more performant thanks to experimentation with prompt engineering and tuning additional parameters. You can now expect to get longer and more detailed responses.


 
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "scribeai",
"displayName": "ScribeAI - ChatGPT & GPT extension for VSCode",
"description": "🚀 Use ChatGPT & GPT right inside VSCode to enhance and automate your coding with AI-powered assistance",
"version": "1.1.2",
"version": "1.1.3",
"publisher": "AndrewZhang",
"private": true,
"icon": "resources/chatbot.png",
Expand Down
36 changes: 15 additions & 21 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,14 @@ export async function activate(context: vscode.ExtensionContext) {
* @param thread
* @returns
*/
function generatePromptV1(question: string, thread: vscode.CommentThread) {
async function generatePromptV1(question: string, thread: vscode.CommentThread) {
const rolePlay =
"I want you to act as a highly intelligent AI chatbot that has deep understanding of any coding language and its API documentations. I will provide you with a code block and your role is to provide a comprehensive answer to any questions or requests that I will ask about the code block. Please answer in as much detail as possible and not be limited to brevity. It is very important that you provide verbose answers.";
//const codeBlock = "class Log:\n def __init__(self, path):\n dirname = os.path.dirname(path)\n os.makedirs(dirname, exist_ok=True)\n f = open(path, \"a+\")\n\n # Check that the file is newline-terminated\n size = os.path.getsize(path)\n if size > 0:\n f.seek(size - 1)\n end = f.read(1)\n if end != \"\\n\":\n f.write(\"\\n\")\n self.f = f\n self.path = path\n\n def log(self, event):\n event[\"_event_id\"] = str(uuid.uuid4())\n json.dump(event, self.f)\n self.f.write(\"\\n\")\n\n def state(self):\n state = {\"complete\": set(), \"last\": None}\n for line in open(self.path):\n event = json.loads(line)\n if event[\"type\"] == \"submit\" and event[\"success\"]:\n state[\"complete\"].add(event[\"id\"])\n state[\"last\"] = event\n return state";
const codeBlock = getCommentThreadCode(thread);
const codeBlock = await getCommentThreadCode(thread);

let conversation = "Human: Who are you?\n\nAI: I am a intelligent AI chatbot\n\n";

for (let i = 0; i < thread.comments.length; i++) {
for (let i = Math.max(0, thread.comments.length - 8); i < thread.comments.length; i++) {
if (thread.comments[i].label !== "NOTE") {
if (thread.comments[i].author.name === "VS Code") {
conversation += `Human: ${thread.comments[i].body}\n\n`;
Expand All @@ -233,7 +232,7 @@ export async function activate(context: vscode.ExtensionContext) {
}
conversation += `Human: ${question}\n\nAI: `;

return rolePlay + "\n" + codeBlock + "\n\n\n" + conversation;
return rolePlay + "\n```\n" + codeBlock + "\n```\n\n\n" + conversation;
}

/**
Expand All @@ -250,8 +249,10 @@ export async function activate(context: vscode.ExtensionContext) {
*/
function generatePromptV2(question: string, thread: vscode.CommentThread) {
const rolePlay =
"I want you to act as a highly intelligent AI chatbot that has deep understanding of any coding language and its API documentations. I will provide you with a code block and your role is to provide a comprehensive answer to any questions or requests that I will ask about the code block. Please answer in as much detail as possible and not be limited to brevity. It is very important that you provide verbose answers.";
//const codeBlock = "class Log:\n def __init__(self, path):\n dirname = os.path.dirname(path)\n os.makedirs(dirname, exist_ok=True)\n f = open(path, \"a+\")\n\n # Check that the file is newline-terminated\n size = os.path.getsize(path)\n if size > 0:\n f.seek(size - 1)\n end = f.read(1)\n if end != \"\\n\":\n f.write(\"\\n\")\n self.f = f\n self.path = path\n\n def log(self, event):\n event[\"_event_id\"] = str(uuid.uuid4())\n json.dump(event, self.f)\n self.f.write(\"\\n\")\n\n def state(self):\n state = {\"complete\": set(), \"last\": None}\n for line in open(self.path):\n event = json.loads(line)\n if event[\"type\"] == \"submit\" and event[\"success\"]:\n state[\"complete\"].add(event[\"id\"])\n state[\"last\"] = event\n return state";
"I want you to act as a highly intelligent AI chatbot that has deep understanding of any coding language and its API documentations. "
+ "I will provide you with a code block and your role is to provide a comprehensive answer to any questions or requests that I will ask about the code block. Please answer in as much detail as possible and not be limited to brevity. It is very important that you provide verbose answers. (When responding to the following prompt, please make sure to properly style your response using Github Flavored Markdown."
+ " Use markdown syntax for things like headings, lists, colored text, code blocks, highlights etc. Make sure not to mention markdown or stying in your actual response."
+ " Try to write code inside a single code block if possible)";
const codeBlock = getCommentThreadCode(thread);

let conversation = "Human: Who are you?\n\nAI: I am a intelligent AI chatbot\n\n";
Expand All @@ -264,14 +265,10 @@ export async function activate(context: vscode.ExtensionContext) {
* @param thread
* @returns
*/
function getCommentThreadCode(thread: vscode.CommentThread) {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return; // No open text editor
}
const document = editor.document;
async function getCommentThreadCode(thread: vscode.CommentThread) {
const document = await vscode.workspace.openTextDocument(thread.uri);
// Get selected code for the comment thread
return document.getText(thread.range);
return document.getText(thread.range).trim();
}

/**
Expand All @@ -283,9 +280,8 @@ export async function activate(context: vscode.ExtensionContext) {
*/
async function askAI(reply: vscode.CommentReply) {
const question = reply.text.trim();
const code = getCommentThreadCode(reply.thread);
const thread = reply.thread;
const prompt = generatePromptV1(question, thread);
const prompt = await generatePromptV1(question, thread);
const model = vscode.workspace.getConfiguration('scribeai').get('models') + "";
const humanComment = new NoteComment(question, vscode.CommentMode.Preview, { name: 'VS Code', iconPath: vscode.Uri.parse("https://img.icons8.com/fluency/96/null/user-male-circle.png") }, thread, thread.comments.length ? 'canDelete' : undefined);
thread.comments = [...thread.comments, humanComment];
Expand All @@ -301,9 +297,8 @@ export async function activate(context: vscode.ExtensionContext) {
apiKey: vscode.workspace.getConfiguration('scribeai').get('ApiKey'),
}));
}

const response = await openai.createCompletion({
model: model === "ChatGPT" ? "text-chat-davinci-002-20230126" : model,
model: model === "ChatGPT" ? "text-chat-davinci-002-20221122" : model,
prompt: prompt,
//prompt: generatePromptV2(question, thread),
temperature: 0,
Expand All @@ -329,7 +324,7 @@ export async function activate(context: vscode.ExtensionContext) {
*/
async function aiEdit(reply: vscode.CommentReply) {
const question = reply.text.trim();
const code = getCommentThreadCode(reply.thread);
const code = await getCommentThreadCode(reply.thread);
const thread = reply.thread;

// If openai is not initialized initialize it with existing API Key
Expand All @@ -352,11 +347,10 @@ export async function activate(context: vscode.ExtensionContext) {
top_p: 1.0,
});
if (response.data.choices[0].text) {
const editor = vscode.window.activeTextEditor;
const editor = await vscode.window.showTextDocument(thread.uri);
if (!editor) {
return; // No open text editor
}
const document = editor.document;
editor.edit(editBuilder => {
editBuilder.replace(thread.range, response.data.choices[0].text + "");
});
Expand Down

0 comments on commit 4dfeb47

Please sign in to comment.