@theia/ai-llamafile 1.55.0-next.37
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 +57 -0
- 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 +9 -0
- package/lib/browser/llamafile-frontend-application-contribution.d.ts.map +1 -0
- package/lib/browser/llamafile-frontend-application-contribution.js +60 -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/browser/llamafile-preferences.d.ts +7 -0
- package/lib/browser/llamafile-preferences.d.ts.map +1 -0
- package/lib/browser/llamafile-preferences.js +60 -0
- package/lib/browser/llamafile-preferences.js.map +1 -0
- package/lib/common/llamafile-language-model.d.ts +12 -0
- package/lib/common/llamafile-language-model.d.ts.map +1 -0
- package/lib/common/llamafile-language-model.js +101 -0
- package/lib/common/llamafile-language-model.js.map +1 -0
- package/lib/common/llamafile-manager.d.ts +24 -0
- package/lib/common/llamafile-manager.d.ts.map +1 -0
- package/lib/common/llamafile-manager.js +36 -0
- package/lib/common/llamafile-manager.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 +30 -0
- package/lib/node/llamafile-backend-module.js.map +1 -0
- package/lib/node/llamafile-manager-impl.d.ts +15 -0
- package/lib/node/llamafile-manager-impl.d.ts.map +1 -0
- package/lib/node/llamafile-manager-impl.js +109 -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 +51 -0
- package/src/browser/llamafile-command-contribution.ts +92 -0
- package/src/browser/llamafile-frontend-application-contribution.ts +59 -0
- package/src/browser/llamafile-frontend-module.ts +45 -0
- package/src/browser/llamafile-preferences.ts +60 -0
- package/src/common/llamafile-language-model.ts +102 -0
- package/src/common/llamafile-manager.ts +50 -0
- package/src/node/llamafile-backend-module.ts +32 -0
- package/src/node/llamafile-manager-impl.ts +109 -0
- package/src/package.spec.ts +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# AI Llamafile Integration
|
|
2
|
+
|
|
3
|
+
The AI Llamafile package provides an integration that allows users to manage and interact with Llamafile language models within Theia IDE.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Start and stop Llamafile language servers.
|
|
8
|
+
|
|
9
|
+
## Commands
|
|
10
|
+
|
|
11
|
+
### Start Llamafile
|
|
12
|
+
|
|
13
|
+
- **Command ID:** `llamafile.start`
|
|
14
|
+
- **Label:** `Start Llamafile`
|
|
15
|
+
- **Functionality:** Allows you to start a Llamafile language server by selecting from a list of configured Llamafiles.
|
|
16
|
+
|
|
17
|
+
### Stop Llamafile
|
|
18
|
+
|
|
19
|
+
- **Command ID:** `llamafile.stop`
|
|
20
|
+
- **Label:** `Stop Llamafile`
|
|
21
|
+
- **Functionality:** Allows you to stop a running Llamafile language server by selecting from a list of currently running Llamafiles.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
1. **Starting a Llamafile Language Server:**
|
|
26
|
+
|
|
27
|
+
- Use the command palette to invoke `Start Llamafile`.
|
|
28
|
+
- A quick pick menu will appear with a list of configured Llamafiles.
|
|
29
|
+
- Select a Llamafile to start its language server.
|
|
30
|
+
|
|
31
|
+
2. **Stopping a Llamafile Language Server:**
|
|
32
|
+
- Use the command palette to invoke `Stop Llamafile`.
|
|
33
|
+
- A quick pick menu will display a list of currently running Llamafiles.
|
|
34
|
+
- Select a Llamafile to stop its language server.
|
|
35
|
+
|
|
36
|
+
## Dependencies
|
|
37
|
+
|
|
38
|
+
This extension depends on the `@theia/ai-core` package for AI-related services and functionalities.
|
|
39
|
+
|
|
40
|
+
## Configuration
|
|
41
|
+
|
|
42
|
+
Make sure to configure your Llamafiles properly within the preference settings.
|
|
43
|
+
This setting is an array of objects, where each object defines a llamafile with a user-friendly name, the file uri, and the port to start the server on.
|
|
44
|
+
|
|
45
|
+
Example Configuration:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"ai-features.llamafile.llamafiles": [
|
|
50
|
+
{
|
|
51
|
+
"name": "MyLlamaFile",
|
|
52
|
+
"uri": "file:///path/to/my.llamafile",
|
|
53
|
+
"port": 30000
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AICommandHandlerFactory } from '@theia/ai-core/lib/browser/ai-command-handler-factory';
|
|
2
|
+
import { CommandContribution, CommandRegistry, MessageService } from '@theia/core';
|
|
3
|
+
import { PreferenceService, 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,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE/E,OAAO,EAAkB,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAG/E,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;CA0C3D"}
|
|
@@ -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("./llamafile-preferences");
|
|
26
|
+
exports.StartLlamafileCommand = {
|
|
27
|
+
id: 'llamafile.start',
|
|
28
|
+
label: 'Start Llamafile',
|
|
29
|
+
};
|
|
30
|
+
exports.StopLlamafileCommand = {
|
|
31
|
+
id: 'llamafile.stop',
|
|
32
|
+
label: '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('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(`Something went wrong during the llamafile start: ${error.message}.\nFor more information, see the console.`);
|
|
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('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(`Something went wrong during the llamafile stop: ${error.message}.\nFor more information, see the console.`);
|
|
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)(browser_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,sCAAmF;AACnF,qDAA+E;AAC/E,4DAAkE;AAClE,mEAA+E;AAC/E,mEAA+D;AAElD,QAAA,qBAAqB,GAAG;IACjC,EAAE,EAAE,iBAAiB;IACrB,KAAK,EAAE,iBAAiB;CAC3B,CAA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uCAfpC,4BAA4B;IADxC,IAAA,sBAAU,GAAE;GACA,4BAA4B,CA2DxC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FrontendApplicationContribution, PreferenceService } from '@theia/core/lib/browser';
|
|
2
|
+
import { LlamafileManager } from '../common/llamafile-manager';
|
|
3
|
+
export declare class LlamafileFrontendApplicationContribution implements FrontendApplicationContribution {
|
|
4
|
+
protected preferenceService: PreferenceService;
|
|
5
|
+
protected llamafileManager: LlamafileManager;
|
|
6
|
+
private _knownLlamaFiles;
|
|
7
|
+
onStart(): void;
|
|
8
|
+
}
|
|
9
|
+
//# 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,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE7F,OAAO,EAAkB,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAG/E,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;CA0BlB"}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 browser_1 = require("@theia/core/lib/browser");
|
|
21
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
22
|
+
const llamafile_manager_1 = require("../common/llamafile-manager");
|
|
23
|
+
const llamafile_preferences_1 = require("./llamafile-preferences");
|
|
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
|
+
this.llamafileManager.addLanguageModels(llamafiles);
|
|
32
|
+
llamafiles.forEach(model => this._knownLlamaFiles.set(model.name, model));
|
|
33
|
+
this.preferenceService.onPreferenceChanged(event => {
|
|
34
|
+
if (event.preferenceName === llamafile_preferences_1.PREFERENCE_LLAMAFILE) {
|
|
35
|
+
// only new models which are actual LLamaFileEntries
|
|
36
|
+
const newModels = event.newValue.filter((llamafileEntry) => llamafile_manager_1.LlamafileEntry.is(llamafileEntry));
|
|
37
|
+
const llamafilesToAdd = newModels.filter(llamafile => !this._knownLlamaFiles.has(llamafile.name) || !llamafile_manager_1.LlamafileEntry.equals(this._knownLlamaFiles.get(llamafile.name), llamafile));
|
|
38
|
+
const llamafileIdsToRemove = [...this._knownLlamaFiles.values()].filter(llamafile => !newModels.find(a => llamafile_manager_1.LlamafileEntry.equals(a, llamafile))).map(a => a.name);
|
|
39
|
+
this.llamafileManager.removeLanguageModels(llamafileIdsToRemove);
|
|
40
|
+
llamafileIdsToRemove.forEach(model => this._knownLlamaFiles.delete(model));
|
|
41
|
+
this.llamafileManager.addLanguageModels(llamafilesToAdd);
|
|
42
|
+
llamafilesToAdd.forEach(model => this._knownLlamaFiles.set(model.name, model));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
exports.LlamafileFrontendApplicationContribution = LlamafileFrontendApplicationContribution;
|
|
49
|
+
tslib_1.__decorate([
|
|
50
|
+
(0, inversify_1.inject)(browser_1.PreferenceService),
|
|
51
|
+
tslib_1.__metadata("design:type", Object)
|
|
52
|
+
], LlamafileFrontendApplicationContribution.prototype, "preferenceService", void 0);
|
|
53
|
+
tslib_1.__decorate([
|
|
54
|
+
(0, inversify_1.inject)(llamafile_manager_1.LlamafileManager),
|
|
55
|
+
tslib_1.__metadata("design:type", Object)
|
|
56
|
+
], LlamafileFrontendApplicationContribution.prototype, "llamafileManager", void 0);
|
|
57
|
+
exports.LlamafileFrontendApplicationContribution = LlamafileFrontendApplicationContribution = tslib_1.__decorate([
|
|
58
|
+
(0, inversify_1.injectable)()
|
|
59
|
+
], LlamafileFrontendApplicationContribution);
|
|
60
|
+
//# 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":[],"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;;;;AA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,CAChF,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,kCAAc,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;oBAEhF,IAAI,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,oBAAoB,CAAC,CAAC;oBACjE,oBAAoB,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;oBAE3E,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC;oBACzD,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;gBACnF,CAAC;YACL,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ,CAAA;AApCY,4FAAwC;AAGvC;IADT,IAAA,kBAAM,EAAC,2BAAiB,CAAC;;mFACqB;AAGrC;IADT,IAAA,kBAAM,EAAC,oCAAgB,CAAC;;kFACoB;mDANpC,wCAAwC;IADpD,IAAA,sBAAU,GAAE;GACA,wCAAwC,CAoCpD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-frontend-module.d.ts","sourceRoot":"","sources":["../../src/browser/llamafile-frontend-module.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;AAO/D,wBAoBG"}
|
|
@@ -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("./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,mEAAqE;AAErE,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,7 @@
|
|
|
1
|
+
import { PreferenceSchema } from '@theia/core/lib/browser';
|
|
2
|
+
import { interfaces } from '@theia/core/shared/inversify';
|
|
3
|
+
export declare const AI_LLAMAFILE_PREFERENCES_TITLE = "\u2728 AI LlamaFile";
|
|
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/browser/llamafile-preferences.ts"],"names":[],"mappings":"AAgBA,OAAO,EAA0B,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE1D,eAAO,MAAM,8BAA8B,wBAAmB,CAAC;AAC/D,eAAO,MAAM,oBAAoB,qCAAqC,CAAC;AAEvE,eAAO,MAAM,4BAA4B,EAAE,gBAiC1C,CAAC;AAEF,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,GAAG,IAAI,CAEtE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 browser_1 = require("@theia/core/lib/browser");
|
|
20
|
+
exports.AI_LLAMAFILE_PREFERENCES_TITLE = '✨ AI LlamaFile';
|
|
21
|
+
exports.PREFERENCE_LLAMAFILE = 'ai-features.llamafile.llamafiles';
|
|
22
|
+
exports.aiLlamafilePreferencesSchema = {
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
[exports.PREFERENCE_LLAMAFILE]: {
|
|
26
|
+
title: exports.AI_LLAMAFILE_PREFERENCES_TITLE,
|
|
27
|
+
markdownDescription: '❗ This setting allows you to add llamafiles.\
|
|
28
|
+
\n\
|
|
29
|
+
You need to provide a user friendly `name`, the file `uri` to the llamafile and the `port` to use.\
|
|
30
|
+
\n\
|
|
31
|
+
In order to start your llamafile you have to call the "Start Llamafile" command where you can then select the llamafile to start.\
|
|
32
|
+
\n\
|
|
33
|
+
If you modify an entry, e.g. change the port and the server was already running, then it will be stopped and you have to manually start it again.',
|
|
34
|
+
type: 'array',
|
|
35
|
+
default: [],
|
|
36
|
+
items: {
|
|
37
|
+
type: 'object',
|
|
38
|
+
properties: {
|
|
39
|
+
name: {
|
|
40
|
+
type: 'string',
|
|
41
|
+
description: 'The model name to use for this Llamafile.'
|
|
42
|
+
},
|
|
43
|
+
uri: {
|
|
44
|
+
type: 'string',
|
|
45
|
+
description: 'The file uri to the Llamafile.'
|
|
46
|
+
},
|
|
47
|
+
port: {
|
|
48
|
+
type: 'number',
|
|
49
|
+
description: 'The port to use to start the server.'
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
function bindAILlamafilePreferences(bind) {
|
|
57
|
+
bind(browser_1.PreferenceContribution).toConstantValue({ schema: exports.aiLlamafilePreferencesSchema });
|
|
58
|
+
}
|
|
59
|
+
exports.bindAILlamafilePreferences = bindAILlamafilePreferences;
|
|
60
|
+
//# sourceMappingURL=llamafile-preferences.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-preferences.js","sourceRoot":"","sources":["../../src/browser/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,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAEhF,qDAAmF;AAGtE,QAAA,8BAA8B,GAAG,gBAAgB,CAAC;AAClD,QAAA,oBAAoB,GAAG,kCAAkC,CAAC;AAE1D,QAAA,4BAA4B,GAAqB;IAC1D,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACR,CAAC,4BAAoB,CAAC,EAAE;YACpB,KAAK,EAAE,sCAA8B;YACrC,mBAAmB,EAAE;;;;;;8JAM6H;YAClJ,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,EAAE;YACX,KAAK,EAAE;gBACH,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACR,IAAI,EAAE;wBACF,IAAI,EAAE,QAAQ;wBACd,WAAW,EAAE,2CAA2C;qBAC3D;oBACD,GAAG,EAAE;wBACD,IAAI,EAAE,QAAQ;wBACd,WAAW,EAAE,gCAAgC;qBAChD;oBACD,IAAI,EAAE;wBACF,IAAI,EAAE,QAAQ;wBACd,WAAW,EAAE,sCAAsC;qBACtD;iBACJ;aACJ;SACJ;KACJ;CACJ,CAAC;AAEF,SAAgB,0BAA0B,CAAC,IAAqB;IAC5D,IAAI,CAAC,gCAAsB,CAAC,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,oCAA4B,EAAE,CAAC,CAAC;AAC3F,CAAC;AAFD,gEAEC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LanguageModel, LanguageModelRequest, LanguageModelResponse } from '@theia/ai-core';
|
|
2
|
+
export declare class LlamafileLanguageModel implements LanguageModel {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly uri: string;
|
|
5
|
+
readonly port: number;
|
|
6
|
+
readonly providerId = "llamafile";
|
|
7
|
+
readonly vendor: string;
|
|
8
|
+
constructor(name: string, uri: string, port: number);
|
|
9
|
+
get id(): string;
|
|
10
|
+
request(request: LanguageModelRequest): Promise<LanguageModelResponse>;
|
|
11
|
+
}
|
|
12
|
+
//# 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,EAAE,oBAAoB,EAAE,qBAAqB,EAAmC,MAAM,gBAAgB,CAAC;AAE7H,qBAAa,sBAAuB,YAAW,aAAa;IAK5C,QAAQ,CAAC,IAAI,EAAE,MAAM;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM;IAH9E,QAAQ,CAAC,UAAU,eAAe;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAa;gBAEf,IAAI,EAAE,MAAM,EAAW,GAAG,EAAE,MAAM,EAAW,IAAI,EAAE,MAAM;IAG9E,IAAI,EAAE,IAAI,MAAM,CAEf;IAEK,OAAO,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAuE/E"}
|
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
class LlamafileLanguageModel {
|
|
20
|
+
constructor(name, uri, port) {
|
|
21
|
+
this.name = name;
|
|
22
|
+
this.uri = uri;
|
|
23
|
+
this.port = port;
|
|
24
|
+
this.providerId = 'llamafile';
|
|
25
|
+
this.vendor = 'Mozilla';
|
|
26
|
+
}
|
|
27
|
+
get id() {
|
|
28
|
+
return this.name;
|
|
29
|
+
}
|
|
30
|
+
async request(request) {
|
|
31
|
+
try {
|
|
32
|
+
let prompt = request.messages.map(message => {
|
|
33
|
+
switch (message.actor) {
|
|
34
|
+
case 'user':
|
|
35
|
+
return `User: ${message.query}`;
|
|
36
|
+
case 'ai':
|
|
37
|
+
return `Llama: ${message.query}`;
|
|
38
|
+
case 'system':
|
|
39
|
+
return `${message.query.replace(/\n\n/g, '\n')}`;
|
|
40
|
+
}
|
|
41
|
+
}).join('\n');
|
|
42
|
+
prompt += '\nLlama:';
|
|
43
|
+
const response = await fetch(`http://localhost:${this.port}/completion`, {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
headers: {
|
|
46
|
+
'Content-Type': 'application/json',
|
|
47
|
+
},
|
|
48
|
+
body: JSON.stringify({
|
|
49
|
+
prompt: prompt,
|
|
50
|
+
n_predict: 200,
|
|
51
|
+
stream: true,
|
|
52
|
+
stop: ['</s>', 'Llama:', 'User:', '<|eot_id|>'],
|
|
53
|
+
cache_prompt: true,
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
58
|
+
}
|
|
59
|
+
if (!response.body) {
|
|
60
|
+
throw new Error('Response body is undefined');
|
|
61
|
+
}
|
|
62
|
+
const reader = response.body.getReader();
|
|
63
|
+
const decoder = new TextDecoder();
|
|
64
|
+
return {
|
|
65
|
+
stream: {
|
|
66
|
+
[Symbol.asyncIterator]() {
|
|
67
|
+
return {
|
|
68
|
+
async next() {
|
|
69
|
+
const { value, done } = await reader.read();
|
|
70
|
+
if (done) {
|
|
71
|
+
return { value: undefined, done: true };
|
|
72
|
+
}
|
|
73
|
+
const read = decoder.decode(value, { stream: true });
|
|
74
|
+
const chunk = read.split('\n').filter(l => l.length !== 0).reduce((acc, line) => {
|
|
75
|
+
try {
|
|
76
|
+
const parsed = JSON.parse(line.substring(6));
|
|
77
|
+
acc += parsed.content;
|
|
78
|
+
return acc;
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
console.error('Error parsing JSON:', error);
|
|
82
|
+
return acc;
|
|
83
|
+
}
|
|
84
|
+
}, '');
|
|
85
|
+
return { value: { content: chunk }, done: false };
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
console.error('Error:', error);
|
|
94
|
+
return {
|
|
95
|
+
text: `Error: ${error}`
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.LlamafileLanguageModel = LlamafileLanguageModel;
|
|
101
|
+
//# 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,gFAAgF;;;AAIhF,MAAa,sBAAsB;IAK/B,YAAqB,IAAY,EAAW,GAA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f,CAAC;gCACL,CAAC,EAAE,EAAE,CAAC,CAAC;gCACP,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;4BACtD,CAAC;yBACJ,CAAC;oBACN,CAAC;iBACJ;aACJ,CAAC;QACN,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YAC/B,OAAO;gBACH,IAAI,EAAE,UAAU,KAAK,EAAE;aAC1B,CAAC;QACN,CAAC;IACL,CAAC;CAEJ;AAnFD,wDAmFC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const LlamafileManager: unique symbol;
|
|
2
|
+
export declare const LlamafileManagerPath = "/services/llamafilemanager";
|
|
3
|
+
export interface LlamafileManager {
|
|
4
|
+
startServer(name: string): Promise<void>;
|
|
5
|
+
stopServer(name: string): void;
|
|
6
|
+
getStartedLlamafiles(): Promise<string[]>;
|
|
7
|
+
setClient(client: LlamafileServerManagerClient): void;
|
|
8
|
+
addLanguageModels(llamaFiles: LlamafileEntry[]): Promise<void>;
|
|
9
|
+
removeLanguageModels(modelIds: string[]): void;
|
|
10
|
+
}
|
|
11
|
+
export interface LlamafileServerManagerClient {
|
|
12
|
+
log(llamafileName: string, message: string): void;
|
|
13
|
+
error(llamafileName: string, message: string): void;
|
|
14
|
+
}
|
|
15
|
+
export interface LlamafileEntry {
|
|
16
|
+
name: string;
|
|
17
|
+
uri: string;
|
|
18
|
+
port: number;
|
|
19
|
+
}
|
|
20
|
+
export declare namespace LlamafileEntry {
|
|
21
|
+
function equals(a: LlamafileEntry, b: LlamafileEntry): boolean;
|
|
22
|
+
function is(entry: unknown): entry is LlamafileEntry;
|
|
23
|
+
}
|
|
24
|
+
//# 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,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,cAAc,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/D,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;AAED,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,yBAAiB,cAAc,CAAC;IAC5B,SAAgB,MAAM,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,EAAE,cAAc,GAAG,OAAO,CAEpE;IACD,SAAgB,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAM1D;CACJ"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LlamafileEntry = 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
|
+
var LlamafileEntry;
|
|
22
|
+
(function (LlamafileEntry) {
|
|
23
|
+
function equals(a, b) {
|
|
24
|
+
return a.name === b.name && a.uri === b.uri && a.port === b.port;
|
|
25
|
+
}
|
|
26
|
+
LlamafileEntry.equals = equals;
|
|
27
|
+
function is(entry) {
|
|
28
|
+
// eslint-disable-next-line no-null/no-null
|
|
29
|
+
return typeof entry === 'object' && entry !== null
|
|
30
|
+
&& 'name' in entry && typeof entry.name === 'string'
|
|
31
|
+
&& 'uri' in entry && typeof entry.uri === 'string'
|
|
32
|
+
&& 'port' in entry && typeof entry.port === 'number';
|
|
33
|
+
}
|
|
34
|
+
LlamafileEntry.is = is;
|
|
35
|
+
})(LlamafileEntry || (exports.LlamafileEntry = LlamafileEntry = {}));
|
|
36
|
+
//# 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;AAqBjE,IAAiB,cAAc,CAW9B;AAXD,WAAiB,cAAc;IAC3B,SAAgB,MAAM,CAAC,CAAiB,EAAE,CAAiB;QACvD,OAAO,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,CAAC;IACrE,CAAC;IAFe,qBAAM,SAErB,CAAA;IACD,SAAgB,EAAE,CAAC,KAAc;QAC7B,2CAA2C;QAC3C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;eAC3C,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;eACjD,KAAK,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ;eAC/C,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;IAC7D,CAAC;IANe,iBAAE,KAMjB,CAAA;AACL,CAAC,EAXgB,cAAc,8BAAd,cAAc,QAW9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-backend-module.d.ts","sourceRoot":"","sources":["../../src/node/llamafile-backend-module.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;AAK/D,wBAUG"}
|