@theia/ai-openai 1.54.0
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.
- package/README.md +31 -0
- package/lib/browser/openai-frontend-application-contribution.d.ts +10 -0
- package/lib/browser/openai-frontend-application-contribution.d.ts.map +1 -0
- package/lib/browser/openai-frontend-application-contribution.js +99 -0
- package/lib/browser/openai-frontend-application-contribution.js.map +1 -0
- package/lib/browser/openai-frontend-module.d.ts +4 -0
- package/lib/browser/openai-frontend-module.d.ts.map +1 -0
- package/lib/browser/openai-frontend-module.js +32 -0
- package/lib/browser/openai-frontend-module.js.map +1 -0
- package/lib/browser/openai-preferences.d.ts +6 -0
- package/lib/browser/openai-preferences.d.ts.map +1 -0
- package/lib/browser/openai-preferences.js +67 -0
- package/lib/browser/openai-preferences.js.map +1 -0
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +20 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/openai-language-models-manager.d.ts +23 -0
- package/lib/common/openai-language-models-manager.d.ts.map +1 -0
- package/lib/common/openai-language-models-manager.js +21 -0
- package/lib/common/openai-language-models-manager.js.map +1 -0
- package/lib/node/openai-backend-module.d.ts +5 -0
- package/lib/node/openai-backend-module.d.ts.map +1 -0
- package/lib/node/openai-backend-module.js +29 -0
- package/lib/node/openai-backend-module.js.map +1 -0
- package/lib/node/openai-language-model.d.ts +24 -0
- package/lib/node/openai-language-model.d.ts.map +1 -0
- package/lib/node/openai-language-model.js +174 -0
- package/lib/node/openai-language-model.js.map +1 -0
- package/lib/node/openai-language-models-manager-impl.d.ts +11 -0
- package/lib/node/openai-language-models-manager-impl.d.ts.map +1 -0
- package/lib/node/openai-language-models-manager-impl.js +77 -0
- package/lib/node/openai-language-models-manager-impl.js.map +1 -0
- package/lib/package.spec.d.ts +1 -0
- package/lib/package.spec.d.ts.map +1 -0
- package/lib/package.spec.js +26 -0
- package/lib/package.spec.js.map +1 -0
- package/package.json +54 -0
- package/src/browser/openai-frontend-application-contribution.ts +98 -0
- package/src/browser/openai-frontend-module.ts +31 -0
- package/src/browser/openai-preferences.ts +67 -0
- package/src/common/index.ts +16 -0
- package/src/common/openai-language-models-manager.ts +37 -0
- package/src/node/openai-backend-module.ts +30 -0
- package/src/node/openai-language-model.ts +187 -0
- package/src/node/openai-language-models-manager-impl.ts +73 -0
- package/src/package.spec.ts +28 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-language-model.js","sourceRoot":"","sources":["../../src/node/openai-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;;;AAWhF,mCAA4B;AAKf,QAAA,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAErE,SAAS,eAAe,CAAC,OAAoC;IACzD,OAAO;QACH,IAAI,EAAE,YAAY,CAAC,OAAO,CAAC;QAC3B,OAAO,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE;KAC/B,CAAC;AACN,CAAC;AAED,SAAS,YAAY,CAAC,OAAoC;IACtD,QAAQ,OAAO,CAAC,KAAK,EAAE,CAAC;QACpB,KAAK,QAAQ;YACT,OAAO,QAAQ,CAAC;QACpB,KAAK,IAAI;YACL,OAAO,WAAW,CAAC;QACvB;YACI,OAAO,MAAM,CAAC;IACtB,CAAC;AACL,CAAC;AAED,MAAa,WAAW;IAEpB;;;;OAIG;IACH,YAA4B,EAAU,EAAS,KAAa,EAAY,MAA8C,EAAS,GAAuB;QAA1H,OAAE,GAAF,EAAE,CAAQ;QAAS,UAAK,GAAL,KAAK,CAAQ;QAAY,WAAM,GAAN,MAAM,CAAwC;QAAS,QAAG,GAA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C1C,OAAO,IAAI,gBAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IACnF,CAAC;CACJ;AAxID,kCAwIC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LanguageModelRegistry } from '@theia/ai-core';
|
|
2
|
+
import { OpenAiLanguageModelsManager, OpenAiModelDescription } from '../common';
|
|
3
|
+
export declare class OpenAiLanguageModelsManagerImpl implements OpenAiLanguageModelsManager {
|
|
4
|
+
protected _apiKey: string | undefined;
|
|
5
|
+
protected readonly languageModelRegistry: LanguageModelRegistry;
|
|
6
|
+
get apiKey(): string | undefined;
|
|
7
|
+
createOrUpdateLanguageModels(...modelDescriptions: OpenAiModelDescription[]): Promise<void>;
|
|
8
|
+
removeLanguageModels(...modelIds: string[]): void;
|
|
9
|
+
setApiKey(apiKey: string | undefined): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=openai-language-models-manager-impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-language-models-manager-impl.d.ts","sourceRoot":"","sources":["../../src/node/openai-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,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAGtC,SAAS,CAAC,QAAQ,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;IAEhE,IAAI,MAAM,IAAI,MAAM,GAAG,SAAS,CAE/B;IAIK,4BAA4B,CAAC,GAAG,iBAAiB,EAAE,sBAAsB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BjG,oBAAoB,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI;IAIjD,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;CAO9C"}
|
|
@@ -0,0 +1,77 @@
|
|
|
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.OpenAiLanguageModelsManagerImpl = void 0;
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
const ai_core_1 = require("@theia/ai-core");
|
|
21
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
22
|
+
const openai_language_model_1 = require("./openai-language-model");
|
|
23
|
+
let OpenAiLanguageModelsManagerImpl = class OpenAiLanguageModelsManagerImpl {
|
|
24
|
+
get apiKey() {
|
|
25
|
+
var _a;
|
|
26
|
+
return (_a = this._apiKey) !== null && _a !== void 0 ? _a : process.env.OPENAI_API_KEY;
|
|
27
|
+
}
|
|
28
|
+
// Triggered from frontend. In case you want to use the models on the backend
|
|
29
|
+
// without a frontend then call this yourself
|
|
30
|
+
async createOrUpdateLanguageModels(...modelDescriptions) {
|
|
31
|
+
for (const modelDescription of modelDescriptions) {
|
|
32
|
+
const model = await this.languageModelRegistry.getLanguageModel(modelDescription.id);
|
|
33
|
+
if (model) {
|
|
34
|
+
if (!(model instanceof openai_language_model_1.OpenAiModel)) {
|
|
35
|
+
console.warn(`Open AI: model ${modelDescription.id} is not an OpenAI model`);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (!modelDescription.url) {
|
|
39
|
+
// This seems to be an official model, but it was already created. This can happen during the initializing of more than one frontend.
|
|
40
|
+
console.info(`Open AI: skip creating model ${modelDescription.id} because it already exists`);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (model.url !== modelDescription.url || model.model !== modelDescription.model) {
|
|
44
|
+
model.url = modelDescription.url;
|
|
45
|
+
model.model = modelDescription.model;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// This can happen during the initializing of more than one frontends.
|
|
49
|
+
console.info(`Open AI: skip creating or updating model ${modelDescription.id} because it already exists and is up to date`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
this.languageModelRegistry.addLanguageModels([new openai_language_model_1.OpenAiModel(modelDescription.id, modelDescription.model, () => this.apiKey, modelDescription.url)]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
removeLanguageModels(...modelIds) {
|
|
58
|
+
this.languageModelRegistry.removeLanguageModels(modelIds);
|
|
59
|
+
}
|
|
60
|
+
setApiKey(apiKey) {
|
|
61
|
+
if (apiKey) {
|
|
62
|
+
this._apiKey = apiKey;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this._apiKey = undefined;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
exports.OpenAiLanguageModelsManagerImpl = OpenAiLanguageModelsManagerImpl;
|
|
70
|
+
tslib_1.__decorate([
|
|
71
|
+
(0, inversify_1.inject)(ai_core_1.LanguageModelRegistry),
|
|
72
|
+
tslib_1.__metadata("design:type", Object)
|
|
73
|
+
], OpenAiLanguageModelsManagerImpl.prototype, "languageModelRegistry", void 0);
|
|
74
|
+
exports.OpenAiLanguageModelsManagerImpl = OpenAiLanguageModelsManagerImpl = tslib_1.__decorate([
|
|
75
|
+
(0, inversify_1.injectable)()
|
|
76
|
+
], OpenAiLanguageModelsManagerImpl);
|
|
77
|
+
//# sourceMappingURL=openai-language-models-manager-impl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-language-models-manager-impl.js","sourceRoot":"","sources":["../../src/node/openai-language-models-manager-impl.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,4CAAuD;AACvD,4DAAkE;AAClE,mEAAsD;AAI/C,IAAM,+BAA+B,GAArC,MAAM,+BAA+B;IAOxC,IAAI,MAAM;;QACN,OAAO,MAAA,IAAI,CAAC,OAAO,mCAAI,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IACtD,CAAC;IAED,6EAA6E;IAC7E,6CAA6C;IAC7C,KAAK,CAAC,4BAA4B,CAAC,GAAG,iBAA2C;QAC7E,KAAK,MAAM,gBAAgB,IAAI,iBAAiB,EAAE,CAAC;YAC/C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;YACrF,IAAI,KAAK,EAAE,CAAC;gBACR,IAAI,CAAC,CAAC,KAAK,YAAY,mCAAW,CAAC,EAAE,CAAC;oBAClC,OAAO,CAAC,IAAI,CAAC,kBAAkB,gBAAgB,CAAC,EAAE,yBAAyB,CAAC,CAAC;oBAC7E,SAAS;gBACb,CAAC;gBACD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AE;GACA,+BAA+B,CAkD3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=package.spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.spec.d.ts","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
/* note: this bogus test file is required so that
|
|
17
|
+
we are able to run mocha unit tests on this
|
|
18
|
+
package, without having any actual unit tests in it.
|
|
19
|
+
This way a coverage report will be generated,
|
|
20
|
+
showing 0% coverage, instead of no report.
|
|
21
|
+
This file can be removed once we have real unit
|
|
22
|
+
tests in place. */
|
|
23
|
+
describe('ai-openai package', () => {
|
|
24
|
+
it('support code coverage statistics', () => true);
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=package.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,oDAAoD;AACpD,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;;;;;;qBAMqB;AAErB,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAE/B,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;AACvD,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@theia/ai-openai",
|
|
3
|
+
"version": "1.54.0",
|
|
4
|
+
"description": "Theia - OpenAI Integration",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@theia/ai-core": "1.54.0",
|
|
7
|
+
"@theia/core": "1.54.0",
|
|
8
|
+
"@theia/filesystem": "1.54.0",
|
|
9
|
+
"@theia/workspace": "1.54.0",
|
|
10
|
+
"minimatch": "^5.1.0",
|
|
11
|
+
"openai": "^4.55.7",
|
|
12
|
+
"tslib": "^2.6.2"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"theiaExtensions": [
|
|
18
|
+
{
|
|
19
|
+
"frontend": "lib/browser/openai-frontend-module",
|
|
20
|
+
"backend": "lib/node/openai-backend-module"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"keywords": [
|
|
24
|
+
"theia-extension"
|
|
25
|
+
],
|
|
26
|
+
"license": "EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/eclipse-theia/theia.git"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/eclipse-theia/theia/issues"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/eclipse-theia/theia",
|
|
35
|
+
"files": [
|
|
36
|
+
"lib",
|
|
37
|
+
"src"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "theiaext build",
|
|
41
|
+
"clean": "theiaext clean",
|
|
42
|
+
"compile": "theiaext compile",
|
|
43
|
+
"lint": "theiaext lint",
|
|
44
|
+
"test": "theiaext test",
|
|
45
|
+
"watch": "theiaext watch"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@theia/ext-scripts": "1.54.0"
|
|
49
|
+
},
|
|
50
|
+
"nyc": {
|
|
51
|
+
"extends": "../../configs/nyc.json"
|
|
52
|
+
},
|
|
53
|
+
"gitHead": "8fb36a237db744cff6e78eaff1481e1f36bb7a69"
|
|
54
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { FrontendApplicationContribution, PreferenceService } from '@theia/core/lib/browser';
|
|
18
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
19
|
+
import { OpenAiLanguageModelsManager, OpenAiModelDescription } from '../common';
|
|
20
|
+
import { API_KEY_PREF, CUSTOM_ENDPOINTS_PREF, MODELS_PREF } from './openai-preferences';
|
|
21
|
+
|
|
22
|
+
@injectable()
|
|
23
|
+
export class OpenAiFrontendApplicationContribution implements FrontendApplicationContribution {
|
|
24
|
+
|
|
25
|
+
@inject(PreferenceService)
|
|
26
|
+
protected preferenceService: PreferenceService;
|
|
27
|
+
|
|
28
|
+
@inject(OpenAiLanguageModelsManager)
|
|
29
|
+
protected manager: OpenAiLanguageModelsManager;
|
|
30
|
+
|
|
31
|
+
// The preferenceChange.oldValue is always undefined for some reason
|
|
32
|
+
protected prevModels: string[] = [];
|
|
33
|
+
protected prevCustomModels: Partial<OpenAiModelDescription>[] = [];
|
|
34
|
+
|
|
35
|
+
onStart(): void {
|
|
36
|
+
this.preferenceService.ready.then(() => {
|
|
37
|
+
const apiKey = this.preferenceService.get<string>(API_KEY_PREF, undefined);
|
|
38
|
+
this.manager.setApiKey(apiKey);
|
|
39
|
+
|
|
40
|
+
const models = this.preferenceService.get<string[]>(MODELS_PREF, []);
|
|
41
|
+
this.manager.createOrUpdateLanguageModels(...models.map(createOpenAIModelDescription));
|
|
42
|
+
this.prevModels = [...models];
|
|
43
|
+
|
|
44
|
+
const customModels = this.preferenceService.get<Partial<OpenAiModelDescription>[]>(CUSTOM_ENDPOINTS_PREF, []);
|
|
45
|
+
this.manager.createOrUpdateLanguageModels(...createCustomModelDescriptionsFromPreferences(customModels));
|
|
46
|
+
this.prevCustomModels = [...customModels];
|
|
47
|
+
|
|
48
|
+
this.preferenceService.onPreferenceChanged(event => {
|
|
49
|
+
if (event.preferenceName === API_KEY_PREF) {
|
|
50
|
+
this.manager.setApiKey(event.newValue);
|
|
51
|
+
} else if (event.preferenceName === MODELS_PREF) {
|
|
52
|
+
const oldModels = new Set(this.prevModels);
|
|
53
|
+
const newModels = new Set(event.newValue as string[]);
|
|
54
|
+
|
|
55
|
+
const modelsToRemove = [...oldModels].filter(model => !newModels.has(model));
|
|
56
|
+
const modelsToAdd = [...newModels].filter(model => !oldModels.has(model));
|
|
57
|
+
|
|
58
|
+
this.manager.removeLanguageModels(...modelsToRemove.map(model => `openai/${model}`));
|
|
59
|
+
this.manager.createOrUpdateLanguageModels(...modelsToAdd.map(createOpenAIModelDescription));
|
|
60
|
+
this.prevModels = [...event.newValue];
|
|
61
|
+
} else if (event.preferenceName === CUSTOM_ENDPOINTS_PREF) {
|
|
62
|
+
const oldModels = createCustomModelDescriptionsFromPreferences(this.prevCustomModels);
|
|
63
|
+
const newModels = createCustomModelDescriptionsFromPreferences(event.newValue);
|
|
64
|
+
|
|
65
|
+
const modelsToRemove = oldModels.filter(model => !newModels.some(newModel => newModel.id === model.id));
|
|
66
|
+
const modelsToAddOrUpdate = newModels.filter(newModel => !oldModels.some(model =>
|
|
67
|
+
model.id === newModel.id && model.model === newModel.model && model.url === newModel.url));
|
|
68
|
+
|
|
69
|
+
this.manager.removeLanguageModels(...modelsToRemove.map(model => model.id));
|
|
70
|
+
this.manager.createOrUpdateLanguageModels(...modelsToAddOrUpdate);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function createOpenAIModelDescription(modelId: string): OpenAiModelDescription {
|
|
78
|
+
return {
|
|
79
|
+
id: `openai/${modelId}`,
|
|
80
|
+
model: modelId
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function createCustomModelDescriptionsFromPreferences(preferences: Partial<OpenAiModelDescription>[]): OpenAiModelDescription[] {
|
|
85
|
+
return preferences.reduce((acc, pref) => {
|
|
86
|
+
if (!pref.model || !pref.url) {
|
|
87
|
+
return acc;
|
|
88
|
+
}
|
|
89
|
+
return [
|
|
90
|
+
...acc,
|
|
91
|
+
{
|
|
92
|
+
id: pref.id ?? pref.model,
|
|
93
|
+
model: pref.model,
|
|
94
|
+
url: pref.url
|
|
95
|
+
}
|
|
96
|
+
];
|
|
97
|
+
}, []);
|
|
98
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
18
|
+
import { OpenAiPreferencesSchema } from './openai-preferences';
|
|
19
|
+
import { FrontendApplicationContribution, PreferenceContribution, RemoteConnectionProvider, ServiceConnectionProvider } from '@theia/core/lib/browser';
|
|
20
|
+
import { OpenAiFrontendApplicationContribution } from './openai-frontend-application-contribution';
|
|
21
|
+
import { OPENAI_LANGUAGE_MODELS_MANAGER_PATH, OpenAiLanguageModelsManager } from '../common';
|
|
22
|
+
|
|
23
|
+
export default new ContainerModule(bind => {
|
|
24
|
+
bind(PreferenceContribution).toConstantValue({ schema: OpenAiPreferencesSchema });
|
|
25
|
+
bind(OpenAiFrontendApplicationContribution).toSelf().inSingletonScope();
|
|
26
|
+
bind(FrontendApplicationContribution).toService(OpenAiFrontendApplicationContribution);
|
|
27
|
+
bind(OpenAiLanguageModelsManager).toDynamicValue(ctx => {
|
|
28
|
+
const provider = ctx.container.get<ServiceConnectionProvider>(RemoteConnectionProvider);
|
|
29
|
+
return provider.createProxy<OpenAiLanguageModelsManager>(OPENAI_LANGUAGE_MODELS_MANAGER_PATH);
|
|
30
|
+
}).inSingletonScope();
|
|
31
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { PreferenceSchema } from '@theia/core/lib/browser/preferences/preference-contribution';
|
|
18
|
+
import { AI_CORE_PREFERENCES_TITLE } from '@theia/ai-core/lib/browser/ai-core-preferences';
|
|
19
|
+
|
|
20
|
+
export const API_KEY_PREF = 'ai-features.openAiOfficial.openAiApiKey';
|
|
21
|
+
export const MODELS_PREF = 'ai-features.openAiOfficial.officialOpenAiModels';
|
|
22
|
+
export const CUSTOM_ENDPOINTS_PREF = 'ai-features.openAiCustom.customOpenAiModels';
|
|
23
|
+
|
|
24
|
+
export const OpenAiPreferencesSchema: PreferenceSchema = {
|
|
25
|
+
type: 'object',
|
|
26
|
+
properties: {
|
|
27
|
+
[API_KEY_PREF]: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
markdownDescription: 'Enter an API Key of your official OpenAI Account. **Please note:** By using this preference the Open AI API key will be stored in clear text\
|
|
30
|
+
on the machine running Theia. Use the environment variable `OPENAI_API_KEY` to set the key securely.',
|
|
31
|
+
title: AI_CORE_PREFERENCES_TITLE,
|
|
32
|
+
},
|
|
33
|
+
[MODELS_PREF]: {
|
|
34
|
+
type: 'array',
|
|
35
|
+
description: 'Official OpenAI models to use',
|
|
36
|
+
title: AI_CORE_PREFERENCES_TITLE,
|
|
37
|
+
default: ['gpt-4o', 'gpt-4o-2024-08-06', 'gpt-4o-2024-05-13', 'gpt-4o-mini', 'gpt-4-turbo', 'gpt-4', 'gpt-3.5-turbo'],
|
|
38
|
+
items: {
|
|
39
|
+
type: 'string'
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
[CUSTOM_ENDPOINTS_PREF]: {
|
|
43
|
+
type: 'array',
|
|
44
|
+
title: AI_CORE_PREFERENCES_TITLE,
|
|
45
|
+
markdownDescription: 'Integrate custom models compatible with the OpenAI API, for example via `vllm`. The required attributes are `model` and `url`.\
|
|
46
|
+
Optionally, you can provide a unique `id` to identify the custom model in the UI. If none is given `model` will be used as `id`.',
|
|
47
|
+
default: [],
|
|
48
|
+
items: {
|
|
49
|
+
type: 'object',
|
|
50
|
+
properties: {
|
|
51
|
+
model: {
|
|
52
|
+
type: 'string',
|
|
53
|
+
title: 'Model ID'
|
|
54
|
+
},
|
|
55
|
+
url: {
|
|
56
|
+
type: 'string',
|
|
57
|
+
title: 'The Open AI API compatible endpoint where the model is hosted'
|
|
58
|
+
},
|
|
59
|
+
id: {
|
|
60
|
+
type: 'string',
|
|
61
|
+
title: 'A unique identifier which is used in the UI to identify the custom model',
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
export * from './openai-language-models-manager';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
export const OPENAI_LANGUAGE_MODELS_MANAGER_PATH = '/services/open-ai/language-model-manager';
|
|
17
|
+
export const OpenAiLanguageModelsManager = Symbol('OpenAiLanguageModelsManager');
|
|
18
|
+
export interface OpenAiModelDescription {
|
|
19
|
+
/**
|
|
20
|
+
* The identifier of the model which will be shown in the UI.
|
|
21
|
+
*/
|
|
22
|
+
id: string;
|
|
23
|
+
/**
|
|
24
|
+
* The model ID as used by the OpenAI API.
|
|
25
|
+
*/
|
|
26
|
+
model: string;
|
|
27
|
+
/**
|
|
28
|
+
* The OpenAI API compatible endpoint where the model is hosted. If not provided the default OpenAI endpoint will be used.
|
|
29
|
+
*/
|
|
30
|
+
url?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface OpenAiLanguageModelsManager {
|
|
33
|
+
apiKey: string | undefined;
|
|
34
|
+
setApiKey(key: string | undefined): void;
|
|
35
|
+
createOrUpdateLanguageModels(...models: OpenAiModelDescription[]): Promise<void>;
|
|
36
|
+
removeLanguageModels(...modelIds: string[]): void
|
|
37
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
18
|
+
import { OPENAI_LANGUAGE_MODELS_MANAGER_PATH, OpenAiLanguageModelsManager } from '../common/openai-language-models-manager';
|
|
19
|
+
import { ConnectionHandler, RpcConnectionHandler } from '@theia/core';
|
|
20
|
+
import { OpenAiLanguageModelsManagerImpl } from './openai-language-models-manager-impl';
|
|
21
|
+
|
|
22
|
+
export const OpenAiModelFactory = Symbol('OpenAiModelFactory');
|
|
23
|
+
|
|
24
|
+
export default new ContainerModule(bind => {
|
|
25
|
+
bind(OpenAiLanguageModelsManagerImpl).toSelf().inSingletonScope();
|
|
26
|
+
bind(OpenAiLanguageModelsManager).toService(OpenAiLanguageModelsManagerImpl);
|
|
27
|
+
bind(ConnectionHandler).toDynamicValue(ctx =>
|
|
28
|
+
new RpcConnectionHandler(OPENAI_LANGUAGE_MODELS_MANAGER_PATH, () => ctx.container.get(OpenAiLanguageModelsManager))
|
|
29
|
+
).inSingletonScope();
|
|
30
|
+
});
|