Skip to content

Commit

Permalink
fix: correctly implement rendered function messages as User messages …
Browse files Browse the repository at this point in the history
…with `LanguageModelChatMessageFunctionResultPart` content (#57)
  • Loading branch information
joyceerhl authored Jun 6, 2024
1 parent 7e4cb3d commit 1dab6fc
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vscode/prompt-tsx",
"version": "0.2.0-alpha",
"version": "0.2.1-alpha",
"description": "Declare LLM prompts with TSX",
"main": "./dist/base/index.js",
"types": "./dist/base/index.d.ts",
Expand Down
5 changes: 5 additions & 0 deletions src/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ export function toVsCodeChatMessages(messages: ChatMessage[]) {
return vscode.LanguageModelChatMessage.Assistant(m.content, m.name);
case ChatRole.User:
return vscode.LanguageModelChatMessage.User(m.content, m.name);
case ChatRole.Function: {
const message = vscode.LanguageModelChatMessage.User('');
message.content2 = new vscode.LanguageModelChatMessageFunctionResultPart(m.name, m.content);
return message;
}
default:
throw new Error(`Converting chat message with role ${m.role} to VS Code chat message is not supported.`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/base/tokenizer/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class AnyTokenizer implements ITokenizer {
case ChatRole.User: return 1;
case ChatRole.Assistant: return 2;
case ChatRole.System: return 1;
case ChatRole.Function: return 5;
case ChatRole.Function: return 1;
}
}
}
58 changes: 58 additions & 0 deletions src/base/vscode.proposed.lmTools.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

declare module 'vscode' {

// TODO@API capabilities

export type JSONSchema = object;

// API -> LM: an tool/function that is available to the language model
export interface LanguageModelChatFunction {
name: string;
description: string;
parametersSchema: JSONSchema;
}

// API -> LM: add tools as request option
export interface LanguageModelChatRequestOptions {
// TODO@API this will a heterogeneous array of different types of tools
tools?: LanguageModelChatFunction[];
}

// LM -> USER: function that should be used
export class LanguageModelChatResponseFunctionUsePart {
name: string;
parameters: any;

constructor(name: string, parameters: any);
}

// LM -> USER: text chunk
export class LanguageModelChatResponseTextPart {
value: string;

constructor(value: string);
}

export interface LanguageModelChatResponse {

stream: AsyncIterable<LanguageModelChatResponseTextPart | LanguageModelChatResponseFunctionUsePart>;
}


// USER -> LM: the result of a function call
export class LanguageModelChatMessageFunctionResultPart {
name: string;
content: string;
isError: boolean;

constructor(name: string, content: string, isError?: boolean);
}

export interface LanguageModelChatMessage {
content2: string | LanguageModelChatMessageFunctionResultPart;
}
}
11 changes: 0 additions & 11 deletions src/base/vscodeTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,6 @@ export enum LanguageModelChatMessageRole {
* The assistant role, e.g. the language model generating responses.
*/
Assistant = 2,

/**
* The tool role, e.g. the language model using a tool.
*/
Tool = 4,

/**
* The function role, e.g. the language model calling a function.
*/
Function = 5,

}

/**
Expand Down

0 comments on commit 1dab6fc

Please sign in to comment.