Skip to content

Commit

Permalink
Adopt LanguageModelToolCallPart arg reordering (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens authored Oct 24, 2024
1 parent f734669 commit cb7e203
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 34 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.3.0-alpha.11",
"version": "0.3.0-alpha.12",
"description": "Declare LLM prompts with TSX",
"main": "./dist/base/index.js",
"types": "./dist/base/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export function toVsCodeChatMessages(messages: ChatMessage[]) {
new vscode.LanguageModelTextPart(m.content),
...m.tool_calls.map(
tc =>
new vscode.LanguageModelToolCallPart(tc.function.name, tc.id, tc.function.arguments)
new vscode.LanguageModelToolCallPart(tc.id, tc.function.name, tc.function.arguments)
)
];
}
Expand Down
75 changes: 43 additions & 32 deletions src/base/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19801,14 +19801,14 @@ declare module 'vscode' {
*/
export class LanguageModelToolCallPart {
/**
* The name of the tool to call.
* The ID of the tool call. This is a unique identifier for the tool call within the chat request.
*/
name: string;
callId: string;

/**
* The ID of the tool call. This is a unique identifier for the tool call within the chat request.
* The name of the tool to call.
*/
callId: string;
name: string;

/**
* The parameters with which to call the tool.
Expand All @@ -19817,8 +19817,36 @@ declare module 'vscode' {

/**
* Create a new LanguageModelToolCallPart.
*
* @param callId The ID of the tool call.
* @param name The name of the tool to call.
* @param parameters The parameters with which to call the tool.
*/
constructor(callId: string, name: string, parameters: object);
}

/**
* The result of a tool call. This is the counterpart of a {@link LanguageModelToolCallPart tool call} and
* it can only be included in the content of a User message
*/
export class LanguageModelToolResultPart {
/**
* The ID of the tool call.
*
* *Note* that this should match the {@link LanguageModelToolCallPart.callId callId} of a tool call part.
*/
callId: string;

/**
* The value of the tool result.
*/
content: (LanguageModelTextPart | LanguageModelPromptTsxPart | unknown)[];

/**
* @param callId The ID of the tool call.
* @param content The content of the tool result.
*/
constructor(name: string, callId: string, parameters: object);
constructor(callId: string, content: (LanguageModelTextPart | LanguageModelPromptTsxPart)[]);
}

/**
Expand Down Expand Up @@ -19854,27 +19882,6 @@ declare module 'vscode' {
constructor(value: unknown);
}

/**
* The result of a tool call. Can only be included in the content of a User message.
*/
export class LanguageModelToolResultPart {
/**
* The ID of the tool call.
*/
callId: string;

/**
* The value of the tool result.
*/
content: (LanguageModelTextPart | LanguageModelPromptTsxPart | unknown)[];

/**
* @param callId The ID of the tool call.
* @param content The content of the tool result.
*/
constructor(callId: string, content: (LanguageModelTextPart | LanguageModelPromptTsxPart | unknown)[]);
}

/**
* A result returned from a tool invocation. If using `@vscode/prompt-tsx`, this result may be rendered using a `ToolResult`.
*/
Expand All @@ -19896,19 +19903,23 @@ declare module 'vscode' {
/**
* A token that can be passed to {@link lm.invokeTool} when invoking a tool inside the context of handling a chat request.
*/
export type ChatParticipantToolToken = unknown;
export type ChatParticipantToolToken = never;

/**
* Options provided for tool invocation.
*/
export interface LanguageModelToolInvocationOptions<T> {
/**
* When this tool is being invoked by a {@link ChatParticipant} within the context of a chat request, this token should be
* passed from {@link ChatRequest.toolInvocationToken}. In that case, a progress bar will be automatically shown for the
* tool invocation in the chat response view, and if the tool requires user confirmation, it will show up inline in the
* chat view. If the tool is being invoked outside of a chat request, `undefined` should be passed instead.
* An opaque object that ties a tool invocation to a chat request from a {@link ChatParticipant chat participant}.
*
* The _only_ way to get a valid tool invocation token is using the provided {@link ChatRequest.toolInvocationToken toolInvocationToken}
* from a chat request. In that case, a progress bar will be automatically shown for the tool invocation in the chat response view, and if
* the tool requires user confirmation, it will show up inline in the chat view.
*
* If the tool is being invoked outside of a chat request, `undefined` should be passed instead, and no special UI except for
* confirmations will be shown.
*
* If a tool invokes another tool during its invocation, it can pass along the `toolInvocationToken` that it received.
* *Note* that a tool that invokes another tool during its invocation, can pass along the `toolInvocationToken` that it received.
*/
toolInvocationToken: ChatParticipantToolToken | undefined;

Expand Down

0 comments on commit cb7e203

Please sign in to comment.