Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/api/browser/mainThreadAiEmbeddingVector.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { CancellationToken } from '../../../base/common/cancellation.js';
7
import { Disposable, DisposableMap } from '../../../base/common/lifecycle.js';
8
import { ExtHostAiEmbeddingVectorShape, ExtHostContext, MainContext, MainThreadAiEmbeddingVectorShape } from '../common/extHost.protocol.js';
9
import { IAiEmbeddingVectorProvider, IAiEmbeddingVectorService } from '../../services/aiEmbeddingVector/common/aiEmbeddingVectorService.js';
10
import { IExtHostContext, extHostNamedCustomer } from '../../services/extensions/common/extHostCustomers.js';
11
12
@extHostNamedCustomer(MainContext.MainThreadAiEmbeddingVector)
13
export class MainThreadAiEmbeddingVector extends Disposable implements MainThreadAiEmbeddingVectorShape {
14
private readonly _proxy: ExtHostAiEmbeddingVectorShape;
15
private readonly _registrations = this._register(new DisposableMap<number>());
16
17
constructor(
18
context: IExtHostContext,
19
@IAiEmbeddingVectorService private readonly _AiEmbeddingVectorService: IAiEmbeddingVectorService,
20
) {
21
super();
22
this._proxy = context.getProxy(ExtHostContext.ExtHostAiEmbeddingVector);
23
}
24
25
$registerAiEmbeddingVectorProvider(model: string, handle: number): void {
26
const provider: IAiEmbeddingVectorProvider = {
27
provideAiEmbeddingVector: (strings: string[], token: CancellationToken) => {
28
return this._proxy.$provideAiEmbeddingVector(
29
handle,
30
strings,
31
token
32
);
33
},
34
};
35
this._registrations.set(handle, this._AiEmbeddingVectorService.registerAiEmbeddingVectorProvider(model, provider));
36
}
37
38
$unregisterAiEmbeddingVectorProvider(handle: number): void {
39
this._registrations.deleteAndDispose(handle);
40
}
41
}
42
43