Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/intents/node/newNotebookIntent.contribution.ts
13399 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
import * as l10n from '@vscode/l10n';
6
import type * as vscode from 'vscode';
7
import { IResponsePart } from '../../../platform/chat/common/chatMLFetcher';
8
import { ChatLocation } from '../../../platform/chat/common/commonTypes';
9
import { IEndpointProvider } from '../../../platform/endpoint/common/endpointProvider';
10
import { IChatEndpoint } from '../../../platform/networking/common/networking';
11
import { CancellationToken } from '../../../util/vs/base/common/cancellation';
12
import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation';
13
import { Intent } from '../../common/constants';
14
import { IBuildPromptContext } from '../../prompt/common/intents';
15
import { IIntent, IIntentInvocation, IIntentInvocationContext, IntentLinkificationOptions, IResponseProcessorContext } from '../../prompt/node/intents';
16
import { PromptRenderer } from '../../prompts/node/base/promptRenderer';
17
import { NewNotebookPlanningPrompt } from '../../prompts/node/panel/newNotebook';
18
import { NewNotebookResponseProcessor } from './newNotebookIntent';
19
20
21
export class NewNotebookIntent implements IIntent {
22
static readonly ID = Intent.NewNotebook;
23
readonly id: string = Intent.NewNotebook;
24
readonly description = l10n.t('Create a new Jupyter Notebook');
25
readonly locations = [ChatLocation.Panel];
26
27
readonly commandInfo = {
28
allowsEmptyArgs: false,
29
yieldsTo: [
30
{ command: 'fix' },
31
{ command: 'explain' },
32
{ command: 'workspace' },
33
{ command: 'tests' },
34
],
35
defaultEnablement: true,
36
sampleRequest: l10n.t('How do I create a notebook to load data from a csv file?')
37
};
38
39
constructor(
40
@IEndpointProvider private readonly endpointProvider: IEndpointProvider,
41
@IInstantiationService private readonly instantiationService: IInstantiationService,
42
) { }
43
44
async invoke(invocationContext: IIntentInvocationContext): Promise<IIntentInvocation> {
45
const location = invocationContext.location;
46
const endpoint = await this.endpointProvider.getChatEndpoint(invocationContext.request);
47
48
return this.instantiationService.createInstance(NewNotebookPlanningInvocation, this, endpoint, location, invocationContext.request.prompt);
49
}
50
}
51
52
class NewNotebookPlanningInvocation implements IIntentInvocation {
53
54
readonly linkification: IntentLinkificationOptions = { disable: true };
55
56
private context: IBuildPromptContext | undefined;
57
58
constructor(
59
readonly intent: NewNotebookIntent,
60
readonly endpoint: IChatEndpoint,
61
readonly location: ChatLocation,
62
readonly query: string,
63
@IInstantiationService private readonly instantiationService: IInstantiationService,
64
) { }
65
66
async buildPrompt(promptContext: IBuildPromptContext, progress: vscode.Progress<vscode.ChatResponseProgressPart | vscode.ChatResponseReferencePart>, token: vscode.CancellationToken) {
67
this.context = promptContext;
68
69
const renderer = PromptRenderer.create(this.instantiationService, this.endpoint, NewNotebookPlanningPrompt, {
70
promptContext,
71
endpoint: this.endpoint,
72
});
73
74
return await renderer.render(progress, token);
75
}
76
77
processResponse(context: IResponseProcessorContext, inputStream: AsyncIterable<IResponsePart>, outputStream: vscode.ChatResponseStream, token: CancellationToken): Promise<void> {
78
outputStream.markdown(l10n.t('Creating a new notebook:\n'));
79
80
const responseProcessor = this.instantiationService.createInstance(NewNotebookResponseProcessor, this.endpoint, this.context);
81
82
return responseProcessor.processResponse(context, inputStream, outputStream, token);
83
}
84
}
85
86