Skip to content

Commit 539db98

Browse files
committed
add option to disable markup and cell outputs
1 parent c36cdff commit 539db98

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

package.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@
3636
{
3737
"title": "Llama coder",
3838
"properties": {
39+
"notebook.includeMarkup": {
40+
"type": "boolean",
41+
"default": true,
42+
"description": "Include markup cell types in prompt"
43+
},
44+
"notebook.includeCellOutputs": {
45+
"type": "boolean",
46+
"default": false,
47+
"description": "Include Cell previous output results in the prompt"
48+
},
49+
"notebook.cellOutputLimit": {
50+
"type": "number",
51+
"default": 256,
52+
"description": "truncate cell output result if exceeds this limit"
53+
},
3954
"inference.endpoint": {
4055
"type": "string",
4156
"default": "",
@@ -121,7 +136,7 @@
121136
"pretest": "yarn run compile && yarn run lint",
122137
"lint": "eslint src --ext ts",
123138
"test": "jest",
124-
"package": "vsce package"
139+
"package": "npx @vscode/vsce package"
125140
},
126141
"devDependencies": {
127142
"@types/jest": "^29.5.10",

src/config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ class Config {
4545
};
4646
}
4747

48+
// Notebook
49+
get notebook() {
50+
let config = vscode.workspace.getConfiguration('notebook');
51+
52+
let includeMarkup = config.get('includeMarkup') as boolean;
53+
let includeCellOutputs = config.get('includeCellOutputs') as boolean;
54+
let cellOutputLimit = config.get('cellOutputLimit') as number;
55+
return {
56+
includeMarkup,
57+
includeCellOutputs,
58+
cellOutputLimit,
59+
};
60+
}
61+
4862
get #config() {
4963
return vscode.workspace.getConfiguration('inference');
5064
};

src/prompts/preparePrompt.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import vscode from 'vscode';
22
import { detectLanguage } from './processors/detectLanguage';
33
import { fileHeaders } from './processors/fileHeaders';
44
import { languages } from './processors/languages';
5+
import { config } from '../config';
56

67
var decoder = new TextDecoder("utf8");
78

@@ -13,12 +14,13 @@ function getNotebookDocument(document: vscode.TextDocument): vscode.NotebookDocu
1314
export async function preparePrompt(document: vscode.TextDocument, position: vscode.Position, context: vscode.InlineCompletionContext) {
1415

1516
// Load document text
16-
console.log(document);
1717
let text = document.getText();
1818
let offset = document.offsetAt(position);
1919
let prefix = text.slice(0, offset);
2020
let suffix: string = text.slice(offset);
2121

22+
let notebookConfig = config.notebook;
23+
2224
// If this is a notebook, add the surrounding cells to the prefix and suffix
2325
let notebookDocument = getNotebookDocument(document);
2426
let language = detectLanguage(document.uri.fsPath, document.languageId);
@@ -43,21 +45,26 @@ export async function preparePrompt(document: vscode.TextDocument, position: vsc
4345

4446
// add the markdown cell output to the prompt as a comment
4547
if (cell.kind === vscode.NotebookCellKind.Markup && commentStart) {
46-
for (const line of cell.document.getText().split('\n')) {
47-
out += `\n${commentStart}${line}`;
48+
if (notebookConfig.includeMarkup) {
49+
for (const line of cell.document.getText().split('\n')) {
50+
out += `\n${commentStart}${line}`;
51+
}
4852
}
4953
} else {
5054
out += cell.document.getText();
5155
}
5256

5357
// if there is any outputs add them to the prompt as a comment
54-
if (cell.kind === vscode.NotebookCellKind.Code && commentStart) {
55-
console.log(cell.outputs);
58+
const addCellOutputs = notebookConfig.includeCellOutputs
59+
&& beforeCurrentCell
60+
&& cell.kind === vscode.NotebookCellKind.Code
61+
&& commentStart;
62+
if (addCellOutputs) {
5663
let cellOutputs = cell.outputs
5764
.map(x => x.items
5865
.filter(x => x.mime === 'text/plain')
5966
.map(x => decoder.decode(x.data))
60-
.map(x => x.slice(0, 256).split('\n'))) // limit to 256 characters
67+
.map(x => x.slice(0, notebookConfig.cellOutputLimit).split('\n')))
6168
.flat(3);
6269

6370
if (cellOutputs.length > 0) {

0 commit comments

Comments
 (0)