Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/prompt/node/settingsEditorSearchResultsSelector.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 type { CancellationToken } from 'vscode';
6
import { ChatFetchResponseType, ChatLocation } from '../../../platform/chat/common/commonTypes';
7
import { IInteractionService } from '../../../platform/chat/common/interactionService';
8
import { SettingListItem } from '../../../platform/embeddings/common/vscodeIndex';
9
import { IChatEndpoint } from '../../../platform/networking/common/networking';
10
import { raceTimeout } from '../../../util/vs/base/common/async';
11
import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation';
12
import { PromptRenderer } from '../../prompts/node/base/promptRenderer';
13
import { SettingsEditorSuggestQueryPrompt } from '../../prompts/node/settingsEditor/settingsEditorSuggestQueryPrompt';
14
15
export class SettingsEditorSearchResultsSelector {
16
private static readonly DEFAULT_TIMEOUT = 10000; // 10 seconds
17
18
constructor(
19
@IInstantiationService private readonly instantiationService: IInstantiationService,
20
@IInteractionService private readonly interactionService: IInteractionService,
21
) { }
22
23
async selectTopSearchResults(endpoint: IChatEndpoint, query: string, settings: SettingListItem[], token: CancellationToken): Promise<string[]> {
24
if (token.isCancellationRequested) {
25
return [];
26
}
27
28
const promptRenderer = PromptRenderer
29
.create(
30
this.instantiationService,
31
endpoint,
32
SettingsEditorSuggestQueryPrompt,
33
{
34
query,
35
settings
36
}
37
);
38
const prompt = await promptRenderer.render(undefined, token);
39
40
this.interactionService.startInteraction();
41
const fetchResult = await raceTimeout(endpoint
42
.makeChatRequest(
43
'settingsEditorSearchSuggestions',
44
prompt.messages,
45
undefined,
46
token,
47
ChatLocation.Other,
48
undefined,
49
{
50
temperature: 0.1
51
}
52
), SettingsEditorSearchResultsSelector.DEFAULT_TIMEOUT);
53
54
if (token.isCancellationRequested || fetchResult === undefined || fetchResult.type !== ChatFetchResponseType.Success) {
55
return [];
56
}
57
58
const rawSuggestions = fetchResult.value;
59
return rawSuggestions.split('\n').map(setting => setting.trim());
60
}
61
}
62