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
introduce a SemanticSimilarity provider model #179640
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/vs/workbench/api/browser/mainThreadSemanticSimilarity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { Disposable, DisposableMap } from 'vs/base/common/lifecycle'; | ||
import { ExtHostContext, ExtHostSemanticSimilarityShape, MainContext, MainThreadSemanticSimilarityShape } from 'vs/workbench/api/common/extHost.protocol'; | ||
import { IExtHostContext, extHostNamedCustomer } from 'vs/workbench/services/extensions/common/extHostCustomers'; | ||
import { ISemanticSimilarityProvider, ISemanticSimilarityService } from 'vs/workbench/services/semanticSimilarity/common/semanticSimilarityService'; | ||
|
||
@extHostNamedCustomer(MainContext.MainThreadSemanticSimilarity) | ||
export class MainThreadSemanticSimilarity extends Disposable implements MainThreadSemanticSimilarityShape { | ||
private readonly _proxy: ExtHostSemanticSimilarityShape; | ||
private readonly _registrations = this._register(new DisposableMap<number>()); | ||
|
||
constructor( | ||
context: IExtHostContext, | ||
@ISemanticSimilarityService private readonly _semanticSimilarityService: ISemanticSimilarityService | ||
) { | ||
super(); | ||
this._proxy = context.getProxy(ExtHostContext.ExtHostSemanticSimilarity); | ||
} | ||
|
||
$registerSemanticSimilarityProvider(handle: number): void { | ||
const provider: ISemanticSimilarityProvider = { | ||
provideSimilarityScore: (string1, comparisons, token) => { | ||
return this._proxy.$provideSimilarityScore(handle, string1, comparisons, token); | ||
}, | ||
}; | ||
this._registrations.set(handle, this._semanticSimilarityService.registerSemanticSimilarityProvider(provider)); | ||
} | ||
|
||
$unregisterSemanticSimilarityProvider(handle: number): void { | ||
this._registrations.deleteAndDispose(handle); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'; | ||
import { ExtHostSemanticSimilarityShape, IMainContext, MainContext, MainThreadSemanticSimilarityShape } from 'vs/workbench/api/common/extHost.protocol'; | ||
import type { CancellationToken, SemanticSimilarityProvider } from 'vscode'; | ||
import { Disposable } from 'vs/workbench/api/common/extHostTypes'; | ||
|
||
export class ExtHostSemanticSimilarity implements ExtHostSemanticSimilarityShape { | ||
private _semanticSimilarityProviders: Map<number, SemanticSimilarityProvider> = new Map(); | ||
private _nextHandle = 0; | ||
|
||
private readonly _proxy: MainThreadSemanticSimilarityShape; | ||
|
||
constructor( | ||
mainContext: IMainContext | ||
) { | ||
this._proxy = mainContext.getProxy(MainContext.MainThreadSemanticSimilarity); | ||
} | ||
|
||
async $provideSimilarityScore(handle: number, string1: string, comparisons: string[], token: CancellationToken): Promise<number[]> { | ||
if (this._semanticSimilarityProviders.size === 0) { | ||
throw new Error('No semantic similarity providers registered'); | ||
} | ||
|
||
const provider = this._semanticSimilarityProviders.get(handle); | ||
if (!provider) { | ||
throw new Error('Semantic similarity provider not found'); | ||
} | ||
|
||
const result = await provider.provideSimilarityScore(string1, comparisons, token); | ||
return result; | ||
} | ||
|
||
registerSemanticSimilarityProvider(extension: IExtensionDescription, provider: SemanticSimilarityProvider): Disposable { | ||
const handle = this._nextHandle; | ||
this._nextHandle++; | ||
this._semanticSimilarityProviders.set(handle, provider); | ||
this._proxy.$registerSemanticSimilarityProvider(handle); | ||
return new Disposable(() => { | ||
this._proxy.$unregisterSemanticSimilarityProvider(handle); | ||
this._semanticSimilarityProviders.delete(handle); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* 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' { | ||
export interface SemanticSimilarityProvider { | ||
/** | ||
* Computes the semantic similarity score between two strings. | ||
* @param string1 The string to compare to all other strings. | ||
* @param comparisons An array of strings to compare string1 to. An array allows you to batch multiple comparisons in one call. | ||
* @param token A cancellation token. | ||
* @return A promise that resolves to the semantic similarity scores between string1 and each string in comparisons. | ||
* The score should be a number between 0 and 1, where 0 means no similarity and 1 means | ||
* perfect similarity. | ||
*/ | ||
provideSimilarityScore(string1: string, comparisons: string[], token: CancellationToken): Thenable<number[]>; | ||
} | ||
export namespace ai { | ||
export function registerSemanticSimilarityProvider(provider: SemanticSimilarityProvider): Disposable; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is an improvement, thanks, but it is a behavior change so if you haven't already, make sure you take a look at the other places it's used and try to check whether that might be an issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's only used in one other place and I think based on the code it seems ok. @sandy081 FYI