Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/notebook/common/alternativeContentProvider.ts
13401 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import type { CancellationToken, NotebookCell, NotebookDocument } from 'vscode';
7
import { Uri } from '../../../vscodeTypes';
8
import { AlternativeNotebookDocument } from './alternativeNotebookDocument';
9
import { LineOfCellText, LineOfText } from './helpers';
10
11
12
export abstract class BaseAlternativeNotebookContentProvider {
13
constructor(public readonly kind: 'xml' | 'text' | 'json') { }
14
15
/**
16
* Give the code for a cell, strips the cell markers and returns the code.
17
* XML and Jupytext formats have cell markers and this allows stripped those markers.
18
*/
19
public abstract stripCellMarkers(text: string): string;
20
21
/**
22
* Generate the Document of the notebook document that is LLM friendly.
23
*/
24
public abstract getAlternativeDocument(notebook: NotebookDocument, excludeMarkdownCells?: boolean): AlternativeNotebookDocument;
25
26
/**
27
* Gets the alternative Document with specific text representation which
28
* may have been model-edited.
29
*/
30
public abstract getAlternativeDocumentFromText(text: string, notebook: NotebookDocument): AlternativeNotebookDocument;
31
32
/**
33
* Generate the summary of the structure of the notebook document that is LLM friendly.
34
* & includes just the cells that are passed in.
35
* This is used to help the LLM understand the structure of the notebook, without including the entire code of all cells.
36
*/
37
public abstract getSummaryOfStructure(notebook: NotebookDocument, cellsToInclude: NotebookCell[], existingCodeMarker: string): string;
38
39
/**
40
* Given the input stream of response parts, parse the response and return an async iterable of lines of text for a given cell.
41
* We accept a NotebookDocument or a Uri.
42
* This is because its possible the Notebook may not have been created/loaded as of yet.
43
* I.e. for new Notebooks, we can emity the Insert Cell Edits without the notebook being created.
44
*/
45
public abstract parseAlternateContent(notebookOrUri: NotebookDocument | Uri, inputStream: AsyncIterable<LineOfText>, token: CancellationToken): AsyncIterable<LineOfCellText>;
46
47
}
48
49