Skip to content

Commit 2db5c05

Browse files
authored
Fallback to GPT-5.4-mini and cache the model used. (#14369)
* Fallback to GPT-5.4-mini and cache the model used.
1 parent bc9a72c commit 2db5c05

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

Extension/src/LanguageServer/Providers/CopilotHoverProvider.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class CopilotHoverProvider implements vscode.HoverProvider {
2727
private cancelledPosition: vscode.Position | undefined;
2828
private content: string | undefined;
2929
private chatModel: vscode.LanguageModelChat | undefined;
30+
private chatModelId: string | undefined; // Save the selected model ID to avoid trying the same unavailable model repeatedly.
3031
// Flag to avoid querying the LanguageModelChat repeatedly if no model is found
3132
private checkedChatModel: boolean = false;
3233
constructor(client: DefaultClient) {
@@ -41,13 +42,29 @@ export class CopilotHoverProvider implements vscode.HoverProvider {
4142
const vscodelm = getVSCodeLanguageModel();
4243
if (vscodelm) {
4344
try {
44-
// First look for GPT-4o which should be available to all
45-
// users and have a 0x multiplier on paid plans.
46-
// GTP-4o is faster than GPT-5-mini (which seems too slow for hover, e.g. 10+ seconds).
47-
let [model] = await vscodelm.selectChatModels({ ...modelSelector, id: 'gpt-4o' });
48-
if (!model) {
49-
// If GPT-4o is not available, fall back to the first available model.
50-
[model] = await vscodelm.selectChatModels(modelSelector);
45+
let model: vscode.LanguageModelChat | undefined;
46+
if (this.chatModelId === undefined) {
47+
// First look for GPT-4o which should be available to all
48+
// users and have a 0x multiplier on paid plans.
49+
// GPT-4o is faster than the x0 GPT-5-mini (which seems too slow for hover, e.g. 10+ seconds).
50+
this.chatModelId = 'gpt-4o';
51+
[model] = await vscodelm.selectChatModels({ ...modelSelector, id: this.chatModelId });
52+
if (!model) {
53+
// If GPT-4o is not available, fallback to GPT-5.4-mini (x0.33 and fast).
54+
this.chatModelId = 'gpt-5.4-mini';
55+
[model] = await vscodelm.selectChatModels({ ...modelSelector, id: this.chatModelId });
56+
}
57+
if (!model) {
58+
// If GPT-5.4-mini is not available, fallback to the first available model.
59+
this.chatModelId = 'default';
60+
[model] = await vscodelm.selectChatModels(modelSelector);
61+
}
62+
} else {
63+
if (this.chatModelId === 'default') {
64+
[model] = await vscodelm.selectChatModels(modelSelector);
65+
} else {
66+
[model] = await vscodelm.selectChatModels({ ...modelSelector, id: this.chatModelId });
67+
}
5168
}
5269
if (!model) {
5370
telemetry.logLanguageServerEvent('CopilotHoverNoModelSelected', { remoteName: vscode.env.remoteName || 'local' });

0 commit comments

Comments
 (0)