@theia/ai-llamafile 1.67.0-next.56 → 1.67.0-next.86
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/lib/browser/llamafile-command-contribution.d.ts +21 -0
- package/lib/browser/llamafile-command-contribution.d.ts.map +1 -0
- package/lib/browser/llamafile-command-contribution.js +104 -0
- package/lib/browser/llamafile-command-contribution.js.map +1 -0
- package/lib/browser/llamafile-frontend-application-contribution.d.ts +17 -0
- package/lib/browser/llamafile-frontend-application-contribution.d.ts.map +1 -0
- package/lib/browser/llamafile-frontend-application-contribution.js +91 -0
- package/lib/browser/llamafile-frontend-application-contribution.js.map +1 -0
- package/lib/browser/llamafile-frontend-module.d.ts +4 -0
- package/lib/browser/llamafile-frontend-module.d.ts.map +1 -0
- package/lib/browser/llamafile-frontend-module.js +46 -0
- package/lib/browser/llamafile-frontend-module.js.map +1 -0
- package/lib/common/llamafile-language-model.d.ts +20 -0
- package/lib/common/llamafile-language-model.d.ts.map +1 -0
- package/lib/common/llamafile-language-model.js +130 -0
- package/lib/common/llamafile-language-model.js.map +1 -0
- package/lib/common/llamafile-manager.d.ts +20 -0
- package/lib/common/llamafile-manager.d.ts.map +1 -0
- package/lib/common/llamafile-manager.js +21 -0
- package/lib/common/llamafile-manager.js.map +1 -0
- package/lib/common/llamafile-preferences.d.ts +7 -0
- package/lib/common/llamafile-preferences.d.ts.map +1 -0
- package/lib/common/llamafile-preferences.js +61 -0
- package/lib/common/llamafile-preferences.js.map +1 -0
- package/lib/node/llamafile-backend-module.d.ts +4 -0
- package/lib/node/llamafile-backend-module.d.ts.map +1 -0
- package/lib/node/llamafile-backend-module.js +37 -0
- package/lib/node/llamafile-backend-module.js.map +1 -0
- package/lib/node/llamafile-manager-impl.d.ts +23 -0
- package/lib/node/llamafile-manager-impl.d.ts.map +1 -0
- package/lib/node/llamafile-manager-impl.js +139 -0
- package/lib/node/llamafile-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 +5 -5
- package/src/node/llamafile-manager-impl.ts +64 -50
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AICommandHandlerFactory } from '@theia/ai-core/lib/browser/ai-command-handler-factory';
|
|
2
|
+
import { CommandContribution, CommandRegistry, MessageService, PreferenceService } from '@theia/core';
|
|
3
|
+
import { QuickInputService } from '@theia/core/lib/browser';
|
|
4
|
+
import { LlamafileManager } from '../common/llamafile-manager';
|
|
5
|
+
export declare const StartLlamafileCommand: {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const StopLlamafileCommand: {
|
|
10
|
+
id: string;
|
|
11
|
+
label: string;
|
|
12
|
+
};
|
|
13
|
+
export declare class LlamafileCommandContribution implements CommandContribution {
|
|
14
|
+
protected readonly quickInputService: QuickInputService;
|
|
15
|
+
protected readonly commandHandlerFactory: AICommandHandlerFactory;
|
|
16
|
+
protected preferenceService: PreferenceService;
|
|
17
|
+
protected messageService: MessageService;
|
|
18
|
+
protected llamafileManager: LlamafileManager;
|
|
19
|
+
registerCommands(commandRegistry: CommandRegistry): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=llamafile-command-contribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-command-contribution.d.ts","sourceRoot":"","sources":["../../src/browser/llamafile-command-contribution.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uDAAuD,CAAC;AAChG,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,cAAc,EAAO,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC3G,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAI/D,eAAO,MAAM,qBAAqB;;;CAGjC,CAAC;AACF,eAAO,MAAM,oBAAoB;;;CAGhC,CAAC;AAEF,qBACa,4BAA6B,YAAW,mBAAmB;IAGpE,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAGxD,SAAS,CAAC,QAAQ,CAAC,qBAAqB,EAAE,uBAAuB,CAAC;IAGlE,SAAS,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAG/C,SAAS,CAAC,cAAc,EAAE,cAAc,CAAC;IAGzC,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAE7C,gBAAgB,CAAC,eAAe,EAAE,eAAe,GAAG,IAAI;CAoD3D"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LlamafileCommandContribution = exports.StopLlamafileCommand = exports.StartLlamafileCommand = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// *****************************************************************************
|
|
6
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
7
|
+
//
|
|
8
|
+
// This program and the accompanying materials are made available under the
|
|
9
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
10
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
11
|
+
//
|
|
12
|
+
// This Source Code may also be made available under the following Secondary
|
|
13
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
14
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
15
|
+
// with the GNU Classpath Exception which is available at
|
|
16
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
17
|
+
//
|
|
18
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
19
|
+
// *****************************************************************************
|
|
20
|
+
const ai_command_handler_factory_1 = require("@theia/ai-core/lib/browser/ai-command-handler-factory");
|
|
21
|
+
const core_1 = require("@theia/core");
|
|
22
|
+
const browser_1 = require("@theia/core/lib/browser");
|
|
23
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
24
|
+
const llamafile_manager_1 = require("../common/llamafile-manager");
|
|
25
|
+
const llamafile_preferences_1 = require("../common/llamafile-preferences");
|
|
26
|
+
exports.StartLlamafileCommand = {
|
|
27
|
+
id: 'llamafile.start',
|
|
28
|
+
label: core_1.nls.localize('theia/ai/llamaFile/start', 'Start Llamafile'),
|
|
29
|
+
};
|
|
30
|
+
exports.StopLlamafileCommand = {
|
|
31
|
+
id: 'llamafile.stop',
|
|
32
|
+
label: core_1.nls.localize('theia/ai/llamaFile/stop', 'Stop Llamafile'),
|
|
33
|
+
};
|
|
34
|
+
let LlamafileCommandContribution = class LlamafileCommandContribution {
|
|
35
|
+
registerCommands(commandRegistry) {
|
|
36
|
+
commandRegistry.registerCommand(exports.StartLlamafileCommand, this.commandHandlerFactory({
|
|
37
|
+
execute: async () => {
|
|
38
|
+
try {
|
|
39
|
+
const llamaFiles = this.preferenceService.get(llamafile_preferences_1.PREFERENCE_LLAMAFILE);
|
|
40
|
+
if (llamaFiles === undefined || llamaFiles.length === 0) {
|
|
41
|
+
this.messageService.error(core_1.nls.localize('theia/ai/llamafile/error/noConfigured', 'No Llamafiles configured.'));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const options = llamaFiles.map(llamaFile => ({ label: llamaFile.name }));
|
|
45
|
+
const result = await this.quickInputService.showQuickPick(options);
|
|
46
|
+
if (result === undefined) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this.llamafileManager.startServer(result.label);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
console.error('Something went wrong during the llamafile start.', error);
|
|
53
|
+
this.messageService.error(core_1.nls.localize('theia/ai/llamafile/error/startFailed', 'Something went wrong during the llamafile start: {0}.\nFor more information, see the console.', error.message));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}));
|
|
57
|
+
commandRegistry.registerCommand(exports.StopLlamafileCommand, this.commandHandlerFactory({
|
|
58
|
+
execute: async () => {
|
|
59
|
+
try {
|
|
60
|
+
const llamaFiles = await this.llamafileManager.getStartedLlamafiles();
|
|
61
|
+
if (llamaFiles === undefined || llamaFiles.length === 0) {
|
|
62
|
+
this.messageService.error(core_1.nls.localize('theia/ai/llamafile/error/noRunning', 'No Llamafiles running.'));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const options = llamaFiles.map(llamaFile => ({ label: llamaFile }));
|
|
66
|
+
const result = await this.quickInputService.showQuickPick(options);
|
|
67
|
+
if (result === undefined) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this.llamafileManager.stopServer(result.label);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.error('Something went wrong during the llamafile stop.', error);
|
|
74
|
+
this.messageService.error(core_1.nls.localize('theia/ai/llamafile/error/stopFailed', 'Something went wrong during the llamafile stop: {0}.\nFor more information, see the console.', error.message));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
exports.LlamafileCommandContribution = LlamafileCommandContribution;
|
|
81
|
+
tslib_1.__decorate([
|
|
82
|
+
(0, inversify_1.inject)(browser_1.QuickInputService),
|
|
83
|
+
tslib_1.__metadata("design:type", Object)
|
|
84
|
+
], LlamafileCommandContribution.prototype, "quickInputService", void 0);
|
|
85
|
+
tslib_1.__decorate([
|
|
86
|
+
(0, inversify_1.inject)(ai_command_handler_factory_1.AICommandHandlerFactory),
|
|
87
|
+
tslib_1.__metadata("design:type", Function)
|
|
88
|
+
], LlamafileCommandContribution.prototype, "commandHandlerFactory", void 0);
|
|
89
|
+
tslib_1.__decorate([
|
|
90
|
+
(0, inversify_1.inject)(core_1.PreferenceService),
|
|
91
|
+
tslib_1.__metadata("design:type", Object)
|
|
92
|
+
], LlamafileCommandContribution.prototype, "preferenceService", void 0);
|
|
93
|
+
tslib_1.__decorate([
|
|
94
|
+
(0, inversify_1.inject)(core_1.MessageService),
|
|
95
|
+
tslib_1.__metadata("design:type", core_1.MessageService)
|
|
96
|
+
], LlamafileCommandContribution.prototype, "messageService", void 0);
|
|
97
|
+
tslib_1.__decorate([
|
|
98
|
+
(0, inversify_1.inject)(llamafile_manager_1.LlamafileManager),
|
|
99
|
+
tslib_1.__metadata("design:type", Object)
|
|
100
|
+
], LlamafileCommandContribution.prototype, "llamafileManager", void 0);
|
|
101
|
+
exports.LlamafileCommandContribution = LlamafileCommandContribution = tslib_1.__decorate([
|
|
102
|
+
(0, inversify_1.injectable)()
|
|
103
|
+
], LlamafileCommandContribution);
|
|
104
|
+
//# sourceMappingURL=llamafile-command-contribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-command-contribution.js","sourceRoot":"","sources":["../../src/browser/llamafile-command-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;AAChF,sGAAgG;AAChG,sCAA2G;AAC3G,qDAA4D;AAC5D,4DAAkE;AAClE,mEAA+D;AAC/D,2EAAuE;AAG1D,QAAA,qBAAqB,GAAG;IACjC,EAAE,EAAE,iBAAiB;IACrB,KAAK,EAAE,UAAG,CAAC,QAAQ,CAAC,0BAA0B,EAAE,iBAAiB,CAAC;CACrE,CAAC;AACW,QAAA,oBAAoB,GAAG;IAChC,EAAE,EAAE,gBAAgB;IACpB,KAAK,EAAE,UAAG,CAAC,QAAQ,CAAC,yBAAyB,EAAE,gBAAgB,CAAC;CACnE,CAAC;AAGK,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IAiBrC,gBAAgB,CAAC,eAAgC;QAC7C,eAA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fpC,4BAA4B;IADxC,IAAA,sBAAU,GAAE;GACA,4BAA4B,CAqExC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
|
|
2
|
+
import { LlamafileManager, LlamafileModelDescription } from '../common/llamafile-manager';
|
|
3
|
+
import { PreferenceService } from '@theia/core';
|
|
4
|
+
export declare class LlamafileFrontendApplicationContribution implements FrontendApplicationContribution {
|
|
5
|
+
protected preferenceService: PreferenceService;
|
|
6
|
+
protected llamafileManager: LlamafileManager;
|
|
7
|
+
private _knownLlamaFiles;
|
|
8
|
+
onStart(): void;
|
|
9
|
+
protected getLLamaFileModelDescriptions(llamafiles: LlamafileEntry[]): LlamafileModelDescription[];
|
|
10
|
+
protected handleLlamaFilePreferenceChange(newModels: LlamafileEntry[]): void;
|
|
11
|
+
}
|
|
12
|
+
export interface LlamafileEntry {
|
|
13
|
+
name: string;
|
|
14
|
+
uri: string;
|
|
15
|
+
port: number;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=llamafile-frontend-application-contribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-frontend-application-contribution.d.ts","sourceRoot":"","sources":["../../src/browser/llamafile-frontend-application-contribution.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC;AAE1E,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAE1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,qBACa,wCAAyC,YAAW,+BAA+B;IAG5F,SAAS,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAG/C,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAE7C,OAAO,CAAC,gBAAgB,CAA0C;IAElE,OAAO,IAAI,IAAI;IAmBf,SAAS,CAAC,6BAA6B,CAAC,UAAU,EAAE,cAAc,EAAE,GAAG,yBAAyB,EAAE;IAQlG,SAAS,CAAC,+BAA+B,CAAC,SAAS,EAAE,cAAc,EAAE,GAAG,IAAI;CAe/E;AAED,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -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.LlamafileFrontendApplicationContribution = void 0;
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
21
|
+
const llamafile_manager_1 = require("../common/llamafile-manager");
|
|
22
|
+
const llamafile_preferences_1 = require("../common/llamafile-preferences");
|
|
23
|
+
const core_1 = require("@theia/core");
|
|
24
|
+
let LlamafileFrontendApplicationContribution = class LlamafileFrontendApplicationContribution {
|
|
25
|
+
constructor() {
|
|
26
|
+
this._knownLlamaFiles = new Map();
|
|
27
|
+
}
|
|
28
|
+
onStart() {
|
|
29
|
+
this.preferenceService.ready.then(() => {
|
|
30
|
+
const llamafiles = this.preferenceService.get(llamafile_preferences_1.PREFERENCE_LLAMAFILE, []);
|
|
31
|
+
const validLlamafiles = llamafiles.filter(LlamafileEntry.is);
|
|
32
|
+
const LlamafileModelDescriptions = this.getLLamaFileModelDescriptions(validLlamafiles);
|
|
33
|
+
this.llamafileManager.addLanguageModels(LlamafileModelDescriptions);
|
|
34
|
+
validLlamafiles.forEach(model => this._knownLlamaFiles.set(model.name, model));
|
|
35
|
+
this.preferenceService.onPreferenceChanged(event => {
|
|
36
|
+
if (event.preferenceName === llamafile_preferences_1.PREFERENCE_LLAMAFILE) {
|
|
37
|
+
const newModels = event.newValue.filter((llamafileEntry) => LlamafileEntry.is(llamafileEntry));
|
|
38
|
+
this.handleLlamaFilePreferenceChange(newModels);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
getLLamaFileModelDescriptions(llamafiles) {
|
|
44
|
+
return llamafiles.map(llamafile => ({
|
|
45
|
+
name: llamafile.name,
|
|
46
|
+
uri: llamafile.uri,
|
|
47
|
+
port: llamafile.port
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
handleLlamaFilePreferenceChange(newModels) {
|
|
51
|
+
const llamafilesToAdd = newModels.filter(llamafile => !this._knownLlamaFiles.has(llamafile.name) ||
|
|
52
|
+
!LlamafileEntry.equals(this._knownLlamaFiles.get(llamafile.name), llamafile));
|
|
53
|
+
const llamafileIdsToRemove = [...this._knownLlamaFiles.values()].filter(llamafile => !newModels.find(newModel => LlamafileEntry.equals(newModel, llamafile)))
|
|
54
|
+
.map(llamafile => llamafile.name);
|
|
55
|
+
this.llamafileManager.removeLanguageModels(llamafileIdsToRemove);
|
|
56
|
+
llamafileIdsToRemove.forEach(id => this._knownLlamaFiles.delete(id));
|
|
57
|
+
this.llamafileManager.addLanguageModels(this.getLLamaFileModelDescriptions(llamafilesToAdd));
|
|
58
|
+
llamafilesToAdd.forEach(model => this._knownLlamaFiles.set(model.name, model));
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
exports.LlamafileFrontendApplicationContribution = LlamafileFrontendApplicationContribution;
|
|
62
|
+
tslib_1.__decorate([
|
|
63
|
+
(0, inversify_1.inject)(core_1.PreferenceService),
|
|
64
|
+
tslib_1.__metadata("design:type", Object)
|
|
65
|
+
], LlamafileFrontendApplicationContribution.prototype, "preferenceService", void 0);
|
|
66
|
+
tslib_1.__decorate([
|
|
67
|
+
(0, inversify_1.inject)(llamafile_manager_1.LlamafileManager),
|
|
68
|
+
tslib_1.__metadata("design:type", Object)
|
|
69
|
+
], LlamafileFrontendApplicationContribution.prototype, "llamafileManager", void 0);
|
|
70
|
+
exports.LlamafileFrontendApplicationContribution = LlamafileFrontendApplicationContribution = tslib_1.__decorate([
|
|
71
|
+
(0, inversify_1.injectable)()
|
|
72
|
+
], LlamafileFrontendApplicationContribution);
|
|
73
|
+
var LlamafileEntry;
|
|
74
|
+
(function (LlamafileEntry) {
|
|
75
|
+
function equals(a, b) {
|
|
76
|
+
return (a.name === b.name &&
|
|
77
|
+
a.uri === b.uri &&
|
|
78
|
+
a.port === b.port);
|
|
79
|
+
}
|
|
80
|
+
LlamafileEntry.equals = equals;
|
|
81
|
+
function is(entry) {
|
|
82
|
+
return (typeof entry === 'object' &&
|
|
83
|
+
// eslint-disable-next-line no-null/no-null
|
|
84
|
+
entry !== null &&
|
|
85
|
+
'name' in entry && typeof entry.name === 'string' &&
|
|
86
|
+
'uri' in entry && typeof entry.uri === 'string' &&
|
|
87
|
+
'port' in entry && typeof entry.port === 'number');
|
|
88
|
+
}
|
|
89
|
+
LlamafileEntry.is = is;
|
|
90
|
+
})(LlamafileEntry || (LlamafileEntry = {}));
|
|
91
|
+
//# sourceMappingURL=llamafile-frontend-application-contribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-frontend-application-contribution.js","sourceRoot":"","sources":["../../src/browser/llamafile-frontend-application-contribution.ts"],"names":[],"mapp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AoBG"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// *****************************************************************************
|
|
4
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
5
|
+
//
|
|
6
|
+
// This program and the accompanying materials are made available under the
|
|
7
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
8
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
9
|
+
//
|
|
10
|
+
// This Source Code may also be made available under the following Secondary
|
|
11
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
12
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
13
|
+
// with the GNU Classpath Exception which is available at
|
|
14
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
15
|
+
//
|
|
16
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
17
|
+
// *****************************************************************************
|
|
18
|
+
const core_1 = require("@theia/core");
|
|
19
|
+
const browser_1 = require("@theia/core/lib/browser");
|
|
20
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
21
|
+
const output_channel_1 = require("@theia/output/lib/browser/output-channel");
|
|
22
|
+
const llamafile_manager_1 = require("../common/llamafile-manager");
|
|
23
|
+
const llamafile_command_contribution_1 = require("./llamafile-command-contribution");
|
|
24
|
+
const llamafile_frontend_application_contribution_1 = require("./llamafile-frontend-application-contribution");
|
|
25
|
+
const llamafile_preferences_1 = require("../common/llamafile-preferences");
|
|
26
|
+
exports.default = new inversify_1.ContainerModule(bind => {
|
|
27
|
+
bind(browser_1.FrontendApplicationContribution).to(llamafile_frontend_application_contribution_1.LlamafileFrontendApplicationContribution).inSingletonScope();
|
|
28
|
+
bind(core_1.CommandContribution).to(llamafile_command_contribution_1.LlamafileCommandContribution).inSingletonScope();
|
|
29
|
+
bind(llamafile_manager_1.LlamafileManager).toDynamicValue(ctx => {
|
|
30
|
+
const connection = ctx.container.get(browser_1.RemoteConnectionProvider);
|
|
31
|
+
const outputChannelManager = ctx.container.get(output_channel_1.OutputChannelManager);
|
|
32
|
+
const client = {
|
|
33
|
+
error: (llamafileName, message) => {
|
|
34
|
+
const channel = outputChannelManager.getChannel(`${llamafileName}-llamafile`);
|
|
35
|
+
channel.appendLine(message, output_channel_1.OutputChannelSeverity.Error);
|
|
36
|
+
},
|
|
37
|
+
log: (llamafileName, message) => {
|
|
38
|
+
const channel = outputChannelManager.getChannel(`${llamafileName}-llamafile`);
|
|
39
|
+
channel.appendLine(message, output_channel_1.OutputChannelSeverity.Info);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
return connection.createProxy(llamafile_manager_1.LlamafileManagerPath, client);
|
|
43
|
+
}).inSingletonScope();
|
|
44
|
+
(0, llamafile_preferences_1.bindAILlamafilePreferences)(bind);
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=llamafile-frontend-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-frontend-module.js","sourceRoot":"","sources":["../../src/browser/llamafile-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;AAChF,sCAAkD;AAClD,qDAA+H;AAC/H,4DAA+D;AAC/D,6EAAuG;AACvG,mEAAmH;AACnH,qFAAgF;AAChF,+GAAyG;AACzG,2EAA6E;AAE7E,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,yCAA+B,CAAC,CAAC,EAAE,CAAC,sFAAwC,CAAC,CAAC,gBAAgB,EAAE,CAAC;IACtG,IAAI,CAAC,0BAAmB,CAAC,CAAC,EAAE,CAAC,6DAA4B,CAAC,CAAC,gBAAgB,EAAE,CAAC;IAC9E,IAAI,CAAC,oCAAgB,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;QACxC,MAAM,UAAU,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAA4B,kCAAwB,CAAC,CAAC;QAC1F,MAAM,oBAAoB,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,qCAAoB,CAAC,CAAC;QACrE,MAAM,MAAM,GAAiC;YACzC,KAAK,EAAE,CAAC,aAAa,EAAE,OAAO,EAAE,EAAE;gBAC9B,MAAM,OAAO,GAAG,oBAAoB,CAAC,UAAU,CAAC,GAAG,aAAa,YAAY,CAAC,CAAC;gBAC9E,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,sCAAqB,CAAC,KAAK,CAAC,CAAC;YAC7D,CAAC;YACD,GAAG,EAAE,CAAC,aAAa,EAAE,OAAO,EAAE,EAAE;gBAC5B,MAAM,OAAO,GAAG,oBAAoB,CAAC,UAAU,CAAC,GAAG,aAAa,YAAY,CAAC,CAAC;gBAC9E,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,sCAAqB,CAAC,IAAI,CAAC,CAAC;YAC5D,CAAC;SACJ,CAAC;QACF,OAAO,UAAU,CAAC,WAAW,CAAmB,wCAAoB,EAAE,MAAM,CAAC,CAAC;IAClF,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC;IAEtB,IAAA,kDAA0B,EAAC,IAAI,CAAC,CAAC;AACrC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LanguageModel, LanguageModelRequest, LanguageModelResponse, LanguageModelStatus } from '@theia/ai-core';
|
|
2
|
+
import { CancellationToken } from '@theia/core';
|
|
3
|
+
export declare class LlamafileLanguageModel implements LanguageModel {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
status: LanguageModelStatus;
|
|
6
|
+
readonly uri: string;
|
|
7
|
+
readonly port: number;
|
|
8
|
+
readonly providerId = "llamafile";
|
|
9
|
+
readonly vendor: string;
|
|
10
|
+
/**
|
|
11
|
+
* @param name the unique name for this language model. It will be used to identify the model in the UI.
|
|
12
|
+
* @param uri the URI pointing to the Llamafile model location.
|
|
13
|
+
* @param port the port on which the Llamafile model server operates.
|
|
14
|
+
*/
|
|
15
|
+
constructor(name: string, status: LanguageModelStatus, uri: string, port: number);
|
|
16
|
+
get id(): string;
|
|
17
|
+
protected getSettings(request: LanguageModelRequest): Record<string, unknown>;
|
|
18
|
+
request(request: LanguageModelRequest, cancellationToken?: CancellationToken): Promise<LanguageModelResponse>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=llamafile-language-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-language-model.d.ts","sourceRoot":"","sources":["../../src/common/llamafile-language-model.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,aAAa,EAAwB,oBAAoB,EAAE,qBAAqB,EAAE,mBAAmB,EAAmC,MAAM,gBAAgB,CAAC;AACxK,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAShD,qBAAa,sBAAuB,YAAW,aAAa;aAWpC,IAAI,EAAE,MAAM;IACrB,MAAM,EAAE,mBAAmB;aAClB,GAAG,EAAE,MAAM;aACX,IAAI,EAAE,MAAM;IAZhC,QAAQ,CAAC,UAAU,eAAe;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAa;IAEpC;;;;OAIG;gBAEiB,IAAI,EAAE,MAAM,EACrB,MAAM,EAAE,mBAAmB,EAClB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM;IAGhC,IAAI,EAAE,IAAI,MAAM,CAEf;IACD,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAUvE,OAAO,CAAC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,qBAAqB,CAAC;CA6EtH"}
|
|
@@ -0,0 +1,130 @@
|
|
|
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.LlamafileLanguageModel = void 0;
|
|
19
|
+
const ai_core_1 = require("@theia/ai-core");
|
|
20
|
+
const createMessageContent = (message) => {
|
|
21
|
+
if (ai_core_1.LanguageModelMessage.isTextMessage(message)) {
|
|
22
|
+
return message.text;
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
};
|
|
26
|
+
class LlamafileLanguageModel {
|
|
27
|
+
/**
|
|
28
|
+
* @param name the unique name for this language model. It will be used to identify the model in the UI.
|
|
29
|
+
* @param uri the URI pointing to the Llamafile model location.
|
|
30
|
+
* @param port the port on which the Llamafile model server operates.
|
|
31
|
+
*/
|
|
32
|
+
constructor(name, status, uri, port) {
|
|
33
|
+
this.name = name;
|
|
34
|
+
this.status = status;
|
|
35
|
+
this.uri = uri;
|
|
36
|
+
this.port = port;
|
|
37
|
+
this.providerId = 'llamafile';
|
|
38
|
+
this.vendor = 'Mozilla';
|
|
39
|
+
}
|
|
40
|
+
get id() {
|
|
41
|
+
return this.name;
|
|
42
|
+
}
|
|
43
|
+
getSettings(request) {
|
|
44
|
+
var _a;
|
|
45
|
+
return {
|
|
46
|
+
n_predict: 200,
|
|
47
|
+
stream: true,
|
|
48
|
+
stop: ['</s>', 'Llama:', 'User:', '<|eot_id|>'],
|
|
49
|
+
cache_prompt: true,
|
|
50
|
+
...((_a = request.settings) !== null && _a !== void 0 ? _a : {})
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async request(request, cancellationToken) {
|
|
54
|
+
const settings = this.getSettings(request);
|
|
55
|
+
try {
|
|
56
|
+
let prompt = request.messages.map(message => {
|
|
57
|
+
const content = createMessageContent(message);
|
|
58
|
+
if (content === undefined) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
switch (message.actor) {
|
|
62
|
+
case 'user':
|
|
63
|
+
return `User: ${content}`;
|
|
64
|
+
case 'ai':
|
|
65
|
+
return `Llama: ${content}`;
|
|
66
|
+
case 'system':
|
|
67
|
+
return `${content.replace(/\n\n/g, '\n')}`;
|
|
68
|
+
}
|
|
69
|
+
}).filter(m => m !== undefined).join('\n');
|
|
70
|
+
prompt += '\nLlama:';
|
|
71
|
+
const response = await fetch(`http://localhost:${this.port}/completion`, {
|
|
72
|
+
method: 'POST',
|
|
73
|
+
headers: {
|
|
74
|
+
'Content-Type': 'application/json',
|
|
75
|
+
},
|
|
76
|
+
body: JSON.stringify({
|
|
77
|
+
prompt: prompt,
|
|
78
|
+
...settings
|
|
79
|
+
}),
|
|
80
|
+
});
|
|
81
|
+
if (!response.ok) {
|
|
82
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
83
|
+
}
|
|
84
|
+
if (!response.body) {
|
|
85
|
+
throw new Error('Response body is undefined');
|
|
86
|
+
}
|
|
87
|
+
const reader = response.body.getReader();
|
|
88
|
+
const decoder = new TextDecoder();
|
|
89
|
+
return {
|
|
90
|
+
stream: {
|
|
91
|
+
[Symbol.asyncIterator]() {
|
|
92
|
+
return {
|
|
93
|
+
async next() {
|
|
94
|
+
if (cancellationToken === null || cancellationToken === void 0 ? void 0 : cancellationToken.isCancellationRequested) {
|
|
95
|
+
reader.cancel();
|
|
96
|
+
return { value: undefined, done: true };
|
|
97
|
+
}
|
|
98
|
+
const { value, done } = await reader.read();
|
|
99
|
+
if (done) {
|
|
100
|
+
return { value: undefined, done: true };
|
|
101
|
+
}
|
|
102
|
+
const read = decoder.decode(value, { stream: true });
|
|
103
|
+
const chunk = read.split('\n').filter(l => l.length !== 0).reduce((acc, line) => {
|
|
104
|
+
try {
|
|
105
|
+
const parsed = JSON.parse(line.substring(6));
|
|
106
|
+
acc += parsed.content;
|
|
107
|
+
return acc;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
console.error('Error parsing JSON:', error);
|
|
111
|
+
return acc;
|
|
112
|
+
}
|
|
113
|
+
}, '');
|
|
114
|
+
return { value: { content: chunk }, done: false };
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
console.error('Error:', error);
|
|
123
|
+
return {
|
|
124
|
+
text: `Error: ${error}`
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.LlamafileLanguageModel = LlamafileLanguageModel;
|
|
130
|
+
//# sourceMappingURL=llamafile-language-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-language-model.js","sourceRoot":"","sources":["../../src/common/llamafile-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,g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AAC,CAAC;YAC/B,OAAO;gBACH,IAAI,EAAE,UAAU,KAAK,EAAE;aAC1B,CAAC;QACN,CAAC;IACL,CAAC;CAEJ;AA3GD,wDA2GC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const LlamafileManager: unique symbol;
|
|
2
|
+
export declare const LlamafileManagerPath = "/services/llamafilemanager";
|
|
3
|
+
export interface LlamafileModelDescription {
|
|
4
|
+
name: string;
|
|
5
|
+
uri: string;
|
|
6
|
+
port: number;
|
|
7
|
+
}
|
|
8
|
+
export interface LlamafileManager {
|
|
9
|
+
startServer(name: string): Promise<void>;
|
|
10
|
+
stopServer(name: string): void;
|
|
11
|
+
getStartedLlamafiles(): Promise<string[]>;
|
|
12
|
+
setClient(client: LlamafileServerManagerClient): void;
|
|
13
|
+
addLanguageModels(llamaFiles: LlamafileModelDescription[]): Promise<void>;
|
|
14
|
+
removeLanguageModels(modelIds: string[]): void;
|
|
15
|
+
}
|
|
16
|
+
export interface LlamafileServerManagerClient {
|
|
17
|
+
log(llamafileName: string, message: string): void;
|
|
18
|
+
error(llamafileName: string, message: string): void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=llamafile-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-manager.d.ts","sourceRoot":"","sources":["../../src/common/llamafile-manager.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,gBAAgB,eAA6B,CAAC;AAE3D,eAAO,MAAM,oBAAoB,+BAA+B,CAAC;AAEjE,MAAM,WAAW,yBAAyB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC7B,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,oBAAoB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1C,SAAS,CAAC,MAAM,EAAE,4BAA4B,GAAG,IAAI,CAAC;IACtD,iBAAiB,CAAC,UAAU,EAAE,yBAAyB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1E,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CAClD;AACD,MAAM,WAAW,4BAA4B;IACzC,GAAG,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAClD,KAAK,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACvD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LlamafileManagerPath = exports.LlamafileManager = void 0;
|
|
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
|
+
exports.LlamafileManager = Symbol('LlamafileManager');
|
|
20
|
+
exports.LlamafileManagerPath = '/services/llamafilemanager';
|
|
21
|
+
//# sourceMappingURL=llamafile-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-manager.js","sourceRoot":"","sources":["../../src/common/llamafile-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;AACnE,QAAA,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAE9C,QAAA,oBAAoB,GAAG,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PreferenceSchema } from '@theia/core';
|
|
2
|
+
import { interfaces } from '@theia/core/shared/inversify';
|
|
3
|
+
export declare const AI_LLAMAFILE_PREFERENCES_TITLE: string;
|
|
4
|
+
export declare const PREFERENCE_LLAMAFILE = "ai-features.llamafile.llamafiles";
|
|
5
|
+
export declare const aiLlamafilePreferencesSchema: PreferenceSchema;
|
|
6
|
+
export declare function bindAILlamafilePreferences(bind: interfaces.Bind): void;
|
|
7
|
+
//# sourceMappingURL=llamafile-preferences.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-preferences.d.ts","sourceRoot":"","sources":["../../src/common/llamafile-preferences.ts"],"names":[],"mappings":"AAgBA,OAAO,EAA+B,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE1D,eAAO,MAAM,8BAA8B,QAAmE,CAAC;AAC/G,eAAO,MAAM,oBAAoB,qCAAqC,CAAC;AAEvE,eAAO,MAAM,4BAA4B,EAAE,gBAkC1C,CAAC;AAEF,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,GAAG,IAAI,CAEtE"}
|
|
@@ -0,0 +1,61 @@
|
|
|
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.bindAILlamafilePreferences = exports.aiLlamafilePreferencesSchema = exports.PREFERENCE_LLAMAFILE = exports.AI_LLAMAFILE_PREFERENCES_TITLE = void 0;
|
|
19
|
+
const core_1 = require("@theia/core");
|
|
20
|
+
exports.AI_LLAMAFILE_PREFERENCES_TITLE = core_1.nls.localize('theia/ai/llamaFile/prefs/title', '✨ AI LlamaFile');
|
|
21
|
+
exports.PREFERENCE_LLAMAFILE = 'ai-features.llamafile.llamafiles';
|
|
22
|
+
exports.aiLlamafilePreferencesSchema = {
|
|
23
|
+
properties: {
|
|
24
|
+
[exports.PREFERENCE_LLAMAFILE]: {
|
|
25
|
+
title: exports.AI_LLAMAFILE_PREFERENCES_TITLE,
|
|
26
|
+
markdownDescription: core_1.nls.localize('theia/ai/llamaFile/prefs/mdDescription', 'This setting allows you to configure and manage LlamaFile models in Theia IDE.\
|
|
27
|
+
\n\
|
|
28
|
+
Each entry requires a user-friendly `name`, the file `uri` pointing to your LlamaFile, and the `port` on which it will run.\
|
|
29
|
+
\n\
|
|
30
|
+
To start a LlamaFile, use the "Start LlamaFile" command, which enables you to select the desired model.\
|
|
31
|
+
\n\
|
|
32
|
+
If you edit an entry (e.g., change the port), any running instance will stop, and you will need to manually start it again.\
|
|
33
|
+
\n\
|
|
34
|
+
[Learn more about configuring and managing LlamaFiles in the Theia IDE documentation](https://theia-ide.org/docs/user_ai/#llamafile-models).'),
|
|
35
|
+
type: 'array',
|
|
36
|
+
default: [],
|
|
37
|
+
items: {
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: {
|
|
40
|
+
name: {
|
|
41
|
+
type: 'string',
|
|
42
|
+
description: core_1.nls.localize('theia/ai/llamaFile/prefs/name/description', 'The model name to use for this Llamafile.')
|
|
43
|
+
},
|
|
44
|
+
uri: {
|
|
45
|
+
type: 'string',
|
|
46
|
+
description: core_1.nls.localize('theia/ai/llamaFile/prefs/uri/description', 'The file uri to the Llamafile.')
|
|
47
|
+
},
|
|
48
|
+
port: {
|
|
49
|
+
type: 'number',
|
|
50
|
+
description: core_1.nls.localize('theia/ai/llamaFile/prefs/port/description', 'The port to use to start the server.')
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
function bindAILlamafilePreferences(bind) {
|
|
58
|
+
bind(core_1.PreferenceContribution).toConstantValue({ schema: exports.aiLlamafilePreferencesSchema });
|
|
59
|
+
}
|
|
60
|
+
exports.bindAILlamafilePreferences = bindAILlamafilePreferences;
|
|
61
|
+
//# sourceMappingURL=llamafile-preferences.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-preferences.js","sourceRoot":"","sources":["../../src/common/llamafile-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,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AoB/D,wBAGG"}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 llamafile_manager_impl_1 = require("./llamafile-manager-impl");
|
|
20
|
+
const llamafile_manager_1 = require("../common/llamafile-manager");
|
|
21
|
+
const core_1 = require("@theia/core");
|
|
22
|
+
const connection_container_module_1 = require("@theia/core/lib/node/messaging/connection-container-module");
|
|
23
|
+
const llamafile_preferences_1 = require("../common/llamafile-preferences");
|
|
24
|
+
// We use a connection module to handle AI services separately for each frontend.
|
|
25
|
+
const llamafileConnectionModule = connection_container_module_1.ConnectionContainerModule.create(({ bind, bindBackendService, bindFrontendService }) => {
|
|
26
|
+
bind(llamafile_manager_1.LlamafileManager).to(llamafile_manager_impl_1.LlamafileManagerImpl).inSingletonScope();
|
|
27
|
+
bind(core_1.ConnectionHandler).toDynamicValue(ctx => new core_1.RpcConnectionHandler(llamafile_manager_1.LlamafileManagerPath, client => {
|
|
28
|
+
const service = ctx.container.get(llamafile_manager_1.LlamafileManager);
|
|
29
|
+
service.setClient(client);
|
|
30
|
+
return service;
|
|
31
|
+
})).inSingletonScope();
|
|
32
|
+
});
|
|
33
|
+
exports.default = new inversify_1.ContainerModule(bind => {
|
|
34
|
+
(0, llamafile_preferences_1.bindAILlamafilePreferences)(bind);
|
|
35
|
+
bind(connection_container_module_1.ConnectionContainerModule).toConstantValue(llamafileConnectionModule);
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=llamafile-backend-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-backend-module.js","sourceRoot":"","sources":["../../src/node/llamafile-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,qEAAgE;AAChE,mEAAmH;AACnH,sCAAsE;AACtE,4GAAuG;AACvG,2EAA6E;AAE7E,iFAAiF;AACjF,MAAM,yBAAyB,GAAG,uDAAyB,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,EAAE,EAAE;IACrH,IAAI,CAAC,oCAAgB,CAAC,CAAC,EAAE,CAAC,6CAAoB,CAAC,CAAC,gBAAgB,EAAE,CAAC;IACnE,IAAI,CAAC,wBAAiB,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,2BAAoB,CAClE,wCAAoB,EACpB,MAAM,CAAC,EAAE;QACL,MAAM,OAAO,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAAmB,oCAAgB,CAAC,CAAC;QACtE,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC1B,OAAO,OAAO,CAAC;IACnB,CAAC,CACJ,CAAC,CAAC,gBAAgB,EAAE,CAAC;AAC1B,CAAC,CAAC,CAAC;AAEH,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAA,kDAA0B,EAAC,IAAI,CAAC,CAAC;IACjC,IAAI,CAAC,uDAAyB,CAAC,CAAC,eAAe,CAAC,yBAAyB,CAAC,CAAC;AAC/E,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { LanguageModelRegistry, LanguageModelStatus } from '@theia/ai-core';
|
|
3
|
+
import { ChildProcessWithoutNullStreams } from 'child_process';
|
|
4
|
+
import { LlamafileLanguageModel } from '../common/llamafile-language-model';
|
|
5
|
+
import { LlamafileManager, LlamafileModelDescription, LlamafileServerManagerClient } from '../common/llamafile-manager';
|
|
6
|
+
export declare class LlamafileManagerImpl implements LlamafileManager {
|
|
7
|
+
protected languageModelRegistry: LanguageModelRegistry;
|
|
8
|
+
private processMap;
|
|
9
|
+
private client;
|
|
10
|
+
addLanguageModels(LlamafileModelDescriptions: LlamafileModelDescription[]): Promise<void>;
|
|
11
|
+
removeLanguageModels(modelIds: string[]): void;
|
|
12
|
+
getStartedLlamafiles(): Promise<string[]>;
|
|
13
|
+
startServer(name: string): Promise<void>;
|
|
14
|
+
protected getLlamafileModel(name: string): Promise<LlamafileLanguageModel | undefined>;
|
|
15
|
+
protected spawnLlamafileProcess(llm: LlamafileLanguageModel): ChildProcessWithoutNullStreams;
|
|
16
|
+
protected attachProcessHandlers(name: string, currentProcess: ChildProcessWithoutNullStreams): void;
|
|
17
|
+
protected updateLanguageModelStatus(modelId: string, hasStarted: boolean, message?: string): Promise<void>;
|
|
18
|
+
protected calculateStatus(started: boolean, message?: string): LanguageModelStatus;
|
|
19
|
+
stopServer(name: string): void;
|
|
20
|
+
isStarted(name: string): boolean;
|
|
21
|
+
setClient(client: LlamafileServerManagerClient): void;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=llamafile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,CAAC,EAAE,MAAM,GAAG,mBAAmB;IAQlF,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAU9B,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIhC,SAAS,CAAC,MAAM,EAAE,4BAA4B,GAAG,IAAI;CAIxD"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LlamafileManagerImpl = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// *****************************************************************************
|
|
6
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
7
|
+
//
|
|
8
|
+
// This program and the accompanying materials are made available under the
|
|
9
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
10
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
11
|
+
//
|
|
12
|
+
// This Source Code may also be made available under the following Secondary
|
|
13
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
14
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
15
|
+
// with the GNU Classpath Exception which is available at
|
|
16
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
17
|
+
//
|
|
18
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
19
|
+
// *****************************************************************************
|
|
20
|
+
const ai_core_1 = require("@theia/ai-core");
|
|
21
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
22
|
+
const child_process_1 = require("child_process");
|
|
23
|
+
const path_1 = require("path");
|
|
24
|
+
const url_1 = require("url");
|
|
25
|
+
const llamafile_language_model_1 = require("../common/llamafile-language-model");
|
|
26
|
+
let LlamafileManagerImpl = class LlamafileManagerImpl {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.processMap = new Map();
|
|
29
|
+
}
|
|
30
|
+
async addLanguageModels(LlamafileModelDescriptions) {
|
|
31
|
+
for (const llamafile of LlamafileModelDescriptions) {
|
|
32
|
+
const model = await this.languageModelRegistry.getLanguageModel(llamafile.name);
|
|
33
|
+
if (model) {
|
|
34
|
+
if (!(model instanceof llamafile_language_model_1.LlamafileLanguageModel)) {
|
|
35
|
+
console.warn(`Llamafile: model ${model.id} is not a Llamafile model`);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// This can happen during the initializing of more than one frontends, changes are handled in the frontend
|
|
40
|
+
console.info(`Llamafile: skip creating or updating model ${llamafile.name} because it already exists.`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.languageModelRegistry.addLanguageModels([
|
|
45
|
+
new llamafile_language_model_1.LlamafileLanguageModel(llamafile.name, this.calculateStatus(false), llamafile.uri, llamafile.port)
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
removeLanguageModels(modelIds) {
|
|
51
|
+
modelIds.filter(modelId => this.isStarted(modelId)).forEach(modelId => this.stopServer(modelId));
|
|
52
|
+
this.languageModelRegistry.removeLanguageModels(modelIds);
|
|
53
|
+
}
|
|
54
|
+
async getStartedLlamafiles() {
|
|
55
|
+
const models = await this.languageModelRegistry.getLanguageModels();
|
|
56
|
+
return models.filter(model => model instanceof llamafile_language_model_1.LlamafileLanguageModel && this.isStarted(model.name)).map(model => model.id);
|
|
57
|
+
}
|
|
58
|
+
async startServer(name) {
|
|
59
|
+
if (this.processMap.has(name)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const llm = await this.getLlamafileModel(name);
|
|
63
|
+
if (!llm) {
|
|
64
|
+
return Promise.reject(`Llamafile ${name} not found`);
|
|
65
|
+
}
|
|
66
|
+
const currentProcess = this.spawnLlamafileProcess(llm);
|
|
67
|
+
this.processMap.set(name, currentProcess);
|
|
68
|
+
await this.updateLanguageModelStatus(name, true);
|
|
69
|
+
this.attachProcessHandlers(name, currentProcess);
|
|
70
|
+
}
|
|
71
|
+
async getLlamafileModel(name) {
|
|
72
|
+
const models = await this.languageModelRegistry.getLanguageModels();
|
|
73
|
+
return models.find(model => model.id === name && model instanceof llamafile_language_model_1.LlamafileLanguageModel);
|
|
74
|
+
}
|
|
75
|
+
spawnLlamafileProcess(llm) {
|
|
76
|
+
const filePath = (0, url_1.fileURLToPath)(llm.uri);
|
|
77
|
+
const dir = (0, path_1.dirname)(filePath);
|
|
78
|
+
const fileName = (0, path_1.basename)(filePath);
|
|
79
|
+
return (0, child_process_1.spawn)(`./${fileName}`, ['--port', '' + llm.port, '--server', '--nobrowser'], { cwd: dir });
|
|
80
|
+
}
|
|
81
|
+
attachProcessHandlers(name, currentProcess) {
|
|
82
|
+
currentProcess.stdout.on('data', (data) => {
|
|
83
|
+
this.client.log(name, data.toString());
|
|
84
|
+
});
|
|
85
|
+
currentProcess.stderr.on('data', (data) => {
|
|
86
|
+
this.client.error(name, data.toString());
|
|
87
|
+
});
|
|
88
|
+
currentProcess.on('close', code => {
|
|
89
|
+
this.client.log(name, `LlamaFile process for file ${name} exited with code ${code}`);
|
|
90
|
+
this.processMap.delete(name);
|
|
91
|
+
// Set status to 'unavailable' when server stops
|
|
92
|
+
this.updateLanguageModelStatus(name, false);
|
|
93
|
+
});
|
|
94
|
+
currentProcess.on('error', error => {
|
|
95
|
+
this.client.error(name, `Error starting LlamaFile process for file ${name}: ${error.message}`);
|
|
96
|
+
this.processMap.delete(name);
|
|
97
|
+
// Set status to 'unavailable' on error
|
|
98
|
+
this.updateLanguageModelStatus(name, false, error.message);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
async updateLanguageModelStatus(modelId, hasStarted, message) {
|
|
102
|
+
const status = this.calculateStatus(hasStarted, message);
|
|
103
|
+
await this.languageModelRegistry.patchLanguageModel(modelId, {
|
|
104
|
+
status
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
calculateStatus(started, message) {
|
|
108
|
+
if (started) {
|
|
109
|
+
return { status: 'ready' };
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
return { status: 'unavailable', message: message || 'Llamafile server is not running' };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
stopServer(name) {
|
|
116
|
+
if (this.processMap.has(name)) {
|
|
117
|
+
const currentProcess = this.processMap.get(name);
|
|
118
|
+
currentProcess.kill();
|
|
119
|
+
this.processMap.delete(name);
|
|
120
|
+
// Set status to 'unavailable' when server is stopped
|
|
121
|
+
this.updateLanguageModelStatus(name, false);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
isStarted(name) {
|
|
125
|
+
return this.processMap.has(name);
|
|
126
|
+
}
|
|
127
|
+
setClient(client) {
|
|
128
|
+
this.client = client;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
exports.LlamafileManagerImpl = LlamafileManagerImpl;
|
|
132
|
+
tslib_1.__decorate([
|
|
133
|
+
(0, inversify_1.inject)(ai_core_1.LanguageModelRegistry),
|
|
134
|
+
tslib_1.__metadata("design:type", Object)
|
|
135
|
+
], LlamafileManagerImpl.prototype, "languageModelRegistry", void 0);
|
|
136
|
+
exports.LlamafileManagerImpl = LlamafileManagerImpl = tslib_1.__decorate([
|
|
137
|
+
(0, inversify_1.injectable)()
|
|
138
|
+
], LlamafileManagerImpl);
|
|
139
|
+
//# sourceMappingURL=llamafile-manager-impl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-manager-impl.js","sourceRoot":"","sources":["../../src/node/llamafile-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;AAChF,4CAA4E;AAC5E,4DAAkE;AAClE,iDAAsE;AACtE,+B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C;IAED,SAAS,CAAC,MAAoC;QAC1C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CAEJ,CAAA;AA/HY,oDAAoB;AAGnB;IADT,IAAA,kBAAM,EAAC,+BAAqB,CAAC;;mEACyB;+BAH9C,oBAAoB;IADhC,IAAA,sBAAU,GAAE;GACA,oBAAoB,CA+HhC"}
|
|
@@ -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 TypeFox 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-llamafile 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,8CAA8C;AAC9C,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,sBAAsB,EAAE,GAAG,EAAE;IAClC,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;AACvD,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theia/ai-llamafile",
|
|
3
|
-
"version": "1.67.0-next.
|
|
3
|
+
"version": "1.67.0-next.86+03f92ff1d",
|
|
4
4
|
"description": "Theia - Llamafile Integration",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@theia/ai-core": "1.67.0-next.
|
|
7
|
-
"@theia/core": "1.67.0-next.
|
|
8
|
-
"@theia/output": "1.67.0-next.
|
|
6
|
+
"@theia/ai-core": "1.67.0-next.86+03f92ff1d",
|
|
7
|
+
"@theia/core": "1.67.0-next.86+03f92ff1d",
|
|
8
|
+
"@theia/output": "1.67.0-next.86+03f92ff1d",
|
|
9
9
|
"tslib": "^2.6.2"
|
|
10
10
|
},
|
|
11
11
|
"publishConfig": {
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"nyc": {
|
|
48
48
|
"extends": "../../configs/nyc.json"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "03f92ff1d97dcb199de39b48e60a53535de22808"
|
|
51
51
|
}
|
|
@@ -27,14 +27,6 @@ export class LlamafileManagerImpl implements LlamafileManager {
|
|
|
27
27
|
@inject(LanguageModelRegistry)
|
|
28
28
|
protected languageModelRegistry: LanguageModelRegistry;
|
|
29
29
|
|
|
30
|
-
protected calculateStatus(started: boolean, message?: string): LanguageModelStatus {
|
|
31
|
-
if (started) {
|
|
32
|
-
return { status: 'ready' };
|
|
33
|
-
} else {
|
|
34
|
-
return { status: 'unavailable', message: message || 'Llamafile server is not running' };
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
30
|
private processMap: Map<string, ChildProcessWithoutNullStreams> = new Map();
|
|
39
31
|
private client: LlamafileServerManagerClient;
|
|
40
32
|
|
|
@@ -73,43 +65,69 @@ export class LlamafileManagerImpl implements LlamafileManager {
|
|
|
73
65
|
}
|
|
74
66
|
|
|
75
67
|
async startServer(name: string): Promise<void> {
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
68
|
+
if (this.processMap.has(name)) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const llm = await this.getLlamafileModel(name);
|
|
73
|
+
if (!llm) {
|
|
74
|
+
return Promise.reject(`Llamafile ${name} not found`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const currentProcess = this.spawnLlamafileProcess(llm);
|
|
78
|
+
this.processMap.set(name, currentProcess);
|
|
79
|
+
await this.updateLanguageModelStatus(name, true);
|
|
80
|
+
this.attachProcessHandlers(name, currentProcess);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
protected async getLlamafileModel(name: string): Promise<LlamafileLanguageModel | undefined> {
|
|
84
|
+
const models = await this.languageModelRegistry.getLanguageModels();
|
|
85
|
+
return models.find(model => model.id === name && model instanceof LlamafileLanguageModel) as LlamafileLanguageModel | undefined;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
protected spawnLlamafileProcess(llm: LlamafileLanguageModel): ChildProcessWithoutNullStreams {
|
|
89
|
+
const filePath = fileURLToPath(llm.uri);
|
|
90
|
+
const dir = dirname(filePath);
|
|
91
|
+
const fileName = basename(filePath);
|
|
92
|
+
return spawn(`./${fileName}`, ['--port', '' + llm.port, '--server', '--nobrowser'], { cwd: dir });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
protected attachProcessHandlers(name: string, currentProcess: ChildProcessWithoutNullStreams): void {
|
|
96
|
+
currentProcess.stdout.on('data', (data: Buffer) => {
|
|
97
|
+
this.client.log(name, data.toString());
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
currentProcess.stderr.on('data', (data: Buffer) => {
|
|
101
|
+
this.client.error(name, data.toString());
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
currentProcess.on('close', code => {
|
|
105
|
+
this.client.log(name, `LlamaFile process for file ${name} exited with code ${code}`);
|
|
106
|
+
this.processMap.delete(name);
|
|
107
|
+
// Set status to 'unavailable' when server stops
|
|
108
|
+
this.updateLanguageModelStatus(name, false);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
currentProcess.on('error', error => {
|
|
112
|
+
this.client.error(name, `Error starting LlamaFile process for file ${name}: ${error.message}`);
|
|
113
|
+
this.processMap.delete(name);
|
|
114
|
+
// Set status to 'unavailable' on error
|
|
115
|
+
this.updateLanguageModelStatus(name, false, error.message);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
protected async updateLanguageModelStatus(modelId: string, hasStarted: boolean, message?: string): Promise<void> {
|
|
120
|
+
const status: LanguageModelStatus = this.calculateStatus(hasStarted, message);
|
|
121
|
+
await this.languageModelRegistry.patchLanguageModel<LlamafileLanguageModel>(modelId, {
|
|
122
|
+
status
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
protected calculateStatus(started: boolean, message?: string): LanguageModelStatus {
|
|
127
|
+
if (started) {
|
|
128
|
+
return { status: 'ready' };
|
|
129
|
+
} else {
|
|
130
|
+
return { status: 'unavailable', message: message || 'Llamafile server is not running' };
|
|
113
131
|
}
|
|
114
132
|
}
|
|
115
133
|
|
|
@@ -119,11 +137,7 @@ export class LlamafileManagerImpl implements LlamafileManager {
|
|
|
119
137
|
currentProcess!.kill();
|
|
120
138
|
this.processMap.delete(name);
|
|
121
139
|
// Set status to 'unavailable' when server is stopped
|
|
122
|
-
this.
|
|
123
|
-
if (model && model instanceof LlamafileLanguageModel) {
|
|
124
|
-
model.status = { status: 'unavailable' };
|
|
125
|
-
}
|
|
126
|
-
});
|
|
140
|
+
this.updateLanguageModelStatus(name, false);
|
|
127
141
|
}
|
|
128
142
|
}
|
|
129
143
|
|