@theia/ai-huggingface 1.46.0-next.241

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +32 -0
  2. package/lib/browser/huggingface-frontend-application-contribution.d.ts +13 -0
  3. package/lib/browser/huggingface-frontend-application-contribution.d.ts.map +1 -0
  4. package/lib/browser/huggingface-frontend-application-contribution.js +91 -0
  5. package/lib/browser/huggingface-frontend-application-contribution.js.map +1 -0
  6. package/lib/browser/huggingface-frontend-module.d.ts +4 -0
  7. package/lib/browser/huggingface-frontend-module.d.ts.map +1 -0
  8. package/lib/browser/huggingface-frontend-module.js +32 -0
  9. package/lib/browser/huggingface-frontend-module.js.map +1 -0
  10. package/lib/browser/huggingface-preferences.d.ts +5 -0
  11. package/lib/browser/huggingface-preferences.d.ts.map +1 -0
  12. package/lib/browser/huggingface-preferences.js +42 -0
  13. package/lib/browser/huggingface-preferences.js.map +1 -0
  14. package/lib/common/huggingface-language-models-manager.d.ts +25 -0
  15. package/lib/common/huggingface-language-models-manager.d.ts.map +1 -0
  16. package/lib/common/huggingface-language-models-manager.js +21 -0
  17. package/lib/common/huggingface-language-models-manager.js.map +1 -0
  18. package/lib/common/index.d.ts +2 -0
  19. package/lib/common/index.d.ts.map +1 -0
  20. package/lib/common/index.js +20 -0
  21. package/lib/common/index.js.map +1 -0
  22. package/lib/node/huggingface-backend-module.d.ts +5 -0
  23. package/lib/node/huggingface-backend-module.d.ts.map +1 -0
  24. package/lib/node/huggingface-backend-module.js +29 -0
  25. package/lib/node/huggingface-backend-module.js.map +1 -0
  26. package/lib/node/huggingface-language-model.d.ts +29 -0
  27. package/lib/node/huggingface-language-model.d.ts.map +1 -0
  28. package/lib/node/huggingface-language-model.js +134 -0
  29. package/lib/node/huggingface-language-model.js.map +1 -0
  30. package/lib/node/huggingface-language-models-manager-impl.d.ts +11 -0
  31. package/lib/node/huggingface-language-models-manager-impl.d.ts.map +1 -0
  32. package/lib/node/huggingface-language-models-manager-impl.js +63 -0
  33. package/lib/node/huggingface-language-models-manager-impl.js.map +1 -0
  34. package/lib/package.spec.d.ts +1 -0
  35. package/lib/package.spec.d.ts.map +1 -0
  36. package/lib/package.spec.js +26 -0
  37. package/lib/package.spec.js.map +1 -0
  38. package/package.json +50 -0
  39. package/src/browser/huggingface-frontend-application-contribution.ts +95 -0
  40. package/src/browser/huggingface-frontend-module.ts +31 -0
  41. package/src/browser/huggingface-preferences.ts +42 -0
  42. package/src/common/huggingface-language-models-manager.ts +40 -0
  43. package/src/common/index.ts +16 -0
  44. package/src/node/huggingface-backend-module.ts +30 -0
  45. package/src/node/huggingface-language-model.ts +166 -0
  46. package/src/node/huggingface-language-models-manager-impl.ts +73 -0
  47. package/src/package.spec.ts +28 -0
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ <div align='center'>
2
+
3
+ <br />
4
+
5
+ <img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' />
6
+
7
+ <h2>ECLIPSE THEIA - Hugging Face AI EXTENSION</h2>
8
+
9
+ <hr />
10
+
11
+ </div>
12
+
13
+ ## Description
14
+
15
+ The `@theia/ai-huggingface` integrates Hugging Face's models with Theia AI.
16
+ The Hugging Face API key and the models to use can be configured via preferences.
17
+ Alternatively, the Hugging Face API key can also be provided via the `HUGGINGFACE_API_KEY` environment variable.
18
+
19
+ ## Additional Information
20
+
21
+ - [Theia - GitHub](https://github.com/eclipse-theia/theia)
22
+ - [Theia - Website](https://theia-ide.org/)
23
+
24
+ ## License
25
+
26
+ - [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
27
+ - [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
28
+
29
+ ## Trademark
30
+
31
+ "Theia" is a trademark of the Eclipse Foundation
32
+ <https://www.eclipse.org/theia>
@@ -0,0 +1,13 @@
1
+ import { FrontendApplicationContribution, PreferenceService } from '@theia/core/lib/browser';
2
+ import { HuggingFaceLanguageModelsManager, HuggingFaceModelDescription } from '../common';
3
+ import { RequestSetting } from '@theia/ai-core/lib/browser/ai-core-preferences';
4
+ export declare class HuggingFaceFrontendApplicationContribution implements FrontendApplicationContribution {
5
+ protected preferenceService: PreferenceService;
6
+ protected manager: HuggingFaceLanguageModelsManager;
7
+ protected prevModels: string[];
8
+ onStart(): void;
9
+ protected handleModelChanges(newModels: string[]): void;
10
+ protected handleRequestSettingsChanges(newSettings: RequestSetting[]): void;
11
+ protected createHuggingFaceModelDescription(modelId: string, requestSettings: RequestSetting[]): HuggingFaceModelDescription;
12
+ }
13
+ //# sourceMappingURL=huggingface-frontend-application-contribution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huggingface-frontend-application-contribution.d.ts","sourceRoot":"","sources":["../../src/browser/huggingface-frontend-application-contribution.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,+BAA+B,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE7F,OAAO,EAAE,gCAAgC,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAE1F,OAAO,EAAoC,cAAc,EAAE,MAAM,gDAAgD,CAAC;AAGlH,qBACa,0CAA2C,YAAW,+BAA+B;IAG9F,SAAS,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAG/C,SAAS,CAAC,OAAO,EAAE,gCAAgC,CAAC;IAEpD,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,CAAM;IAEpC,OAAO,IAAI,IAAI;IAsBf,SAAS,CAAC,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI;IAavD,SAAS,CAAC,4BAA4B,CAAC,WAAW,EAAE,cAAc,EAAE,GAAG,IAAI;IAK3E,SAAS,CAAC,iCAAiC,CACvC,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,cAAc,EAAE,GAClC,2BAA2B;CAiBjC"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2024 EclipseSource GmbH.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.HuggingFaceFrontendApplicationContribution = void 0;
19
+ const tslib_1 = require("tslib");
20
+ const browser_1 = require("@theia/core/lib/browser");
21
+ const inversify_1 = require("@theia/core/shared/inversify");
22
+ const common_1 = require("../common");
23
+ const huggingface_preferences_1 = require("./huggingface-preferences");
24
+ const ai_core_preferences_1 = require("@theia/ai-core/lib/browser/ai-core-preferences");
25
+ const HUGGINGFACE_PROVIDER_ID = 'huggingface';
26
+ let HuggingFaceFrontendApplicationContribution = class HuggingFaceFrontendApplicationContribution {
27
+ constructor() {
28
+ this.prevModels = [];
29
+ }
30
+ onStart() {
31
+ this.preferenceService.ready.then(() => {
32
+ const apiKey = this.preferenceService.get(huggingface_preferences_1.API_KEY_PREF, undefined);
33
+ this.manager.setApiKey(apiKey);
34
+ const models = this.preferenceService.get(huggingface_preferences_1.MODELS_PREF, []);
35
+ const requestSettings = this.preferenceService.get(ai_core_preferences_1.PREFERENCE_NAME_REQUEST_SETTINGS, []);
36
+ this.manager.createOrUpdateLanguageModels(...models.map(modelId => this.createHuggingFaceModelDescription(modelId, requestSettings)));
37
+ this.prevModels = [...models];
38
+ this.preferenceService.onPreferenceChanged(event => {
39
+ if (event.preferenceName === huggingface_preferences_1.API_KEY_PREF) {
40
+ this.manager.setApiKey(event.newValue);
41
+ }
42
+ else if (event.preferenceName === huggingface_preferences_1.MODELS_PREF) {
43
+ this.handleModelChanges(event.newValue);
44
+ }
45
+ else if (event.preferenceName === ai_core_preferences_1.PREFERENCE_NAME_REQUEST_SETTINGS) {
46
+ this.handleRequestSettingsChanges(event.newValue);
47
+ }
48
+ });
49
+ });
50
+ }
51
+ handleModelChanges(newModels) {
52
+ const oldModels = new Set(this.prevModels);
53
+ const updatedModels = new Set(newModels);
54
+ const modelsToRemove = [...oldModels].filter(model => !updatedModels.has(model));
55
+ const modelsToAdd = [...updatedModels].filter(model => !oldModels.has(model));
56
+ this.manager.removeLanguageModels(...modelsToRemove.map(model => `${HUGGINGFACE_PROVIDER_ID}/${model}`));
57
+ const requestSettings = this.preferenceService.get(ai_core_preferences_1.PREFERENCE_NAME_REQUEST_SETTINGS, []);
58
+ this.manager.createOrUpdateLanguageModels(...modelsToAdd.map(modelId => this.createHuggingFaceModelDescription(modelId, requestSettings)));
59
+ this.prevModels = newModels;
60
+ }
61
+ handleRequestSettingsChanges(newSettings) {
62
+ const models = this.preferenceService.get(huggingface_preferences_1.MODELS_PREF, []);
63
+ this.manager.createOrUpdateLanguageModels(...models.map(modelId => this.createHuggingFaceModelDescription(modelId, newSettings)));
64
+ }
65
+ createHuggingFaceModelDescription(modelId, requestSettings) {
66
+ const id = `${HUGGINGFACE_PROVIDER_ID}/${modelId}`;
67
+ const matchingSettings = requestSettings.filter(setting => (!setting.providerId || setting.providerId === HUGGINGFACE_PROVIDER_ID) && setting.modelId === modelId);
68
+ if (matchingSettings.length > 1) {
69
+ console.warn(`Multiple entries found for modelId "${modelId}". Using the first match and ignoring the rest.`);
70
+ }
71
+ const modelRequestSetting = matchingSettings[0];
72
+ return {
73
+ id: id,
74
+ model: modelId,
75
+ defaultRequestSettings: modelRequestSetting === null || modelRequestSetting === void 0 ? void 0 : modelRequestSetting.requestSettings
76
+ };
77
+ }
78
+ };
79
+ exports.HuggingFaceFrontendApplicationContribution = HuggingFaceFrontendApplicationContribution;
80
+ tslib_1.__decorate([
81
+ (0, inversify_1.inject)(browser_1.PreferenceService),
82
+ tslib_1.__metadata("design:type", Object)
83
+ ], HuggingFaceFrontendApplicationContribution.prototype, "preferenceService", void 0);
84
+ tslib_1.__decorate([
85
+ (0, inversify_1.inject)(common_1.HuggingFaceLanguageModelsManager),
86
+ tslib_1.__metadata("design:type", Object)
87
+ ], HuggingFaceFrontendApplicationContribution.prototype, "manager", void 0);
88
+ exports.HuggingFaceFrontendApplicationContribution = HuggingFaceFrontendApplicationContribution = tslib_1.__decorate([
89
+ (0, inversify_1.injectable)()
90
+ ], HuggingFaceFrontendApplicationContribution);
91
+ //# sourceMappingURL=huggingface-frontend-application-contribution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huggingface-frontend-application-contribution.js","sourceRoot":"","sources":["../../src/browser/huggingface-frontend-application-contribution.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAEhF,qDAA6F;AAC7F,4DAAkE;AAClE,sCAA0F;AAC1F,uEAAsE;AACtE,wFAAkH;AAElH,MAAM,uBAAuB,GAAG,aAAa,CAAC;AAEvC,IAAM,0CAA0C,GAAhD,MAAM,0CAA0C;IAAhD;QAQO,eAAU,GAAa,EAAE,CAAC;IA8DxC,CAAC;IA5DG,OAAO;QACH,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;YACnC,MAAM,MAAM,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAS,sCAAY,EAAE,SAAS,CAAC,CAAC;YAC3E,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,C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KAAK,OAAO,CACpH,CAAC;QACF,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,OAAO,CAAC,IAAI,CACR,uCAAuC,OAAO,iDAAiD,CAClG,CAAC;QACN,CAAC;QACD,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;QAChD,OAAO;YACH,EAAE,EAAE,EAAE;YACN,KAAK,EAAE,OAAO;YACd,sBAAsB,EAAE,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,eAAe;SAC/D,CAAC;IACN,CAAC;CACJ,CAAA;AAtEY,gGAA0C;AAGzC;IADT,IAAA,kBAAM,EAAC,2BAAiB,CAAC;;qFACqB;AAGrC;IADT,IAAA,kBAAM,EAAC,yCAAgC,CAAC;;2EACW;qDAN3C,0CAA0C;IADtD,IAAA,sBAAU,GAAE;GACA,0CAA0C,CAsEtD"}
@@ -0,0 +1,4 @@
1
+ import { ContainerModule } from '@theia/core/shared/inversify';
2
+ declare const _default: ContainerModule;
3
+ export default _default;
4
+ //# sourceMappingURL=huggingface-frontend-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huggingface-frontend-module.d.ts","sourceRoot":"","sources":["../../src/browser/huggingface-frontend-module.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;AAM/D,wBAQG"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2024 EclipseSource GmbH.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const inversify_1 = require("@theia/core/shared/inversify");
19
+ const huggingface_preferences_1 = require("./huggingface-preferences");
20
+ const browser_1 = require("@theia/core/lib/browser");
21
+ const huggingface_frontend_application_contribution_1 = require("./huggingface-frontend-application-contribution");
22
+ const common_1 = require("../common");
23
+ exports.default = new inversify_1.ContainerModule(bind => {
24
+ bind(browser_1.PreferenceContribution).toConstantValue({ schema: huggingface_preferences_1.HuggingFacePreferencesSchema });
25
+ bind(huggingface_frontend_application_contribution_1.HuggingFaceFrontendApplicationContribution).toSelf().inSingletonScope();
26
+ bind(browser_1.FrontendApplicationContribution).toService(huggingface_frontend_application_contribution_1.HuggingFaceFrontendApplicationContribution);
27
+ bind(common_1.HuggingFaceLanguageModelsManager).toDynamicValue(ctx => {
28
+ const provider = ctx.container.get(browser_1.RemoteConnectionProvider);
29
+ return provider.createProxy(common_1.HUGGINGFACE_LANGUAGE_MODELS_MANAGER_PATH);
30
+ }).inSingletonScope();
31
+ });
32
+ //# sourceMappingURL=huggingface-frontend-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huggingface-frontend-module.js","sourceRoot":"","sources":["../../src/browser/huggingface-frontend-module.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF,4DAA+D;AAC/D,uEAAyE;AACzE,qDAAuJ;AACvJ,mHAA6G;AAC7G,sCAAuG;AAEvG,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,gCAAsB,CAAC,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,sDAA4B,EAAE,CAAC,CAAC;IACvF,IAAI,CAAC,0FAA0C,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAC7E,IAAI,CAAC,yCAA+B,CAAC,CAAC,SAAS,CAAC,0FAA0C,CAAC,CAAC;IAC5F,IAAI,CAAC,yCAAgC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;QACxD,MAAM,QAAQ,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAA4B,kCAAwB,CAAC,CAAC;QACxF,OAAO,QAAQ,CAAC,WAAW,CAAmC,iDAAwC,CAAC,CAAC;IAC5G,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC;AAC1B,CAAC,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { PreferenceSchema } from '@theia/core/lib/browser/preferences/preference-contribution';
2
+ export declare const API_KEY_PREF = "ai-features.huggingFace.apiKey";
3
+ export declare const MODELS_PREF = "ai-features.huggingFace.models";
4
+ export declare const HuggingFacePreferencesSchema: PreferenceSchema;
5
+ //# sourceMappingURL=huggingface-preferences.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huggingface-preferences.d.ts","sourceRoot":"","sources":["../../src/browser/huggingface-preferences.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6DAA6D,CAAC;AAG/F,eAAO,MAAM,YAAY,mCAAmC,CAAC;AAC7D,eAAO,MAAM,WAAW,mCAAmC,CAAC;AAE5D,eAAO,MAAM,4BAA4B,EAAE,gBAmB1C,CAAC"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2024 EclipseSource GmbH.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.HuggingFacePreferencesSchema = exports.MODELS_PREF = exports.API_KEY_PREF = void 0;
19
+ const ai_core_preferences_1 = require("@theia/ai-core/lib/browser/ai-core-preferences");
20
+ exports.API_KEY_PREF = 'ai-features.huggingFace.apiKey';
21
+ exports.MODELS_PREF = 'ai-features.huggingFace.models';
22
+ exports.HuggingFacePreferencesSchema = {
23
+ type: 'object',
24
+ properties: {
25
+ [exports.API_KEY_PREF]: {
26
+ type: 'string',
27
+ markdownDescription: 'Enter an API Key for your Hugging Face Account. **Please note:** By using this preference the Hugging Face API key will be stored in clear text\
28
+ on the machine running Theia. Use the environment variable `HUGGINGFACE_API_KEY` to set the key securely.',
29
+ title: ai_core_preferences_1.AI_CORE_PREFERENCES_TITLE,
30
+ },
31
+ [exports.MODELS_PREF]: {
32
+ type: 'array',
33
+ description: 'Hugging Face models to use',
34
+ title: ai_core_preferences_1.AI_CORE_PREFERENCES_TITLE,
35
+ default: ['bigcode/starcoder'],
36
+ items: {
37
+ type: 'string'
38
+ }
39
+ }
40
+ }
41
+ };
42
+ //# sourceMappingURL=huggingface-preferences.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huggingface-preferences.js","sourceRoot":"","sources":["../../src/browser/huggingface-preferences.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAGhF,wFAA2F;AAE9E,QAAA,YAAY,GAAG,gCAAgC,CAAC;AAChD,QAAA,WAAW,GAAG,gCAAgC,CAAC;AAE/C,QAAA,4BAA4B,GAAqB;IAC1D,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACR,CAAC,oBAAY,CAAC,EAAE;YACZ,IAAI,EAAE,QAAQ;YACd,mBAAmB,EAAE;sHACqF;YAC1G,KAAK,EAAE,+CAAyB;SACnC;QACD,CAAC,mBAAW,CAAC,EAAE;YACX,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,4BAA4B;YACzC,KAAK,EAAE,+CAAyB;YAChC,OAAO,EAAE,CAAC,mBAAmB,CAAC;YAC9B,KAAK,EAAE;gBACH,IAAI,EAAE,QAAQ;aACjB;SACJ;KACJ;CACJ,CAAC"}
@@ -0,0 +1,25 @@
1
+ export declare const HUGGINGFACE_LANGUAGE_MODELS_MANAGER_PATH = "/services/huggingface/language-model-manager";
2
+ export declare const HuggingFaceLanguageModelsManager: unique symbol;
3
+ export interface HuggingFaceModelDescription {
4
+ /**
5
+ * The identifier of the model which will be shown in the UI.
6
+ */
7
+ id: string;
8
+ /**
9
+ * The model ID as used by the Hugging Face API.
10
+ */
11
+ model: string;
12
+ /**
13
+ * Default request settings for the Hugging Face model.
14
+ */
15
+ defaultRequestSettings?: {
16
+ [key: string]: unknown;
17
+ };
18
+ }
19
+ export interface HuggingFaceLanguageModelsManager {
20
+ apiKey: string | undefined;
21
+ setApiKey(key: string | undefined): void;
22
+ createOrUpdateLanguageModels(...models: HuggingFaceModelDescription[]): Promise<void>;
23
+ removeLanguageModels(...modelIds: string[]): void;
24
+ }
25
+ //# sourceMappingURL=huggingface-language-models-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huggingface-language-models-manager.d.ts","sourceRoot":"","sources":["../../src/common/huggingface-language-models-manager.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,wCAAwC,iDAAiD,CAAC;AACvG,eAAO,MAAM,gCAAgC,eAA6C,CAAC;AAE3F,MAAM,WAAW,2BAA2B;IACxC;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,sBAAsB,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;CACvD;AAED,MAAM,WAAW,gCAAgC;IAC7C,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACzC,4BAA4B,CAAC,GAAG,MAAM,EAAE,2BAA2B,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtF,oBAAoB,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CACrD"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2024 EclipseSource GmbH.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.HuggingFaceLanguageModelsManager = exports.HUGGINGFACE_LANGUAGE_MODELS_MANAGER_PATH = void 0;
19
+ exports.HUGGINGFACE_LANGUAGE_MODELS_MANAGER_PATH = '/services/huggingface/language-model-manager';
20
+ exports.HuggingFaceLanguageModelsManager = Symbol('HuggingFaceLanguageModelsManager');
21
+ //# sourceMappingURL=huggingface-language-models-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huggingface-language-models-manager.js","sourceRoot":"","sources":["../../src/common/huggingface-language-models-manager.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAEnE,QAAA,wCAAwC,GAAG,8CAA8C,CAAC;AAC1F,QAAA,gCAAgC,GAAG,MAAM,CAAC,kCAAkC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './huggingface-language-models-manager';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAeA,cAAc,uCAAuC,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ // *****************************************************************************
5
+ // Copyright (C) 2024 EclipseSource GmbH.
6
+ //
7
+ // This program and the accompanying materials are made available under the
8
+ // terms of the Eclipse Public License v. 2.0 which is available at
9
+ // http://www.eclipse.org/legal/epl-2.0.
10
+ //
11
+ // This Source Code may also be made available under the following Secondary
12
+ // Licenses when the conditions for such availability set forth in the Eclipse
13
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
14
+ // with the GNU Classpath Exception which is available at
15
+ // https://www.gnu.org/software/classpath/license.html.
16
+ //
17
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
18
+ // *****************************************************************************
19
+ tslib_1.__exportStar(require("./huggingface-language-models-manager"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF,gFAAsD"}
@@ -0,0 +1,5 @@
1
+ import { ContainerModule } from '@theia/core/shared/inversify';
2
+ export declare const HuggingFaceModelFactory: unique symbol;
3
+ declare const _default: ContainerModule;
4
+ export default _default;
5
+ //# sourceMappingURL=huggingface-backend-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huggingface-backend-module.d.ts","sourceRoot":"","sources":["../../src/node/huggingface-backend-module.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAK/D,eAAO,MAAM,uBAAuB,eAAoC,CAAC;;AAEzE,wBAMG"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2024 EclipseSource GmbH.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.HuggingFaceModelFactory = void 0;
19
+ const inversify_1 = require("@theia/core/shared/inversify");
20
+ const huggingface_language_models_manager_1 = require("../common/huggingface-language-models-manager");
21
+ const core_1 = require("@theia/core");
22
+ const huggingface_language_models_manager_impl_1 = require("./huggingface-language-models-manager-impl");
23
+ exports.HuggingFaceModelFactory = Symbol('HuggingFaceModelFactory');
24
+ exports.default = new inversify_1.ContainerModule(bind => {
25
+ bind(huggingface_language_models_manager_impl_1.HuggingFaceLanguageModelsManagerImpl).toSelf().inSingletonScope();
26
+ bind(huggingface_language_models_manager_1.HuggingFaceLanguageModelsManager).toService(huggingface_language_models_manager_impl_1.HuggingFaceLanguageModelsManagerImpl);
27
+ bind(core_1.ConnectionHandler).toDynamicValue(ctx => new core_1.RpcConnectionHandler(huggingface_language_models_manager_1.HUGGINGFACE_LANGUAGE_MODELS_MANAGER_PATH, () => ctx.container.get(huggingface_language_models_manager_1.HuggingFaceLanguageModelsManager))).inSingletonScope();
28
+ });
29
+ //# sourceMappingURL=huggingface-backend-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huggingface-backend-module.js","sourceRoot":"","sources":["../../src/node/huggingface-backend-module.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAEhF,4DAA+D;AAC/D,uGAA2I;AAC3I,sCAAsE;AACtE,yGAAkG;AAErF,QAAA,uBAAuB,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAC;AAEzE,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,+EAAoC,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACvE,IAAI,CAAC,sEAAgC,CAAC,CAAC,SAAS,CAAC,+EAAoC,CAAC,CAAC;IACvF,IAAI,CAAC,wBAAiB,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CACzC,IAAI,2BAAoB,CAAC,8EAAwC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,sEAAgC,CAAC,CAAC,CAChI,CAAC,gBAAgB,EAAE,CAAC;AACzB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { LanguageModel, LanguageModelRequest, LanguageModelResponse, LanguageModelTextResponse } from '@theia/ai-core';
2
+ import { CancellationToken } from '@theia/core';
3
+ import { HfInference } from '@huggingface/inference';
4
+ export declare const HuggingFaceModelIdentifier: unique symbol;
5
+ export declare class HuggingFaceModel implements LanguageModel {
6
+ readonly id: string;
7
+ model: string;
8
+ apiKey: () => string | undefined;
9
+ readonly name?: string | undefined;
10
+ readonly vendor?: string | undefined;
11
+ readonly version?: string | undefined;
12
+ readonly family?: string | undefined;
13
+ readonly maxInputTokens?: number | undefined;
14
+ readonly maxOutputTokens?: number | undefined;
15
+ defaultRequestSettings?: Record<string, unknown> | undefined;
16
+ /**
17
+ * @param id the unique id for this language model. It will be used to identify the model in the UI.
18
+ * @param model the model id as it is used by the Hugging Face API
19
+ * @param apiKey function to retrieve the API key for Hugging Face
20
+ */
21
+ constructor(id: string, model: string, apiKey: () => string | undefined, name?: string | undefined, vendor?: string | undefined, version?: string | undefined, family?: string | undefined, maxInputTokens?: number | undefined, maxOutputTokens?: number | undefined, defaultRequestSettings?: Record<string, unknown> | undefined);
22
+ request(request: LanguageModelRequest, cancellationToken?: CancellationToken): Promise<LanguageModelResponse>;
23
+ protected getSettings(request: LanguageModelRequest): Record<string, unknown>;
24
+ protected handleNonStreamingRequest(hfInference: HfInference, request: LanguageModelRequest): Promise<LanguageModelTextResponse>;
25
+ protected handleStreamingRequest(hfInference: HfInference, request: LanguageModelRequest, cancellationToken?: CancellationToken): Promise<LanguageModelResponse>;
26
+ protected isStreamingSupported(model: string): boolean;
27
+ private initializeHfInference;
28
+ }
29
+ //# sourceMappingURL=huggingface-language-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huggingface-language-model.d.ts","sourceRoot":"","sources":["../../src/node/huggingface-language-model.ts"],"names":[],"mappings":"AAgBA,OAAO,EACH,aAAa,EACb,oBAAoB,EAEpB,qBAAqB,EAErB,yBAAyB,EAE5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,eAAO,MAAM,0BAA0B,eAAuC,CAAC;AAsB/E,qBAAa,gBAAiB,YAAW,aAAa;aAQ9B,EAAE,EAAE,MAAM;IACnB,KAAK,EAAE,MAAM;IACb,MAAM,EAAE,MAAM,MAAM,GAAG,SAAS;aACvB,IAAI,CAAC;aACL,MAAM,CAAC;aACP,OAAO,CAAC;aACR,MAAM,CAAC;aACP,cAAc,CAAC;aACf,eAAe,CAAC;IACzB,sBAAsB,CAAC;IAflC;;;;OAIG;gBAEiB,EAAE,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,MAAM,GAAG,SAAS,EACvB,IAAI,CAAC,oBAAQ,EACb,MAAM,CAAC,oBAAQ,EACf,OAAO,CAAC,oBAAQ,EAChB,MAAM,CAAC,oBAAQ,EACf,cAAc,CAAC,oBAAQ,EACvB,eAAe,CAAC,oBAAQ,EACjC,sBAAsB,CAAC,qCAAyB;IAGrD,OAAO,CAAC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IASnH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;cAQ7D,yBAAyB,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,yBAAyB,CAAC;cAyBtH,sBAAsB,CAClC,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,oBAAoB,EAC7B,iBAAiB,CAAC,EAAE,iBAAiB,GACtC,OAAO,CAAC,qBAAqB,CAAC;IAqCjC,SAAS,CAAC,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAKtD,OAAO,CAAC,qBAAqB;CAOhC"}
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2024 EclipseSource GmbH.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.HuggingFaceModel = exports.HuggingFaceModelIdentifier = void 0;
19
+ const inference_1 = require("@huggingface/inference");
20
+ exports.HuggingFaceModelIdentifier = Symbol('HuggingFaceModelIdentifier');
21
+ function toHuggingFacePrompt(messages) {
22
+ if (messages.length === 1) {
23
+ return messages[0].query;
24
+ }
25
+ return messages.map(message => `${toRoleLabel(message.actor)}: ${message.query}`).join('\n');
26
+ }
27
+ function toRoleLabel(actor) {
28
+ switch (actor) {
29
+ case 'user':
30
+ return 'User';
31
+ case 'ai':
32
+ return 'Assistant';
33
+ case 'system':
34
+ return 'System';
35
+ default:
36
+ return '';
37
+ }
38
+ }
39
+ class HuggingFaceModel {
40
+ /**
41
+ * @param id the unique id for this language model. It will be used to identify the model in the UI.
42
+ * @param model the model id as it is used by the Hugging Face API
43
+ * @param apiKey function to retrieve the API key for Hugging Face
44
+ */
45
+ constructor(id, model, apiKey, name, vendor, version, family, maxInputTokens, maxOutputTokens, defaultRequestSettings) {
46
+ this.id = id;
47
+ this.model = model;
48
+ this.apiKey = apiKey;
49
+ this.name = name;
50
+ this.vendor = vendor;
51
+ this.version = version;
52
+ this.family = family;
53
+ this.maxInputTokens = maxInputTokens;
54
+ this.maxOutputTokens = maxOutputTokens;
55
+ this.defaultRequestSettings = defaultRequestSettings;
56
+ }
57
+ async request(request, cancellationToken) {
58
+ const hfInference = this.initializeHfInference();
59
+ if (this.isStreamingSupported(this.model)) {
60
+ return this.handleStreamingRequest(hfInference, request, cancellationToken);
61
+ }
62
+ else {
63
+ return this.handleNonStreamingRequest(hfInference, request);
64
+ }
65
+ }
66
+ getSettings(request) {
67
+ const settings = request.settings ? request.settings : this.defaultRequestSettings;
68
+ if (!settings) {
69
+ return {};
70
+ }
71
+ return settings;
72
+ }
73
+ async handleNonStreamingRequest(hfInference, request) {
74
+ const settings = this.getSettings(request);
75
+ const response = await hfInference.textGeneration({
76
+ model: this.model,
77
+ inputs: toHuggingFacePrompt(request.messages),
78
+ parameters: {
79
+ ...settings
80
+ }
81
+ });
82
+ const stopWords = Array.isArray(settings.stop) ? settings.stop : [];
83
+ let cleanText = response.generated_text;
84
+ stopWords.forEach(stopWord => {
85
+ if (cleanText.endsWith(stopWord)) {
86
+ cleanText = cleanText.slice(0, -stopWord.length).trim();
87
+ }
88
+ });
89
+ return {
90
+ text: cleanText
91
+ };
92
+ }
93
+ async handleStreamingRequest(hfInference, request, cancellationToken) {
94
+ const settings = this.getSettings(request);
95
+ const stream = hfInference.textGenerationStream({
96
+ model: this.model,
97
+ inputs: toHuggingFacePrompt(request.messages),
98
+ parameters: {
99
+ ...settings
100
+ }
101
+ });
102
+ const stopWords = Array.isArray(settings.stop) ? settings.stop : [];
103
+ const asyncIterator = {
104
+ async *[Symbol.asyncIterator]() {
105
+ for await (const chunk of stream) {
106
+ let content = chunk.token.text;
107
+ stopWords.forEach(stopWord => {
108
+ if (content.endsWith(stopWord)) {
109
+ content = content.slice(0, -stopWord.length).trim();
110
+ }
111
+ });
112
+ yield { content };
113
+ if (cancellationToken === null || cancellationToken === void 0 ? void 0 : cancellationToken.isCancellationRequested) {
114
+ break;
115
+ }
116
+ }
117
+ }
118
+ };
119
+ return { stream: asyncIterator };
120
+ }
121
+ isStreamingSupported(model) {
122
+ // Assuming all models support streaming for now; can be refined if needed
123
+ return true;
124
+ }
125
+ initializeHfInference() {
126
+ const token = this.apiKey();
127
+ if (!token) {
128
+ throw new Error('Please provide a Hugging Face API token.');
129
+ }
130
+ return new inference_1.HfInference(token);
131
+ }
132
+ }
133
+ exports.HuggingFaceModel = HuggingFaceModel;
134
+ //# sourceMappingURL=huggingface-language-model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huggingface-language-model.js","sourceRoot":"","sources":["../../src/node/huggingface-language-model.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAYhF,sDAAqD;AAExC,QAAA,0BAA0B,GAAG,MAAM,CAAC,4BAA4B,CAAC,CAAC;AAE/E,SAAS,mBAAmB,CAAC,QAAuC;IAChE,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC7B,CAAC;IACD,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjG,CAAC;AAED,SAAS,WAAW,CAAC,KAAmB;IACpC,QAAQ,KAAK,EAAE,CAAC;QACZ,KAAK,MAAM;YACP,OAA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
+ import { HuggingFaceLanguageModelsManager, HuggingFaceModelDescription } from '../common';
3
+ export declare class HuggingFaceLanguageModelsManagerImpl implements HuggingFaceLanguageModelsManager {
4
+ protected _apiKey: string | undefined;
5
+ protected readonly languageModelRegistry: LanguageModelRegistry;
6
+ get apiKey(): string | undefined;
7
+ createOrUpdateLanguageModels(...modelDescriptions: HuggingFaceModelDescription[]): Promise<void>;
8
+ removeLanguageModels(...modelIds: string[]): void;
9
+ setApiKey(apiKey: string | undefined): void;
10
+ }
11
+ //# sourceMappingURL=huggingface-language-models-manager-impl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"huggingface-language-models-manager-impl.d.ts","sourceRoot":"","sources":["../../src/node/huggingface-language-models-manager-impl.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAGvD,OAAO,EAAE,gCAAgC,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAE1F,qBACa,oCAAqC,YAAW,gCAAgC;IAEzF,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAGtC,SAAS,CAAC,QAAQ,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;IAEhE,IAAI,MAAM,IAAI,MAAM,GAAG,SAAS,CAE/B;IAEK,4BAA4B,CAAC,GAAG,iBAAiB,EAAE,2BAA2B,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAgCtG,oBAAoB,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI;IAIjD,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;CAG9C"}