support modelSelector option when running inline chat (#279976)

https://github.com/microsoft/vscode-copilot-evaluation/issues/894
This commit is contained in:
Johannes Rieken
2025-11-28 15:51:19 +01:00
committed by GitHub
parent 898431e0c2
commit c426bc9e9a
3 changed files with 43 additions and 8 deletions

View File

@@ -58,6 +58,7 @@ import { IChatService } from '../../chat/common/chatService.js';
import { IChatRequestVariableEntry, IDiagnosticVariableEntryFilterData } from '../../chat/common/chatVariableEntries.js';
import { isResponseVM } from '../../chat/common/chatViewModel.js';
import { ChatAgentLocation } from '../../chat/common/constants.js';
import { ILanguageModelChatSelector, ILanguageModelsService, isILanguageModelChatSelector } from '../../chat/common/languageModels.js';
import { isNotebookContainingCellEditor as isNotebookWithCellEditor } from '../../notebook/browser/notebookEditor.js';
import { INotebookEditorService } from '../../notebook/browser/services/notebookEditorService.js';
import { ICellEditOperation } from '../../notebook/common/notebookCommon.js';
@@ -91,6 +92,7 @@ const enum Message {
}
export abstract class InlineChatRunOptions {
initialSelection?: ISelection;
initialRange?: IRange;
message?: string;
@@ -98,9 +100,15 @@ export abstract class InlineChatRunOptions {
autoSend?: boolean;
existingSession?: Session;
position?: IPosition;
modelSelector?: ILanguageModelChatSelector;
static isInlineChatRunOptions(options: any): options is InlineChatRunOptions {
const { initialSelection, initialRange, message, autoSend, position, existingSession, attachments: attachments } = <InlineChatRunOptions>options;
static isInlineChatRunOptions(options: unknown): options is InlineChatRunOptions {
if (typeof options !== 'object' || options === null) {
return false;
}
const { initialSelection, initialRange, message, autoSend, position, existingSession, attachments, modelSelector } = <InlineChatRunOptions>options;
if (
typeof message !== 'undefined' && typeof message !== 'string'
|| typeof autoSend !== 'undefined' && typeof autoSend !== 'boolean'
@@ -109,9 +117,11 @@ export abstract class InlineChatRunOptions {
|| typeof position !== 'undefined' && !Position.isIPosition(position)
|| typeof existingSession !== 'undefined' && !(existingSession instanceof Session)
|| typeof attachments !== 'undefined' && (!Array.isArray(attachments) || !attachments.every(item => item instanceof URI))
|| typeof modelSelector !== 'undefined' && !isILanguageModelChatSelector(modelSelector)
) {
return false;
}
return true;
}
}
@@ -1270,6 +1280,7 @@ export class InlineChatController2 implements IEditorContribution {
@IChatAttachmentResolveService private readonly _chatAttachmentResolveService: IChatAttachmentResolveService,
@IEditorService private readonly _editorService: IEditorService,
@IMarkerDecorationsService private readonly _markerDecorationsService: IMarkerDecorationsService,
@ILanguageModelsService private readonly _languageModelService: ILanguageModelsService,
@IChatService chatService: IChatService,
) {
@@ -1520,10 +1531,6 @@ export class InlineChatController2 implements IEditorContribution {
this._zone.rawValue?.widget.focus();
}
markActiveController() {
this._isActiveController.set(true, undefined);
}
async run(arg?: InlineChatRunOptions): Promise<boolean> {
assertType(this._editor.hasModel());
@@ -1536,7 +1543,7 @@ export class InlineChatController2 implements IEditorContribution {
existingSession.dispose();
}
this.markActiveController();
this._isActiveController.set(true, undefined);
const session = await this._inlineChatSessions.createSession2(this._editor, uri, CancellationToken.None);
@@ -1572,6 +1579,17 @@ export class InlineChatController2 implements IEditorContribution {
}));
delete arg.attachments;
}
if (arg.modelSelector) {
const id = (await this._languageModelService.selectLanguageModels(arg.modelSelector, false)).sort().at(0);
if (!id) {
throw new Error(`No language models found matching selector: ${JSON.stringify(arg.modelSelector)}.`);
}
const model = this._languageModelService.lookupLanguageModel(id);
if (!model) {
throw new Error(`Language model not loaded: ${id}.`);
}
this._zone.value.widget.chatWidget.input.setCurrentLanguageModel({ metadata: model, identifier: id });
}
if (arg.message) {
this._zone.value.widget.chatWidget.setInput(arg.message);
if (arg.autoSend) {