Johannes Rieken 2024-10-22 12:52:51 +02:00 committed by GitHub
parent c50ff3b53a
commit b79ff2ede0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 10 deletions

View File

@ -4608,30 +4608,34 @@ export class LanguageModelChatMessage implements vscode.LanguageModelChatMessage
role: vscode.LanguageModelChatMessageRole;
// Temp to avoid breaking changes
content2: (string | LanguageModelToolResultPart | LanguageModelToolCallPart)[] | undefined;
content: (LanguageModelTextPart | LanguageModelToolResultPart | LanguageModelToolCallPart)[];
private _content: (LanguageModelTextPart | LanguageModelToolResultPart | LanguageModelToolCallPart)[];
get content(): (LanguageModelTextPart | LanguageModelToolResultPart | LanguageModelToolCallPart)[] {
// Temp for back-compat
if (this.content2) {
return this.content2.map(part => {
// Temp to avoid breaking changes
set content2(value: (string | LanguageModelToolResultPart | LanguageModelToolCallPart)[] | undefined) {
if (value) {
this.content = value.map(part => {
if (typeof part === 'string') {
return new LanguageModelTextPart(part);
}
return part;
});
}
}
return this._content;
get content2(): (string | LanguageModelToolResultPart | LanguageModelToolCallPart)[] | undefined {
return this.content.map(part => {
if (part instanceof LanguageModelTextPart) {
return part.value;
}
return part;
});
}
name: string | undefined;
constructor(role: vscode.LanguageModelChatMessageRole, content: string | (LanguageModelTextPart | LanguageModelToolResultPart | LanguageModelToolCallPart)[], name?: string) {
this.role = role;
this._content = typeof content === 'string' ? [new LanguageModelTextPart(content)] : content;
this.content = typeof content === 'string' ? [new LanguageModelTextPart(content)] : content;
this.name = name;
}
}

View File

@ -775,4 +775,20 @@ suite('ExtHostTypes', function () {
assert.throws(() => types.FileDecoration.validate({ badge: 'புன்சிரிப்போடு' }));
assert.throws(() => types.FileDecoration.validate({ badge: 'ããã' }));
});
test('No longer possible to set content on LanguageModelChatMessage', function () {
const m = types.LanguageModelChatMessage.Assistant('');
m.content = [new types.LanguageModelToolCallPart('toolCall.tool.name', 'toolCall.call.callId', 'toolCall.call.parameters')];
assert.equal(m.content.length, 1);
assert.equal(m.content2?.length, 1);
m.content2 = ['foo'];
assert.equal(m.content.length, 1);
assert.ok(m.content[0] instanceof types.LanguageModelTextPart);
assert.equal(m.content2?.length, 1);
assert.ok(typeof m.content2[0] === 'string');
});
});