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

removing vscode -based auth for azure #693

Closed
wants to merge 3 commits into from
Closed

Conversation

pelikhan
Copy link
Member

@pelikhan pelikhan commented Sep 5, 2024

  • Refactored the Azure token handling, including:

    • Introduced the LanguageModelAuthenticationToken interface for language model authentications.
    • The azure token is now prefixed with Bearer .
    • The method setLanguageModelConnectionToken is added to RuntimeHost, and is implemented in NodeHost to store the token based on the provider.
    • The method isLanguageModelAuthenticationTokenExpired is introduced to check token expiration.
    • On NodeHost, the previously used AuthenticationToken is replaced with LanguageModelAuthenticationToken, and storage of the token is changed to a Record based on provider.
    • Refactored the requesting of Azure Token in getLanguageModelConfiguration based on the new changes.
  • Updated the code to set the language model connection token in runScript if provided.

  • The server now receives an additional modelToken with script start request and passes it to the client script run.

  • The client now sends an additional modelToken with the script start request.

  • Updated the VSCode extension to fetch Azure token on-demand and prefix it with Bearer .

  • The Language Model Configuration now extends LanguageModelAuthenticationToken.

  • The vscode engine is updated from "1.92.0" to "1.93.0".

  • Fixed a typo error in throwing an error message in lmaccess.ts and state.ts.

💡 Major updates revolve around handling azure tokens used in Language Model authentications, providing a more structured approach to manage different providers and their tokens. User-facing APIs are unaffected by these changes.

generated by pr-describe

@pelikhan pelikhan closed this Sep 5, 2024
@pelikhan pelikhan deleted the azure-account-selection branch September 5, 2024 23:13
const { DefaultAzureCredential } = await import("@azure/identity")
const azureToken = await new DefaultAzureCredential().getToken(
AZURE_OPENAI_TOKEN_SCOPES.slice(),
{ abortSignal: signal }
)
const res = {
token: azureToken.token,
provider: MODEL_PROVIDER_AZURE,
token: "Bearer " + azureToken.token,
expiresOnTimestamp: azureToken.expiresOnTimestamp
? azureToken.expiresOnTimestamp
: Date.now() + AZURE_OPENAI_TOKEN_EXPIRATION,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MODEL_PROVIDER_AZURE constant is used but not imported in this file.

generated by pr-review-commit missing_import

private readonly _languageModelAuthenticationTokens: Record<
string,
LanguageModelAuthenticationToken
> = {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type of _languageModelAuthenticationTokens is not defined. It should be Record<string, LanguageModelAuthenticationToken>.

generated by pr-review-commit missing_type

token?.expiresOnTimestamp <
Date.now() - LANGUAGE_MODEL_TOKEN_EXPIRATION_OFFSET
) // avoid data races
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LANGUAGE_MODEL_TOKEN_EXPIRATION_OFFSET constant is used but not imported in this file.

generated by pr-review-commit missing_import

Copy link

github-actions bot commented Sep 5, 2024

The changes in the GIT_DIFF:

  1. Refactor the AuthenticationToken interface to LanguageModelAuthenticationToken and moved it to the host.ts file.
  2. Change the returned token in createAzureToken function to prefix it with Bearer .
  3. In NodeHost:
    • A method setLanguageModelConnectionToken is added to set the Language Model token.
    • The _azureToken is updated to _languageModelAuthenticationTokens, a Record of Language Model tokens.
    • In getLanguageModelConfiguration, the Azure token is fetched from _languageModelAuthenticationTokens instead of _azureToken.
  4. The runScript function now accepts a modelToken option, and it sets the Language Model token into the runtimeHost.
  5. The startServer function now accepts modelToken from data and passes it on to the runScript function.
  6. A constant LANGUAGE_MODEL_TOKEN_EXPIRATION_OFFSET is added in constants.ts.
  7. A function isLanguageModelAuthenticationTokenExpired is added in host.ts.
  8. LanguageModelAuthenticationToken is added as a property in LanguageModelConfiguration interface.
  9. The access token in the AzureManager is now prefixed with Bearer , and the account is selected before getting the Session.
  10. A modelToken is added in the data in PromptScriptStart interface.
  11. modelToken is accepted in the startScript function in WebSocketClient and sent in the request.
  12. setLanguageModelConnectionToken is added in TestHost.
  13. In state.ts, modelToken is set according to some conditions before calling startScript.
  14. In VSCodeHost, the token is prefixed with Bearer if the provider is MODEL_PROVIDER_CLIENT and the modelId provider is MODEL_PROVIDER_AZURE.

Concerns:

  1. In AzureManager, the conditions for the QuickPickItem prompt when multiple accounts are found may not cover all edge cases. The user response res could be undefined if the user cancels the prompt, and the account variable would be undefined.

LGTM overall 🚀, but the concern above should be addressed to prevent potential issues.

generated by pr-review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant