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

Language model access API #206265

Closed
4 of 5 tasks
jrieken opened this issue Feb 26, 2024 · 24 comments
Closed
4 of 5 tasks

Language model access API #206265

jrieken opened this issue Feb 26, 2024 · 24 comments
Assignees
Labels
api-finalization feature-request Request for new features or functionality lm-access on-release-notes Issue/pull request mentioned in release notes on-testplan
Milestone

Comments

@jrieken
Copy link
Member

jrieken commented Feb 26, 2024

This issue is about allowing extensions to use language model that are contributed by other extensions. The API proposal is https://github.com/microsoft/vscode/blob/main/src/vscode-dts/vscode.proposed.languageModels.d.ts and its scope is to allow to use the chat feature of language models.

Remaining finalisation todos

  • consolidate different LanguageModelChatXYZMessage-type into one type and a role-enum
  • move System message/role into its own proposal
  • have a select-function that's the only way of getting to a chat model
  • consider moving token counting into its own proposal (some model don't do token counting e.g anthropic or ollama)
  • consider to have more sturcture on LanguageModelChatResponse, e.g have a fake reply message with role like others (ollama, open ai, anthropic)
    • I renamed LanguageModelChatResponse#stream to text and I will continue to explore a stream of structured objects. That would be additive to text and plugged in as its foundation.
    • add something like modelResult: Thenable<{ [name: string]: any }>
  • add a StopReason-enum that's also used in LanguageModelChat
@jrieken jrieken self-assigned this Feb 26, 2024
@jrieken jrieken added api-finalization lm-access feature-request Request for new features or functionality labels Feb 26, 2024
@jrieken jrieken added this to the March 2024 milestone Feb 26, 2024
@isidorn
Copy link
Contributor

isidorn commented Feb 26, 2024

This was referenced Feb 27, 2024
@jrieken
Copy link
Member Author

jrieken commented Feb 27, 2024

With #206358 there will be no more language model access object. Instead all requests are made directly via vscode.lm.sendChatRequest(model, messages, options, token)

jrieken added a commit that referenced this issue Feb 27, 2024
jrieken added a commit that referenced this issue Feb 27, 2024
jrieken added a commit that referenced this issue Feb 28, 2024
* makes ExtHostAuth and ExtHostLM injectable
* (hack) makes silents auth requests for all extension upon LM registration

#206265
hbons pushed a commit that referenced this issue Feb 28, 2024
jrieken added a commit that referenced this issue Feb 28, 2024
* makes ExtHostAuth and ExtHostLM injectable
* (hack) makes silents auth requests for all extension upon LM registration

#206265
@jrieken jrieken modified the milestones: March 2024, April 2024 Mar 22, 2024
jrieken added a commit that referenced this issue Apr 11, 2024
@jrieken jrieken modified the milestones: April 2024, May 2024 Apr 18, 2024
@worksofliam
Copy link

Hi @jrieken

Is there any plans to add a registerLanguageModel, so I can implement my own calls to other models other than the Copilot provided models?

Thanks!

@jrieken
Copy link
Member Author

jrieken commented May 7, 2024

Yeah, that exists. It is the src/vscode-dts/vscode.proposed.chatProvider.d.ts which is still very rough and currently not yet scheduled for finalisation. Tho, feel free to give it a spin and report what's missing/wrong. For instance, locally I have a dummy extension that uses ollama to drive this API

@worksofliam
Copy link

@jrieken I assume you are referring to the createChatParticipant API?

So if I use createChatParticipant, I can then use the id I give it with sendChatMessage?

@jrieken
Copy link
Member Author

jrieken commented May 7, 2024

@jrieken I assume you are referring to the createChatParticipant API?

No, I mean the proposal that I have mentioned

@jrieken
Copy link
Member Author

jrieken commented May 8, 2024

FYI that I made the following changes to the languageModels proposal

  • there is no more vscode.lm.languageModels and generally no more referring of language model by string-identifier.
  • there is vscode.lm.selectChatModels(selector) that takes a selector and returns matching chat models or nothing (undefined)

These changes allow for a better implementation of the providing-end (chatProvider-proposal) and most importantly make it more obvious that models can (and will) change. The following pattern had become popular'ish vscode.lm.sendChatRequest('hardcoded.model.id, ....)`. This is brittle because extensions break as soon as the model id isn't known anymore. Instead models need to be selected, making it hopefully more clear that a desired model doesn't exist. The new selector-mechanism allows for new flexibility as well. A couple of samples

// select a model by vendor and family
await vscode.lm.selectChatModels({ vendor: 'copilot', family: 'gpt-3.5-turbo' })

// select all models
await vscode.lm.selectChatModels()

// hardcode an identifier (previous usage model, NOT recommended because brittle)
await vscode.lm.selectChatModels({ id: 'someHardcodedModelId' })

To restate, the selectChatModels-function can return undefined which means no model was found. That's because the selector is to strict (using id) or because no models are known (missing extensions). The shape of language model selectors is this

export interface LanguageModelChatSelector {
  vendor?: string;
  family?: string;
  version?: string;
  id?: string;
}

Note that

  • property order represents how specific it is
  • properties are matched based on equality, when present it must match
  • we will likely add some comparison selector for input and/or output tokens

@jrieken
Copy link
Member Author

jrieken commented May 13, 2024

hi @jrieken met below error after sendRequest(). Any guidance?

@yungezz Make sure that you are on latest pre-release of the copilot-chat extension

When running against the same Codespace with browser Insiders, vscode.lm.selectChatModels() always returns undefined, implying there are no chat models available.

@bwateratmsft That's certainly possible when copilot-chat isn't installed in the codespace.

@bwateratmsft
Copy link
Contributor

bwateratmsft commented May 13, 2024

When running against the same Codespace with browser Insiders, vscode.lm.selectChatModels() always returns undefined, implying there are no chat models available.

@bwateratmsft That's certainly possible when copilot-chat isn't installed in the codespace.

It is installed, and regular Copilot Chat works normally, but our extension can't get a language model.

@jrieken
Copy link
Member Author

jrieken commented May 13, 2024

And it is latest prerelease?

@bwateratmsft
Copy link
Contributor

bwateratmsft commented May 13, 2024

Yep!

Version: 1.90.0-insider
Commit: 3028408
Date: 2024-05-13T12:40:35.552Z
Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0

image
image

Here's regular chat working:
image

And our extension emitting to its output log, via this line of code:

ext.outputChannel.error(JSON.stringify(await vscode.lm.selectChatModels()));

image

The same codespace but using desktop frontend instead of browser (working as expected):
image

@jrieken
Copy link
Member Author

jrieken commented May 14, 2024

Really confusing... In my sample remote-setup (which isn't codespaces) this is working just fine and I see so smoking guns for why this wouldn't work in codespaces. For now, I have added some logging that should help us get to the bottom of this

@InTheCloudDan
Copy link

I see mention of moving the System prompt to a separate Proposal, can that be linked to? I am not finding it and we use it in our extension.

Also is this section of the guide still accurate? https://code.visualstudio.com/api/extension-guides/language-model#prompt-crafting It's not showing those commands as imports anymore and from my reading of the types it looks like it should be closer to:

vscode.LanguageModelChatMessage(vscode.LanguageModelChatMessageRole.User, message)

@jrieken
Copy link
Member Author

jrieken commented May 14, 2024

This is place of all API proposals: https://github.com/microsoft/vscode/tree/main/src/vscode-dts

Also is this section of the guide still accurate

Likely outdated

@bwateratmsft
Copy link
Contributor

Really confusing... In my sample remote-setup (which isn't codespaces) this is working just fine and I see so smoking guns for why this wouldn't work in codespaces. For now, I have added some logging that should help us get to the bottom of this

Where should I look for the additional logs?

@jrieken
Copy link
Member Author

jrieken commented May 15, 2024

Enable trace logging, show the window-log and check for messages starting with [LM]. There should be some for registering and some for selection

Screenshot 2024-05-15 at 08 15 30

@jrieken
Copy link
Member Author

jrieken commented May 15, 2024

@bwateratmsft I did find something after @roblourens running into a similar issues. Can you confirm that a later/second invocation yields models and/or that the vscode.lm.onDidChangeChatModels-event fires and that after that chat models are selected?

@bwateratmsft
Copy link
Contributor

bwateratmsft commented May 15, 2024

I found some log lines for selection but nothing for registration:

[LM] selected language models {"vendor":"copilot","extension":{"value":"ms-azuretools.vscode-azure-github-copilot","_lower":"ms-azuretools.vscode-azure-github-copilot"}} []

We end up doing language model selection several times and each time it returns undefined.

I even tried doing the following and still there were no log lines about registration:

  1. Disable all 3 extensions (Copilot Chat, Copilot, and our extension)
  2. Reload browser window
  3. Enable trace window logging
  4. Enable extensions
  5. Execute a query with regular Copilot (success)
  6. Execute a query with our extension (failure)

However, when using VSCode Desktop as the frontend, I do see log lines about language model registration:

[LM] registering language model chat github.copilot-chat/1/gpt-3.5-turbo {"extension":{"value":"GitHub.copilot-chat","_lower":"github.copilot-chat"},"id":"gpt-3.5-turbo","vendor":"copilot","name":"GPT 3.5 Turbo","family":"gpt-3.5-turbo","version":"gpt-3.5-turbo-0613","maxInputTokens":4000,"maxOutputTokens":2000,"auth":{"providerLabel":"GitHub Copilot Chat","accountLabel":"bwateratmsft"}}
...
[LM] registering language model chat github.copilot-chat/2/gpt-4 {"extension":{"value":"GitHub.copilot-chat","_lower":"github.copilot-chat"},"id":"gpt-4","vendor":"copilot","name":"GPT 4","family":"gpt-4","version":"gpt-4-0613","maxInputTokens":4000,"maxOutputTokens":2000,"auth":{"providerLabel":"GitHub Copilot Chat","accountLabel":"bwateratmsft"}}

@jrieken
Copy link
Member Author

jrieken commented May 15, 2024

I even tried doing the following and still there were no log lines about registration

Thanks for the update. That would really mean the language model API doesn't register. Can you check the chat log (Output > GH Copilot Chat) for messages starting with registerChatResponseProvider

@bwateratmsft
Copy link
Contributor

I don't see any messages like that from either browser or desktop frontend on the Codespace. However, on the browser session there was this message which did not appear on the desktop session--might be spurious but I'm not sure:

2024-05-15 17:47:09.424 [info] [RemoteAgents] Invalid remote agent response: bad request: unknown integration (SyntaxError: Unexpected token 'b', "bad reques"... is not valid JSON)

@isidorn
Copy link
Contributor

isidorn commented May 17, 2024

We have finalized the Language Model and Chat Participant API 🚀

Thus, you can now publish your extensions to the VS Marketplace. This API is finalized in VS Code Insiders, and will be finalized in VS Code Stable in July. Thus we suggest that you use an engines: ^1.90.0 property in your package.json, and VS Code Stable will gracefully handle your extensions and ignore your usage of Language Model and Chat API until the API gets finalized in Stable in July.

Full docs https://code.visualstudio.com/api/extension-guides/language-model

We have decided to only finalise the User message. And System message might be finalised in one of the future iterations. Main reason for this is general API consideration - as we are still learning how the System prompt API would fit with some of the non-GPT models. Also we believe that the System prompt API requires more responsible AI testing from our team.
If your extension would like to use the System prompt API - please let us know if you hit issues with using the User prompt as a replacement.

We are excited to see what you build ✨

@isidorn isidorn closed this as completed May 17, 2024
@jrieken jrieken added the on-release-notes Issue/pull request mentioned in release notes label May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-finalization feature-request Request for new features or functionality lm-access on-release-notes Issue/pull request mentioned in release notes on-testplan
Projects
None yet
Development

No branches or pull requests

9 participants