Skip to content

Commit

Permalink
Update model family handling in getModelFamily function to use offici…
Browse files Browse the repository at this point in the history
…al way to determine the user selected model (#2)
  • Loading branch information
tspascoal authored Jan 2, 2025
1 parent d498884 commit d37f69e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 42 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "tspascoal-copilot-chat-parrot",
"displayName": "Parrot",
"description": "Parrot is a chat participant that repeats things",
"version": "0.0.10",
"version": "0.0.11",
"repository": {
"type": "git",
"url": "https://github.com/tspascoal/copilot-chat-parrot-extension.git"
Expand Down
10 changes: 5 additions & 5 deletions src/parrotchathandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ export function getCurrentSelectionLocation(): vscode.Location | vscode.Uri | nu
* @returns A tuple where the first element is the model name and the second element is the modified prompt.
*
*/
export function getModelFamily(request: any): string {
// Request should be vscode.ChatRequest but userSelectedModel is not in the type definition yet

if (request.userSelectedModel) {
return request.userSelectedModel.family;
export function getModelFamily(request: vscode.ChatRequest): string {
if (request.model) {
return request.model.family;
} else {
// This should only happen on old vscode versions that didn't
// supported the picker yet
return 'gpt-4o-mini';
}
}
Expand Down
56 changes: 25 additions & 31 deletions src/test/parrotchathandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,35 @@ import { addReferencesToResponse, generateLikeSystemPrompt, getModelFamily, getU
import * as vscode from 'vscode';
import * as sinon from 'sinon';

suite('getModelFamily Test Suite', () => {
test('Returns user selected model family if present', () => {
const request = {
userSelectedModel: {
family: 'gpt-3'
function getMockedRequest (family: string, id: string) : vscode.ChatRequest {
return {
model: {
family: family,
id: id,
name: family,
vendor: 'copilot',
version: '',
maxInputTokens: 0,
sendRequest: function (messages: vscode.LanguageModelChatMessage[], options?: vscode.LanguageModelChatRequestOptions, token?: vscode.CancellationToken): Thenable<vscode.LanguageModelChatResponse> {
throw new Error('Function not implemented.');
},
countTokens: function (text: string | vscode.LanguageModelChatMessage, token?: vscode.CancellationToken): Thenable<number> {
throw new Error('Function not implemented.');
}
};
const result = getModelFamily(request);
assert.strictEqual(result, 'gpt-3');
});

test('Returns default model family if user selected model is not present', () => {
const request = {};
const result = getModelFamily(request);
assert.strictEqual(result, 'gpt-4o-mini');
});

test('Returns default model family if user selected model is undefined', () => {
const request = { userSelectedModel: undefined };
const result = getModelFamily(request);
assert.strictEqual(result, 'gpt-4o-mini');
});
});
},
prompt: '',
command: '',
references: [],
toolReferences: [],
toolInvocationToken: (undefined as never)
}
}

suite('getModelFamily Test Suite', () => {
test('Returns default model family if userSelectedModel is null', () => {
const request = { userSelectedModel: null };
const result = getModelFamily(request);
assert.strictEqual(result, 'gpt-4o-mini');
});

test('Returns user selected model family if userSelectedModel.family is a non-empty string', () => {
const request = { userSelectedModel: { family: 'gpt-3.5' } };
test('Returns user selected model family if present', () => {
const request = getMockedRequest('gpt-3', 'gpt-3') ;
const result = getModelFamily(request);
assert.strictEqual(result, 'gpt-3.5');
assert.strictEqual(result, 'gpt-3');
});
});

Expand Down

0 comments on commit d37f69e

Please sign in to comment.