Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The types LanguageModelChatTool and LanguageModelToolInformation are incompatible when exactOptionalPropertyTypes set #241285

Closed
tamuratak opened this issue Feb 20, 2025 · 3 comments · Fixed by #241502
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug unreleased Patch has not yet been released in VS Code Insiders
Milestone

Comments

@tamuratak
Copy link
Contributor

Version: 1.98.0-insider
Commit: 105d4af
Date: 2025-02-19T06:43:12.388Z
Electron: 34.1.0
ElectronBuildId: 10990655
Chromium: 132.0.6834.194
Node.js: 20.18.1
V8: 13.2.152.38-electron.0
OS: Darwin x64 22.6.0

Steps to Reproduce:

  1. Set "exactOptionalPropertyTypes": true in tsconfig.json
  2. We cannot directly use the result of vscode.lm.tools.find with vscode.lm.invokeTool because the types LanguageModelChatTool and LanguageModelToolInformation are incompatible.
  3. See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-4.html#exact-optional-property-types---exactoptionalpropertytypes
  4. The inputSchema property in both types should be inputSchema?: object | undefined;
@mjbvz mjbvz added the bug Issue identified by VS Code Team member as probable bug label Feb 21, 2025
@mjbvz mjbvz added this to the February 2025 milestone Feb 21, 2025
@jrieken
Copy link
Member

jrieken commented Feb 24, 2025

We cannot directly use the result of vscode.lm.tools.find with vscode.lm.invokeTool because the types LanguageModelChatTool and LanguageModelToolInformation are incompatible.

@tamuratak Do you have a more complete sample that clarifies how invokeTool and picking from lm.tools interact? When invoking a tool you shouldn't use the inputSchema but an input-object with actual values

@tamuratak
Copy link
Contributor Author

My comment was incorrect. It should have been LanguageModelChat.sendRequest, not invokeTool. The following is the actual code:

        const tools = getLmTools()
        const chatResponse = await model.sendRequest(
            messages, { tools }, token
        ).then(r => r, e => {

https://github.com/tamuratak/vscode-able/blob/73d0923492dc84167a3f62fb794e1dcdc1860f21/src/chat/chatlib/copilotchathandler.ts#L34

In my code, the getLmTools function transforms LanguageModelToolInformation[] to LanguageModelChatTool[]. Without that, we have

src/chat/chatlib/copilotchathandler.ts:35:25 - error TS2322: Type 'LanguageModelToolInformation[]' is not assignable to type 'LanguageModelChatTool[]'.
  Type 'LanguageModelToolInformation' is not assignable to type 'LanguageModelChatTool' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
    Types of property 'inputSchema' are incompatible.
      Type 'object | undefined' is not assignable to type 'object'.
        Type 'undefined' is not assignable to type 'object'.

35             messages, { tools }, token

@jrieken
Copy link
Member

jrieken commented Feb 25, 2025

Ok, that makes more sense. Thanks for clarifying!

@mjbvz mjbvz closed this as completed in 1a5a854 Feb 25, 2025
@vs-code-engineering vs-code-engineering bot added the unreleased Patch has not yet been released in VS Code Insiders label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug unreleased Patch has not yet been released in VS Code Insiders
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants