@theia/ai-ollama 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 +30 -0
  2. package/lib/browser/ollama-frontend-application-contribution.d.ts +13 -0
  3. package/lib/browser/ollama-frontend-application-contribution.d.ts.map +1 -0
  4. package/lib/browser/ollama-frontend-application-contribution.js +91 -0
  5. package/lib/browser/ollama-frontend-application-contribution.js.map +1 -0
  6. package/lib/browser/ollama-frontend-module.d.ts +4 -0
  7. package/lib/browser/ollama-frontend-module.d.ts.map +1 -0
  8. package/lib/browser/ollama-frontend-module.js +32 -0
  9. package/lib/browser/ollama-frontend-module.js.map +1 -0
  10. package/lib/browser/ollama-preferences.d.ts +5 -0
  11. package/lib/browser/ollama-preferences.d.ts.map +1 -0
  12. package/lib/browser/ollama-preferences.js +40 -0
  13. package/lib/browser/ollama-preferences.js.map +1 -0
  14. package/lib/common/index.d.ts +2 -0
  15. package/lib/common/index.d.ts.map +1 -0
  16. package/lib/common/index.js +20 -0
  17. package/lib/common/index.js.map +1 -0
  18. package/lib/common/ollama-language-models-manager.d.ts +25 -0
  19. package/lib/common/ollama-language-models-manager.d.ts.map +1 -0
  20. package/lib/common/ollama-language-models-manager.js +21 -0
  21. package/lib/common/ollama-language-models-manager.js.map +1 -0
  22. package/lib/node/ollama-backend-module.d.ts +5 -0
  23. package/lib/node/ollama-backend-module.d.ts.map +1 -0
  24. package/lib/node/ollama-backend-module.js +29 -0
  25. package/lib/node/ollama-backend-module.js.map +1 -0
  26. package/lib/node/ollama-language-model.d.ts +31 -0
  27. package/lib/node/ollama-language-model.d.ts.map +1 -0
  28. package/lib/node/ollama-language-model.js +148 -0
  29. package/lib/node/ollama-language-model.js.map +1 -0
  30. package/lib/node/ollama-language-models-manager-impl.d.ts +11 -0
  31. package/lib/node/ollama-language-models-manager-impl.d.ts.map +1 -0
  32. package/lib/node/ollama-language-models-manager-impl.js +63 -0
  33. package/lib/node/ollama-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 +54 -0
  39. package/src/browser/ollama-frontend-application-contribution.ts +91 -0
  40. package/src/browser/ollama-frontend-module.ts +31 -0
  41. package/src/browser/ollama-preferences.ts +40 -0
  42. package/src/common/index.ts +16 -0
  43. package/src/common/ollama-language-models-manager.ts +40 -0
  44. package/src/node/ollama-backend-module.ts +30 -0
  45. package/src/node/ollama-language-model.ts +167 -0
  46. package/src/node/ollama-language-models-manager-impl.ts +67 -0
  47. package/src/package.spec.ts +27 -0
package/README.md ADDED
@@ -0,0 +1,30 @@
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 - Ollama EXTENSION</h2>
8
+
9
+ <hr />
10
+
11
+ </div>
12
+
13
+ ## Description
14
+
15
+ The `@theia/ai-ollama` integrates Ollama's models with Theia AI.
16
+
17
+ ## Additional Information
18
+
19
+ - [Theia - GitHub](https://github.com/eclipse-theia/theia)
20
+ - [Theia - Website](https://theia-ide.org/)
21
+
22
+ ## License
23
+
24
+ - [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
25
+ - [(Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
26
+
27
+ ## Trademark
28
+
29
+ "Theia" is a trademark of the Eclipse Foundation
30
+ <https://www.eclipse.org/theia>
@@ -0,0 +1,13 @@
1
+ import { FrontendApplicationContribution, PreferenceService } from '@theia/core/lib/browser';
2
+ import { OllamaLanguageModelsManager, OllamaModelDescription } from '../common';
3
+ import { RequestSetting } from '@theia/ai-core/lib/browser/ai-core-preferences';
4
+ export declare class OllamaFrontendApplicationContribution implements FrontendApplicationContribution {
5
+ protected preferenceService: PreferenceService;
6
+ protected manager: OllamaLanguageModelsManager;
7
+ protected prevModels: string[];
8
+ onStart(): void;
9
+ protected handleModelChanges(newModels: string[]): void;
10
+ protected handleRequestSettingsChange(newSettings: RequestSetting[]): void;
11
+ protected createOllamaModelDescription(modelId: string, requestSettings: RequestSetting[]): OllamaModelDescription;
12
+ }
13
+ //# sourceMappingURL=ollama-frontend-application-contribution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ollama-frontend-application-contribution.d.ts","sourceRoot":"","sources":["../../src/browser/ollama-frontend-application-contribution.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,+BAA+B,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE7F,OAAO,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAEhF,OAAO,EAAoC,cAAc,EAAE,MAAM,gDAAgD,CAAC;AAGlH,qBACa,qCAAsC,YAAW,+BAA+B;IAGzF,SAAS,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAG/C,SAAS,CAAC,OAAO,EAAE,2BAA2B,CAAC;IAE/C,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,2BAA2B,CAAC,WAAW,EAAE,cAAc,EAAE,GAAG,IAAI;IAK1E,SAAS,CAAC,4BAA4B,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,GAAG,sBAAsB;CAgBrH"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2024 TypeFox 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.OllamaFrontendApplicationContribution = 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 ollama_preferences_1 = require("./ollama-preferences");
24
+ const ai_core_preferences_1 = require("@theia/ai-core/lib/browser/ai-core-preferences");
25
+ const OLLAMA_PROVIDER_ID = 'ollama';
26
+ let OllamaFrontendApplicationContribution = class OllamaFrontendApplicationContribution {
27
+ constructor() {
28
+ this.prevModels = [];
29
+ }
30
+ onStart() {
31
+ this.preferenceService.ready.then(() => {
32
+ const host = this.preferenceService.get(ollama_preferences_1.HOST_PREF, 'http://localhost:11434');
33
+ this.manager.setHost(host);
34
+ const models = this.preferenceService.get(ollama_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.createOllamaModelDescription(modelId, requestSettings)));
37
+ this.prevModels = [...models];
38
+ this.preferenceService.onPreferenceChanged(event => {
39
+ if (event.preferenceName === ollama_preferences_1.HOST_PREF) {
40
+ this.manager.setHost(event.newValue);
41
+ }
42
+ else if (event.preferenceName === ollama_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.handleRequestSettingsChange(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);
57
+ const requestSettings = this.preferenceService.get(ai_core_preferences_1.PREFERENCE_NAME_REQUEST_SETTINGS, []);
58
+ this.manager.createOrUpdateLanguageModels(...modelsToAdd.map(modelId => this.createOllamaModelDescription(modelId, requestSettings)));
59
+ this.prevModels = newModels;
60
+ }
61
+ handleRequestSettingsChange(newSettings) {
62
+ const models = this.preferenceService.get(ollama_preferences_1.MODELS_PREF, []);
63
+ this.manager.createOrUpdateLanguageModels(...models.map(modelId => this.createOllamaModelDescription(modelId, newSettings)));
64
+ }
65
+ createOllamaModelDescription(modelId, requestSettings) {
66
+ const id = `${OLLAMA_PROVIDER_ID}/${modelId}`;
67
+ const matchingSettings = requestSettings.filter(setting => (!setting.providerId || setting.providerId === OLLAMA_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.OllamaFrontendApplicationContribution = OllamaFrontendApplicationContribution;
80
+ tslib_1.__decorate([
81
+ (0, inversify_1.inject)(browser_1.PreferenceService),
82
+ tslib_1.__metadata("design:type", Object)
83
+ ], OllamaFrontendApplicationContribution.prototype, "preferenceService", void 0);
84
+ tslib_1.__decorate([
85
+ (0, inversify_1.inject)(common_1.OllamaLanguageModelsManager),
86
+ tslib_1.__metadata("design:type", Object)
87
+ ], OllamaFrontendApplicationContribution.prototype, "manager", void 0);
88
+ exports.OllamaFrontendApplicationContribution = OllamaFrontendApplicationContribution = tslib_1.__decorate([
89
+ (0, inversify_1.injectable)()
90
+ ], OllamaFrontendApplicationContribution);
91
+ //# sourceMappingURL=ollama-frontend-application-contribution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ollama-frontend-application-contribution.js","sourceRoot":"","sources":["../../src/browser/ollama-frontend-application-contribution.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,mCAAmC;AACnC,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,sCAAgF;AAChF,6DAA8D;AAC9D,wFAAkH;AAElH,MAAM,kBAAkB,GAAG,QAAQ,CAAC;AAE7B,IAAM,qCAAqC,GAA3C,MAAM,qCAAqC;IAA3C;QAQO,eAAU,GAAa,EAAE,CAAC;IA0DxC,CAAC;IAxDG,OAAO;QACH,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;YACnC,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAS,8BAAS,EAAE,wBAAwB,CAAC,CAAC;YACrF,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAE3B,MAAM,MAAM,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAW,gCAAW,EAAE,EAAE,CAAC,CAAC;YACrE,MAAM,eAAe,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAmB,sDAAgC,EAAE,EAAE,CAAC,CAAC;YAC3G,IAAI,CAAC,OAAO,CAAC,4BAA4B,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IA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A;AAlEY,sFAAqC;AAGpC;IADT,IAAA,kBAAM,EAAC,2BAAiB,CAAC;;gFACqB;AAGrC;IADT,IAAA,kBAAM,EAAC,oCAA2B,CAAC;;sEACW;gDANtC,qCAAqC;IADjD,IAAA,sBAAU,GAAE;GACA,qCAAqC,CAkEjD"}
@@ -0,0 +1,4 @@
1
+ import { ContainerModule } from '@theia/core/shared/inversify';
2
+ declare const _default: ContainerModule;
3
+ export default _default;
4
+ //# sourceMappingURL=ollama-frontend-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ollama-frontend-module.d.ts","sourceRoot":"","sources":["../../src/browser/ollama-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 TypeFox 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 ollama_preferences_1 = require("./ollama-preferences");
20
+ const browser_1 = require("@theia/core/lib/browser");
21
+ const ollama_frontend_application_contribution_1 = require("./ollama-frontend-application-contribution");
22
+ const common_1 = require("../common");
23
+ exports.default = new inversify_1.ContainerModule(bind => {
24
+ bind(browser_1.PreferenceContribution).toConstantValue({ schema: ollama_preferences_1.OllamaPreferencesSchema });
25
+ bind(ollama_frontend_application_contribution_1.OllamaFrontendApplicationContribution).toSelf().inSingletonScope();
26
+ bind(browser_1.FrontendApplicationContribution).toService(ollama_frontend_application_contribution_1.OllamaFrontendApplicationContribution);
27
+ bind(common_1.OllamaLanguageModelsManager).toDynamicValue(ctx => {
28
+ const provider = ctx.container.get(browser_1.RemoteConnectionProvider);
29
+ return provider.createProxy(common_1.OLLAMA_LANGUAGE_MODELS_MANAGER_PATH);
30
+ }).inSingletonScope();
31
+ });
32
+ //# sourceMappingURL=ollama-frontend-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ollama-frontend-module.js","sourceRoot":"","sources":["../../src/browser/ollama-frontend-module.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,mCAAmC;AACnC,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,6DAA+D;AAC/D,qDAAuJ;AACvJ,yGAAmG;AACnG,sCAA6F;AAE7F,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,gCAAsB,CAAC,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,4CAAuB,EAAE,CAAC,CAAC;IAClF,IAAI,CAAC,gFAAqC,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACxE,IAAI,CAAC,yCAA+B,CAAC,CAAC,SAAS,CAAC,gFAAqC,CAAC,CAAC;IACvF,IAAI,CAAC,oCAA2B,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;QACnD,MAAM,QAAQ,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAA4B,kCAAwB,CAAC,CAAC;QACxF,OAAO,QAAQ,CAAC,WAAW,CAA8B,4CAAmC,CAAC,CAAC;IAClG,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 HOST_PREF = "ai-features.ollama.ollamaHost";
3
+ export declare const MODELS_PREF = "ai-features.ollama.ollamaModels";
4
+ export declare const OllamaPreferencesSchema: PreferenceSchema;
5
+ //# sourceMappingURL=ollama-preferences.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ollama-preferences.d.ts","sourceRoot":"","sources":["../../src/browser/ollama-preferences.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6DAA6D,CAAC;AAG/F,eAAO,MAAM,SAAS,kCAAkC,CAAC;AACzD,eAAO,MAAM,WAAW,oCAAoC,CAAC;AAE7D,eAAO,MAAM,uBAAuB,EAAE,gBAiBrC,CAAC"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2024 TypeFox 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.OllamaPreferencesSchema = exports.MODELS_PREF = exports.HOST_PREF = void 0;
19
+ const ai_core_preferences_1 = require("@theia/ai-core/lib/browser/ai-core-preferences");
20
+ exports.HOST_PREF = 'ai-features.ollama.ollamaHost';
21
+ exports.MODELS_PREF = 'ai-features.ollama.ollamaModels';
22
+ exports.OllamaPreferencesSchema = {
23
+ type: 'object',
24
+ properties: {
25
+ [exports.HOST_PREF]: {
26
+ type: 'string',
27
+ title: ai_core_preferences_1.AI_CORE_PREFERENCES_TITLE,
28
+ default: 'http://localhost:11434'
29
+ },
30
+ [exports.MODELS_PREF]: {
31
+ type: 'array',
32
+ title: ai_core_preferences_1.AI_CORE_PREFERENCES_TITLE,
33
+ default: ['llama3', 'gemma2'],
34
+ items: {
35
+ type: 'string'
36
+ }
37
+ }
38
+ }
39
+ };
40
+ //# sourceMappingURL=ollama-preferences.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ollama-preferences.js","sourceRoot":"","sources":["../../src/browser/ollama-preferences.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,mCAAmC;AACnC,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,SAAS,GAAG,+BAA+B,CAAC;AAC5C,QAAA,WAAW,GAAG,iCAAiC,CAAC;AAEhD,QAAA,uBAAuB,GAAqB;IACrD,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACR,CAAC,iBAAS,CAAC,EAAE;YACT,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,+CAAyB;YAChC,OAAO,EAAE,wBAAwB;SACpC;QACD,CAAC,mBAAW,CAAC,EAAE;YACX,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,+CAAyB;YAChC,OAAO,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;YAC7B,KAAK,EAAE;gBACH,IAAI,EAAE,QAAQ;aACjB;SACJ;KACJ;CACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './ollama-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,kCAAkC,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 TypeFox 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("./ollama-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,mCAAmC;AACnC,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,2EAAiD"}
@@ -0,0 +1,25 @@
1
+ export declare const OLLAMA_LANGUAGE_MODELS_MANAGER_PATH = "/services/ollama/language-model-manager";
2
+ export declare const OllamaLanguageModelsManager: unique symbol;
3
+ export interface OllamaModelDescription {
4
+ /**
5
+ * The identifier of the model which will be shown in the UI.
6
+ */
7
+ id: string;
8
+ /**
9
+ * The name or ID of the model in the Ollama environment.
10
+ */
11
+ model: string;
12
+ /**
13
+ * Default request settings for the Ollama model.
14
+ */
15
+ defaultRequestSettings?: {
16
+ [key: string]: unknown;
17
+ };
18
+ }
19
+ export interface OllamaLanguageModelsManager {
20
+ host: string | undefined;
21
+ setHost(host: string | undefined): void;
22
+ createOrUpdateLanguageModels(...models: OllamaModelDescription[]): Promise<void>;
23
+ removeLanguageModels(...modelIds: string[]): void;
24
+ }
25
+ //# sourceMappingURL=ollama-language-models-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ollama-language-models-manager.d.ts","sourceRoot":"","sources":["../../src/common/ollama-language-models-manager.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,mCAAmC,4CAA4C,CAAC;AAC7F,eAAO,MAAM,2BAA2B,eAAwC,CAAC;AAEjF,MAAM,WAAW,sBAAsB;IACnC;;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,2BAA2B;IACxC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACxC,4BAA4B,CAAC,GAAG,MAAM,EAAE,sBAAsB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjF,oBAAoB,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CACrD"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2024 TypeFox 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.OllamaLanguageModelsManager = exports.OLLAMA_LANGUAGE_MODELS_MANAGER_PATH = void 0;
19
+ exports.OLLAMA_LANGUAGE_MODELS_MANAGER_PATH = '/services/ollama/language-model-manager';
20
+ exports.OllamaLanguageModelsManager = Symbol('OllamaLanguageModelsManager');
21
+ //# sourceMappingURL=ollama-language-models-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ollama-language-models-manager.js","sourceRoot":"","sources":["../../src/common/ollama-language-models-manager.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,mCAAmC;AACnC,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,mCAAmC,GAAG,yCAAyC,CAAC;AAChF,QAAA,2BAA2B,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { ContainerModule } from '@theia/core/shared/inversify';
2
+ export declare const OllamaModelFactory: unique symbol;
3
+ declare const _default: ContainerModule;
4
+ export default _default;
5
+ //# sourceMappingURL=ollama-backend-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ollama-backend-module.d.ts","sourceRoot":"","sources":["../../src/node/ollama-backend-module.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAK/D,eAAO,MAAM,kBAAkB,eAA+B,CAAC;;AAE/D,wBAMG"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2024 TypeFox 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.OllamaModelFactory = void 0;
19
+ const inversify_1 = require("@theia/core/shared/inversify");
20
+ const ollama_language_models_manager_1 = require("../common/ollama-language-models-manager");
21
+ const core_1 = require("@theia/core");
22
+ const ollama_language_models_manager_impl_1 = require("./ollama-language-models-manager-impl");
23
+ exports.OllamaModelFactory = Symbol('OllamaModelFactory');
24
+ exports.default = new inversify_1.ContainerModule(bind => {
25
+ bind(ollama_language_models_manager_impl_1.OllamaLanguageModelsManagerImpl).toSelf().inSingletonScope();
26
+ bind(ollama_language_models_manager_1.OllamaLanguageModelsManager).toService(ollama_language_models_manager_impl_1.OllamaLanguageModelsManagerImpl);
27
+ bind(core_1.ConnectionHandler).toDynamicValue(ctx => new core_1.RpcConnectionHandler(ollama_language_models_manager_1.OLLAMA_LANGUAGE_MODELS_MANAGER_PATH, () => ctx.container.get(ollama_language_models_manager_1.OllamaLanguageModelsManager))).inSingletonScope();
28
+ });
29
+ //# sourceMappingURL=ollama-backend-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ollama-backend-module.js","sourceRoot":"","sources":["../../src/node/ollama-backend-module.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,mCAAmC;AACnC,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,6FAA4H;AAC5H,sCAAsE;AACtE,+FAAwF;AAE3E,QAAA,kBAAkB,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAE/D,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,qEAA+B,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAClE,IAAI,CAAC,4DAA2B,CAAC,CAAC,SAAS,CAAC,qEAA+B,CAAC,CAAC;IAC7E,IAAI,CAAC,wBAAiB,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CACzC,IAAI,2BAAoB,CAAC,oEAAmC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,4DAA2B,CAAC,CAAC,CACtH,CAAC,gBAAgB,EAAE,CAAC;AACzB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { LanguageModel, LanguageModelParsedResponse, LanguageModelRequest, LanguageModelRequestMessage, LanguageModelResponse, ToolRequest } from '@theia/ai-core';
2
+ import { CancellationToken } from '@theia/core';
3
+ import { ChatRequest, Message, Ollama, Tool } from 'ollama';
4
+ export declare const OllamaModelIdentifier: unique symbol;
5
+ export declare class OllamaModel implements LanguageModel {
6
+ readonly id: string;
7
+ protected readonly model: string;
8
+ protected host: () => string | undefined;
9
+ defaultRequestSettings?: {
10
+ [key: string]: unknown;
11
+ } | undefined;
12
+ protected readonly DEFAULT_REQUEST_SETTINGS: Partial<Omit<ChatRequest, 'stream' | 'model'>>;
13
+ readonly providerId = "ollama";
14
+ readonly vendor: string;
15
+ /**
16
+ * @param id the unique id for this language model. It will be used to identify the model in the UI.
17
+ * @param model the unique model name as used in the Ollama environment.
18
+ * @param hostProvider a function to provide the host URL for the Ollama server.
19
+ * @param defaultRequestSettings optional default settings for requests made using this model.
20
+ */
21
+ constructor(id: string, model: string, host: () => string | undefined, defaultRequestSettings?: {
22
+ [key: string]: unknown;
23
+ } | undefined);
24
+ protected getSettings(request: LanguageModelRequest): Partial<ChatRequest>;
25
+ request(request: LanguageModelRequest, cancellationToken?: CancellationToken): Promise<LanguageModelResponse>;
26
+ protected handleStructuredOutputRequest(ollama: Ollama, request: LanguageModelRequest): Promise<LanguageModelParsedResponse>;
27
+ protected initializeOllama(): Ollama;
28
+ protected toOllamaTool(tool: ToolRequest): Tool;
29
+ protected toOllamaMessage(message: LanguageModelRequestMessage): Message;
30
+ }
31
+ //# sourceMappingURL=ollama-language-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ollama-language-model.d.ts","sourceRoot":"","sources":["../../src/node/ollama-language-model.ts"],"names":[],"mappings":"AAgBA,OAAO,EACH,aAAa,EACb,2BAA2B,EAC3B,oBAAoB,EACpB,2BAA2B,EAC3B,qBAAqB,EAErB,WAAW,EACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,WAAW,EAAgB,OAAO,EAAE,MAAM,EAAW,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnF,eAAO,MAAM,qBAAqB,eAAkC,CAAC;AAErE,qBAAa,WAAY,YAAW,aAAa;aAgBzB,EAAE,EAAE,MAAM;IAC1B,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM;IAChC,SAAS,CAAC,IAAI,EAAE,MAAM,MAAM,GAAG,SAAS;IACjC,sBAAsB,CAAC;;;IAjBlC,SAAS,CAAC,QAAQ,CAAC,wBAAwB,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC,CAEzF;IAEF,QAAQ,CAAC,UAAU,YAAY;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAY;IAEnC;;;;;OAKG;gBAEiB,EAAE,EAAE,MAAM,EACP,KAAK,EAAE,MAAM,EACtB,IAAI,EAAE,MAAM,MAAM,GAAG,SAAS,EACjC,sBAAsB,CAAC;;iBAA4B;IAG9D,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,WAAW,CAAC;IAOpE,OAAO,CAAC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,qBAAqB,CAAC;cA6BnG,6BAA6B,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAyBlI,SAAS,CAAC,gBAAgB,IAAI,MAAM;IAQpC,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI;IAiC/C,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,2BAA2B,GAAG,OAAO;CAY3E"}
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2024 TypeFox 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.OllamaModel = exports.OllamaModelIdentifier = void 0;
19
+ const ollama_1 = require("ollama");
20
+ exports.OllamaModelIdentifier = Symbol('OllamaModelIdentifier');
21
+ class OllamaModel {
22
+ /**
23
+ * @param id the unique id for this language model. It will be used to identify the model in the UI.
24
+ * @param model the unique model name as used in the Ollama environment.
25
+ * @param hostProvider a function to provide the host URL for the Ollama server.
26
+ * @param defaultRequestSettings optional default settings for requests made using this model.
27
+ */
28
+ constructor(id, model, host, defaultRequestSettings) {
29
+ this.id = id;
30
+ this.model = model;
31
+ this.host = host;
32
+ this.defaultRequestSettings = defaultRequestSettings;
33
+ this.DEFAULT_REQUEST_SETTINGS = {
34
+ keep_alive: '15m'
35
+ };
36
+ this.providerId = 'ollama';
37
+ this.vendor = 'Ollama';
38
+ }
39
+ getSettings(request) {
40
+ var _a, _b;
41
+ const settings = (_b = (_a = request.settings) !== null && _a !== void 0 ? _a : this.defaultRequestSettings) !== null && _b !== void 0 ? _b : {};
42
+ return {
43
+ options: settings
44
+ };
45
+ }
46
+ async request(request, cancellationToken) {
47
+ var _a, _b;
48
+ const settings = this.getSettings(request);
49
+ const ollama = this.initializeOllama();
50
+ if (((_a = request.response_format) === null || _a === void 0 ? void 0 : _a.type) === 'json_schema') {
51
+ return this.handleStructuredOutputRequest(ollama, request);
52
+ }
53
+ const response = await ollama.chat({
54
+ model: this.model,
55
+ ...this.DEFAULT_REQUEST_SETTINGS,
56
+ ...settings,
57
+ messages: request.messages.map(this.toOllamaMessage),
58
+ stream: true,
59
+ tools: (_b = request.tools) === null || _b === void 0 ? void 0 : _b.map(this.toOllamaTool),
60
+ });
61
+ cancellationToken === null || cancellationToken === void 0 ? void 0 : cancellationToken.onCancellationRequested(() => {
62
+ response.abort();
63
+ });
64
+ async function* wrapAsyncIterator(inputIterable) {
65
+ for await (const item of inputIterable) {
66
+ // TODO handle tool calls
67
+ yield { content: item.message.content };
68
+ }
69
+ }
70
+ return { stream: wrapAsyncIterator(response) };
71
+ }
72
+ async handleStructuredOutputRequest(ollama, request) {
73
+ const settings = this.getSettings(request);
74
+ const result = await ollama.chat({
75
+ ...settings,
76
+ ...this.DEFAULT_REQUEST_SETTINGS,
77
+ model: this.model,
78
+ messages: request.messages.map(this.toOllamaMessage),
79
+ format: 'json',
80
+ stream: false,
81
+ });
82
+ try {
83
+ return {
84
+ content: result.message.content,
85
+ parsed: JSON.parse(result.message.content)
86
+ };
87
+ }
88
+ catch (error) {
89
+ // TODO use ILogger
90
+ console.log('Failed to parse structured response from the language model.', error);
91
+ return {
92
+ content: result.message.content,
93
+ parsed: {}
94
+ };
95
+ }
96
+ }
97
+ initializeOllama() {
98
+ const host = this.host();
99
+ if (!host) {
100
+ throw new Error('Please provide OLLAMA_HOST in preferences or via environment variable');
101
+ }
102
+ return new ollama_1.Ollama({ host: host });
103
+ }
104
+ toOllamaTool(tool) {
105
+ var _a, _b, _c, _d, _e, _f, _g;
106
+ const transform = (props) => {
107
+ if (!props) {
108
+ return undefined;
109
+ }
110
+ const result = {};
111
+ for (const key in props) {
112
+ if (Object.prototype.hasOwnProperty.call(props, key)) {
113
+ result[key] = {
114
+ type: props[key].type,
115
+ description: key
116
+ };
117
+ }
118
+ }
119
+ return result;
120
+ };
121
+ return {
122
+ type: 'function',
123
+ function: {
124
+ name: tool.name,
125
+ description: (_a = tool.description) !== null && _a !== void 0 ? _a : 'Tool named ' + tool.name,
126
+ parameters: {
127
+ type: (_c = (_b = tool.parameters) === null || _b === void 0 ? void 0 : _b.type) !== null && _c !== void 0 ? _c : 'object',
128
+ required: Object.keys((_e = (_d = tool.parameters) === null || _d === void 0 ? void 0 : _d.properties) !== null && _e !== void 0 ? _e : {}),
129
+ properties: (_g = transform((_f = tool.parameters) === null || _f === void 0 ? void 0 : _f.properties)) !== null && _g !== void 0 ? _g : {}
130
+ },
131
+ }
132
+ };
133
+ }
134
+ toOllamaMessage(message) {
135
+ if (message.actor === 'ai') {
136
+ return { role: 'assistant', content: message.query || '' };
137
+ }
138
+ if (message.actor === 'user') {
139
+ return { role: 'user', content: message.query || '' };
140
+ }
141
+ if (message.actor === 'system') {
142
+ return { role: 'system', content: message.query || '' };
143
+ }
144
+ return { role: 'system', content: '' };
145
+ }
146
+ }
147
+ exports.OllamaModel = OllamaModel;
148
+ //# sourceMappingURL=ollama-language-model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ollama-language-model.js","sourceRoot":"","sources":["../../src/node/ollama-language-model.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,mCAAmC;AACnC,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,mCAAmF;AAEtE,QAAA,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAErE,MAAa,WAAW;IASpB;;;;;OAKG;IACH,YACoB,EAAU,EACP,KAAa,EACtB,IAA8B,EACjC,sBAAmD;QAH1C,OAAE,GAAF,EAAE,CAAQ;QACP,UAAK,GAAL,KAAK,CAAQ;QACtB,SAAI,GAAJ,IAAI,CAA0B;QACjC,2BAAsB,GAAtB,sBAAsB,CAA6B;QAjB3C,6BAAwB,GAAmD;YAC1F,UAAU,EAAE,KAAK;SACpB,CAAC;QAEO,eAAU,GAAG,QAAQ,CAAC;QACtB,WAAM,GAAW,QAAQ,CAAC;IAa/B,CAAC;IAEK,WAAW,CAAC,OAA6B;;QAC/C,MAAM,QAAQ,GAAG,MAAA,MAAA,OAAO,CAAC,QAAQ,mCAAI,IAAI,CAAC,sBAAsB,mCAAI,EAAE,CAAC;QACvE,OAAO;YACH,OAAO,EAAE,QAA4B;SACxC,CAAC;IACN,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAA6B,EAAE,iBAAqC;;QAC9E,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC3C,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAEvC,IAAI,CAAA,MAAA,OAAO,CAAC,eAAe,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LanguageModelsManager, OllamaModelDescription } from '../common';
3
+ export declare class OllamaLanguageModelsManagerImpl implements OllamaLanguageModelsManager {
4
+ protected _host: string | undefined;
5
+ protected readonly languageModelRegistry: LanguageModelRegistry;
6
+ get host(): string | undefined;
7
+ createOrUpdateLanguageModels(...models: OllamaModelDescription[]): Promise<void>;
8
+ removeLanguageModels(...modelIds: string[]): void;
9
+ setHost(host: string | undefined): void;
10
+ }
11
+ //# sourceMappingURL=ollama-language-models-manager-impl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ollama-language-models-manager-impl.d.ts","sourceRoot":"","sources":["../../src/node/ollama-language-models-manager-impl.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAGvD,OAAO,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAEhF,qBACa,+BAAgC,YAAW,2BAA2B;IAE/E,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAGpC,SAAS,CAAC,QAAQ,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;IAEhE,IAAI,IAAI,IAAI,MAAM,GAAG,SAAS,CAE7B;IAIK,4BAA4B,CAAC,GAAG,MAAM,EAAE,sBAAsB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBtF,oBAAoB,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI;IAIjD,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;CAG1C"}