@theia/ai-llamafile 1.46.0-next.241
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +18 -0
- package/lib/browser/llamafile-frontend-application-contribution.d.ts.map +1 -0
- package/lib/browser/llamafile-frontend-application-contribution.js +113 -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 +62 -0
- package/lib/browser/llamafile-preferences.js.map +1 -0
- package/lib/common/llamafile-language-model.d.ts +25 -0
- package/lib/common/llamafile-language-model.d.ts.map +1 -0
- package/lib/common/llamafile-language-model.js +122 -0
- package/lib/common/llamafile-language-model.js.map +1 -0
- package/lib/common/llamafile-manager.d.ts +29 -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/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 +18 -0
- package/lib/node/llamafile-manager-impl.d.ts.map +1 -0
- package/lib/node/llamafile-manager-impl.js +123 -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 +93 -0
- package/src/browser/llamafile-frontend-application-contribution.ts +126 -0
- package/src/browser/llamafile-frontend-module.ts +45 -0
- package/src/browser/llamafile-preferences.ts +62 -0
- package/src/common/llamafile-language-model.ts +126 -0
- package/src/common/llamafile-manager.ts +42 -0
- package/src/node/llamafile-backend-module.ts +32 -0
- package/src/node/llamafile-manager-impl.ts +129 -0
- package/src/package.spec.ts +27 -0
|
@@ -0,0 +1,62 @@
|
|
|
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 { PreferenceContribution, PreferenceSchema } from '@theia/core/lib/browser';
|
|
18
|
+
import { interfaces } from '@theia/core/shared/inversify';
|
|
19
|
+
|
|
20
|
+
export const AI_LLAMAFILE_PREFERENCES_TITLE = '✨ AI LlamaFile';
|
|
21
|
+
export const PREFERENCE_LLAMAFILE = 'ai-features.llamafile.llamafiles';
|
|
22
|
+
|
|
23
|
+
export const aiLlamafilePreferencesSchema: PreferenceSchema = {
|
|
24
|
+
type: 'object',
|
|
25
|
+
properties: {
|
|
26
|
+
[PREFERENCE_LLAMAFILE]: {
|
|
27
|
+
title: AI_LLAMAFILE_PREFERENCES_TITLE,
|
|
28
|
+
markdownDescription: 'This setting allows you to configure and manage LlamaFile models in Theia IDE.\
|
|
29
|
+
\n\
|
|
30
|
+
Each entry requires a user-friendly `name`, the file `uri` pointing to your LlamaFile, and the `port` on which it will run.\
|
|
31
|
+
\n\
|
|
32
|
+
To start a LlamaFile, use the "Start LlamaFile" command, which enables you to select the desired model.\
|
|
33
|
+
\n\
|
|
34
|
+
If you edit an entry (e.g., change the port), any running instance will stop, and you will need to manually start it again.\
|
|
35
|
+
\n\
|
|
36
|
+
[Learn more about configuring and managing LlamaFiles in the Theia IDE documentation](https://theia-ide.org/docs/user_ai/#llamafile-models).',
|
|
37
|
+
type: 'array',
|
|
38
|
+
default: [],
|
|
39
|
+
items: {
|
|
40
|
+
type: 'object',
|
|
41
|
+
properties: {
|
|
42
|
+
name: {
|
|
43
|
+
type: 'string',
|
|
44
|
+
description: 'The model name to use for this Llamafile.'
|
|
45
|
+
},
|
|
46
|
+
uri: {
|
|
47
|
+
type: 'string',
|
|
48
|
+
description: 'The file uri to the Llamafile.'
|
|
49
|
+
},
|
|
50
|
+
port: {
|
|
51
|
+
type: 'number',
|
|
52
|
+
description: 'The port to use to start the server.'
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export function bindAILlamafilePreferences(bind: interfaces.Bind): void {
|
|
61
|
+
bind(PreferenceContribution).toConstantValue({ schema: aiLlamafilePreferencesSchema });
|
|
62
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
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 { LanguageModel, LanguageModelRequest, LanguageModelResponse, LanguageModelStreamResponsePart } from '@theia/ai-core';
|
|
18
|
+
import { CancellationToken } from '@theia/core';
|
|
19
|
+
export class LlamafileLanguageModel implements LanguageModel {
|
|
20
|
+
|
|
21
|
+
readonly providerId = 'llamafile';
|
|
22
|
+
readonly vendor: string = 'Mozilla';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param name the unique name for this language model. It will be used to identify the model in the UI.
|
|
26
|
+
* @param uri the URI pointing to the Llamafile model location.
|
|
27
|
+
* @param port the port on which the Llamafile model server operates.
|
|
28
|
+
* @param defaultRequestSettings optional default settings for requests made using this model.
|
|
29
|
+
*/
|
|
30
|
+
constructor(
|
|
31
|
+
public readonly name: string,
|
|
32
|
+
public readonly uri: string,
|
|
33
|
+
public readonly port: number,
|
|
34
|
+
public defaultRequestSettings?: { [key: string]: unknown }
|
|
35
|
+
) { }
|
|
36
|
+
|
|
37
|
+
get id(): string {
|
|
38
|
+
return this.name;
|
|
39
|
+
}
|
|
40
|
+
protected getSettings(request: LanguageModelRequest): Record<string, unknown> {
|
|
41
|
+
const settings = request.settings ? request.settings : this.defaultRequestSettings;
|
|
42
|
+
if (!settings) {
|
|
43
|
+
return {
|
|
44
|
+
n_predict: 200,
|
|
45
|
+
stream: true,
|
|
46
|
+
stop: ['</s>', 'Llama:', 'User:', '<|eot_id|>'],
|
|
47
|
+
cache_prompt: true,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return settings;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async request(request: LanguageModelRequest, cancellationToken?: CancellationToken): Promise<LanguageModelResponse> {
|
|
54
|
+
const settings = this.getSettings(request);
|
|
55
|
+
try {
|
|
56
|
+
let prompt = request.messages.map(message => {
|
|
57
|
+
switch (message.actor) {
|
|
58
|
+
case 'user':
|
|
59
|
+
return `User: ${message.query}`;
|
|
60
|
+
case 'ai':
|
|
61
|
+
return `Llama: ${message.query}`;
|
|
62
|
+
case 'system':
|
|
63
|
+
return `${message.query.replace(/\n\n/g, '\n')}`;
|
|
64
|
+
}
|
|
65
|
+
}).join('\n');
|
|
66
|
+
prompt += '\nLlama:';
|
|
67
|
+
const response = await fetch(`http://localhost:${this.port}/completion`, {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
headers: {
|
|
70
|
+
'Content-Type': 'application/json',
|
|
71
|
+
},
|
|
72
|
+
body: JSON.stringify({
|
|
73
|
+
prompt: prompt,
|
|
74
|
+
...settings
|
|
75
|
+
}),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (!response.ok) {
|
|
79
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!response.body) {
|
|
83
|
+
throw new Error('Response body is undefined');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const reader = response.body.getReader();
|
|
87
|
+
const decoder = new TextDecoder();
|
|
88
|
+
return {
|
|
89
|
+
stream: {
|
|
90
|
+
[Symbol.asyncIterator](): AsyncIterator<LanguageModelStreamResponsePart> {
|
|
91
|
+
return {
|
|
92
|
+
async next(): Promise<IteratorResult<LanguageModelStreamResponsePart>> {
|
|
93
|
+
if (cancellationToken?.isCancellationRequested) {
|
|
94
|
+
reader.cancel();
|
|
95
|
+
return { value: undefined, done: true };
|
|
96
|
+
}
|
|
97
|
+
const { value, done } = await reader.read();
|
|
98
|
+
if (done) {
|
|
99
|
+
return { value: undefined, done: true };
|
|
100
|
+
}
|
|
101
|
+
const read = decoder.decode(value, { stream: true });
|
|
102
|
+
const chunk = read.split('\n').filter(l => l.length !== 0).reduce((acc, line) => {
|
|
103
|
+
try {
|
|
104
|
+
const parsed = JSON.parse(line.substring(6));
|
|
105
|
+
acc += parsed.content;
|
|
106
|
+
return acc;
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error('Error parsing JSON:', error);
|
|
109
|
+
return acc;
|
|
110
|
+
}
|
|
111
|
+
}, '');
|
|
112
|
+
return { value: { content: chunk }, done: false };
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
} catch (error) {
|
|
119
|
+
console.error('Error:', error);
|
|
120
|
+
return {
|
|
121
|
+
text: `Error: ${error}`
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 LlamafileModelDescription {
|
|
21
|
+
name: string;
|
|
22
|
+
uri: string;
|
|
23
|
+
port: number;
|
|
24
|
+
/**
|
|
25
|
+
* Default request settings for the Llama model.
|
|
26
|
+
*/
|
|
27
|
+
defaultRequestSettings?: { [key: string]: unknown };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface LlamafileManager {
|
|
31
|
+
startServer(name: string): Promise<void>;
|
|
32
|
+
stopServer(name: string): void;
|
|
33
|
+
getStartedLlamafiles(): Promise<string[]>;
|
|
34
|
+
setClient(client: LlamafileServerManagerClient): void;
|
|
35
|
+
addLanguageModels(llamaFiles: LlamafileModelDescription[]): Promise<void>;
|
|
36
|
+
removeLanguageModels(modelIds: string[]): void;
|
|
37
|
+
updateRequestSettings(modelId: string, requestSettings?: { [key: string]: unknown }): void;
|
|
38
|
+
}
|
|
39
|
+
export interface LlamafileServerManagerClient {
|
|
40
|
+
log(llamafileName: string, message: string): void;
|
|
41
|
+
error(llamafileName: string, message: string): void;
|
|
42
|
+
}
|
|
@@ -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,129 @@
|
|
|
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 { LlamafileManager, LlamafileModelDescription, 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(LlamafileModelDescriptions: LlamafileModelDescription[]): Promise<void> {
|
|
34
|
+
for (const llamafile of LlamafileModelDescriptions) {
|
|
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 a 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([
|
|
46
|
+
new LlamafileLanguageModel(
|
|
47
|
+
llamafile.name,
|
|
48
|
+
llamafile.uri,
|
|
49
|
+
llamafile.port,
|
|
50
|
+
llamafile.defaultRequestSettings
|
|
51
|
+
)
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async updateRequestSettings(modelId: string, requestSettings?: { [key: string]: unknown; }): Promise<void> {
|
|
58
|
+
const model = await this.languageModelRegistry.getLanguageModel(modelId);
|
|
59
|
+
if (model) {
|
|
60
|
+
if (!(model instanceof LlamafileLanguageModel)) {
|
|
61
|
+
console.warn(`Llamafile: model ${model.id} is not a Llamafile model`);
|
|
62
|
+
return;
|
|
63
|
+
} else {
|
|
64
|
+
model.defaultRequestSettings = requestSettings;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
removeLanguageModels(modelIds: string[]): void {
|
|
70
|
+
modelIds.filter(modelId => this.isStarted(modelId)).forEach(modelId => this.stopServer(modelId));
|
|
71
|
+
this.languageModelRegistry.removeLanguageModels(modelIds);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async getStartedLlamafiles(): Promise<string[]> {
|
|
75
|
+
const models = await this.languageModelRegistry.getLanguageModels();
|
|
76
|
+
return models.filter(model => model instanceof LlamafileLanguageModel && this.isStarted(model.name)).map(model => model.id);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async startServer(name: string): Promise<void> {
|
|
80
|
+
if (!this.processMap.has(name)) {
|
|
81
|
+
const models = await this.languageModelRegistry.getLanguageModels();
|
|
82
|
+
const llm = models.find(model => model.id === name && model instanceof LlamafileLanguageModel) as LlamafileLanguageModel | undefined;
|
|
83
|
+
if (llm === undefined) {
|
|
84
|
+
return Promise.reject(`Llamafile ${name} not found`);
|
|
85
|
+
}
|
|
86
|
+
const filePath = fileURLToPath(llm.uri);
|
|
87
|
+
|
|
88
|
+
// Extract the directory and file name
|
|
89
|
+
const dir = dirname(filePath);
|
|
90
|
+
const fileName = basename(filePath);
|
|
91
|
+
const currentProcess = spawn(`./${fileName}`, ['--port', '' + llm.port, '--server', '--nobrowser'], { cwd: dir });
|
|
92
|
+
this.processMap.set(name, currentProcess);
|
|
93
|
+
|
|
94
|
+
currentProcess.stdout.on('data', (data: Buffer) => {
|
|
95
|
+
const output = data.toString();
|
|
96
|
+
this.client.log(name, output);
|
|
97
|
+
});
|
|
98
|
+
currentProcess.stderr.on('data', (data: Buffer) => {
|
|
99
|
+
const output = data.toString();
|
|
100
|
+
this.client.error(name, output);
|
|
101
|
+
});
|
|
102
|
+
currentProcess.on('close', code => {
|
|
103
|
+
this.client.log(name, `LlamaFile process for file ${name} exited with code ${code}`);
|
|
104
|
+
this.processMap.delete(name);
|
|
105
|
+
});
|
|
106
|
+
currentProcess.on('error', error => {
|
|
107
|
+
this.client.error(name, `Error starting LlamaFile process for file ${name}: ${error.message}`);
|
|
108
|
+
this.processMap.delete(name);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
stopServer(name: string): void {
|
|
114
|
+
if (this.processMap.has(name)) {
|
|
115
|
+
const currentProcess = this.processMap.get(name);
|
|
116
|
+
currentProcess!.kill();
|
|
117
|
+
this.processMap.delete(name);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
isStarted(name: string): boolean {
|
|
122
|
+
return this.processMap.has(name);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
setClient(client: LlamafileServerManagerClient): void {
|
|
126
|
+
this.client = client;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
}
|
|
@@ -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
|
+
});
|