@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
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
export const LlamafileManager = Symbol('LlamafileManager');
|
|
17
|
+
|
|
18
|
+
export const LlamafileManagerPath = '/services/llamafilemanager';
|
|
19
|
+
|
|
20
|
+
export interface LlamafileManager {
|
|
21
|
+
startServer(name: string): Promise<void>;
|
|
22
|
+
stopServer(name: string): void;
|
|
23
|
+
getStartedLlamafiles(): Promise<string[]>;
|
|
24
|
+
setClient(client: LlamafileServerManagerClient): void;
|
|
25
|
+
addLanguageModels(llamaFiles: LlamafileEntry[]): Promise<void>;
|
|
26
|
+
removeLanguageModels(modelIds: string[]): void;
|
|
27
|
+
}
|
|
28
|
+
export interface LlamafileServerManagerClient {
|
|
29
|
+
log(llamafileName: string, message: string): void;
|
|
30
|
+
error(llamafileName: string, message: string): void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface LlamafileEntry {
|
|
34
|
+
name: string;
|
|
35
|
+
uri: string;
|
|
36
|
+
port: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export namespace LlamafileEntry {
|
|
40
|
+
export function equals(a: LlamafileEntry, b: LlamafileEntry): boolean {
|
|
41
|
+
return a.name === b.name && a.uri === b.uri && a.port === b.port;
|
|
42
|
+
}
|
|
43
|
+
export function is(entry: unknown): entry is LlamafileEntry {
|
|
44
|
+
// eslint-disable-next-line no-null/no-null
|
|
45
|
+
return typeof entry === 'object' && entry !== null
|
|
46
|
+
&& 'name' in entry && typeof entry.name === 'string'
|
|
47
|
+
&& 'uri' in entry && typeof entry.uri === 'string'
|
|
48
|
+
&& 'port' in entry && typeof entry.port === 'number';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
18
|
+
import { LlamafileManagerImpl } from './llamafile-manager-impl';
|
|
19
|
+
import { LlamafileManager, LlamafileServerManagerClient, LlamafileManagerPath } from '../common/llamafile-manager';
|
|
20
|
+
import { ConnectionHandler, RpcConnectionHandler } from '@theia/core';
|
|
21
|
+
|
|
22
|
+
export default new ContainerModule(bind => {
|
|
23
|
+
bind(LlamafileManager).to(LlamafileManagerImpl).inSingletonScope();
|
|
24
|
+
bind(ConnectionHandler).toDynamicValue(ctx => new RpcConnectionHandler<LlamafileServerManagerClient>(
|
|
25
|
+
LlamafileManagerPath,
|
|
26
|
+
client => {
|
|
27
|
+
const service = ctx.container.get<LlamafileManager>(LlamafileManager);
|
|
28
|
+
service.setClient(client);
|
|
29
|
+
return service;
|
|
30
|
+
}
|
|
31
|
+
)).inSingletonScope();
|
|
32
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
import { LanguageModelRegistry } from '@theia/ai-core';
|
|
17
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
18
|
+
import { ChildProcessWithoutNullStreams, spawn } from 'child_process';
|
|
19
|
+
import { basename, dirname } from 'path';
|
|
20
|
+
import { fileURLToPath } from 'url';
|
|
21
|
+
import { LlamafileLanguageModel } from '../common/llamafile-language-model';
|
|
22
|
+
import { LlamafileEntry, LlamafileManager, LlamafileServerManagerClient } from '../common/llamafile-manager';
|
|
23
|
+
|
|
24
|
+
@injectable()
|
|
25
|
+
export class LlamafileManagerImpl implements LlamafileManager {
|
|
26
|
+
|
|
27
|
+
@inject(LanguageModelRegistry)
|
|
28
|
+
protected languageModelRegistry: LanguageModelRegistry;
|
|
29
|
+
|
|
30
|
+
private processMap: Map<string, ChildProcessWithoutNullStreams> = new Map();
|
|
31
|
+
private client: LlamafileServerManagerClient;
|
|
32
|
+
|
|
33
|
+
async addLanguageModels(llamaFiles: LlamafileEntry[]): Promise<void> {
|
|
34
|
+
for (const llamafile of llamaFiles) {
|
|
35
|
+
const model = await this.languageModelRegistry.getLanguageModel(llamafile.name);
|
|
36
|
+
if (model) {
|
|
37
|
+
if (!(model instanceof LlamafileLanguageModel)) {
|
|
38
|
+
console.warn(`Llamafile: model ${model.id} is not an LLamafile model`);
|
|
39
|
+
continue;
|
|
40
|
+
} else {
|
|
41
|
+
// This can happen during the initializing of more than one frontends, changes are handled in the frontend
|
|
42
|
+
console.info(`Llamafile: skip creating or updating model ${llamafile.name} because it already exists.`);
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
this.languageModelRegistry.addLanguageModels([new LlamafileLanguageModel(llamafile.name, llamafile.uri, llamafile.port)]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
removeLanguageModels(modelIds: string[]): void {
|
|
50
|
+
modelIds.filter(modelId => this.isStarted(modelId)).forEach(modelId => this.stopServer(modelId));
|
|
51
|
+
this.languageModelRegistry.removeLanguageModels(modelIds);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async getStartedLlamafiles(): Promise<string[]> {
|
|
55
|
+
const models = await this.languageModelRegistry.getLanguageModels();
|
|
56
|
+
return models.filter(model => model instanceof LlamafileLanguageModel && this.isStarted(model.name)).map(model => model.id);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async startServer(name: string): Promise<void> {
|
|
60
|
+
if (!this.processMap.has(name)) {
|
|
61
|
+
const models = await this.languageModelRegistry.getLanguageModels();
|
|
62
|
+
const llm = models.find(model => model.id === name && model instanceof LlamafileLanguageModel) as LlamafileLanguageModel | undefined;
|
|
63
|
+
if (llm === undefined) {
|
|
64
|
+
return Promise.reject(`Llamafile ${name} not found`);
|
|
65
|
+
}
|
|
66
|
+
const filePath = fileURLToPath(llm.uri);
|
|
67
|
+
|
|
68
|
+
// Extract the directory and file name
|
|
69
|
+
const dir = dirname(filePath);
|
|
70
|
+
const fileName = basename(filePath);
|
|
71
|
+
const currentProcess = spawn(`./${fileName}`, ['--port', '' + llm.port, '--server', '--nobrowser'], { cwd: dir });
|
|
72
|
+
this.processMap.set(name, currentProcess);
|
|
73
|
+
|
|
74
|
+
currentProcess.stdout.on('data', (data: Buffer) => {
|
|
75
|
+
const output = data.toString();
|
|
76
|
+
this.client.log(name, output);
|
|
77
|
+
});
|
|
78
|
+
currentProcess.stderr.on('data', (data: Buffer) => {
|
|
79
|
+
const output = data.toString();
|
|
80
|
+
this.client.error(name, output);
|
|
81
|
+
});
|
|
82
|
+
currentProcess.on('close', code => {
|
|
83
|
+
this.client.log(name, `LlamaFile process for file ${name} exited with code ${code}`);
|
|
84
|
+
this.processMap.delete(name);
|
|
85
|
+
});
|
|
86
|
+
currentProcess.on('error', error => {
|
|
87
|
+
this.client.error(name, `Error starting LlamaFile process for file ${name}: ${error.message}`);
|
|
88
|
+
this.processMap.delete(name);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
stopServer(name: string): void {
|
|
94
|
+
if (this.processMap.has(name)) {
|
|
95
|
+
const currentProcess = this.processMap.get(name);
|
|
96
|
+
currentProcess!.kill();
|
|
97
|
+
this.processMap.delete(name);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
isStarted(name: string): boolean {
|
|
102
|
+
return this.processMap.has(name);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
setClient(client: LlamafileServerManagerClient): void {
|
|
106
|
+
this.client = client;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
|
|
17
|
+
/* note: this bogus test file is required so that
|
|
18
|
+
we are able to run mocha unit tests on this
|
|
19
|
+
package, without having any actual unit tests in it.
|
|
20
|
+
This way a coverage report will be generated,
|
|
21
|
+
showing 0% coverage, instead of no report.
|
|
22
|
+
This file can be removed once we have real unit
|
|
23
|
+
tests in place. */
|
|
24
|
+
|
|
25
|
+
describe('ai-llamafile package', () => {
|
|
26
|
+
it('support code coverage statistics', () => true);
|
|
27
|
+
});
|