forked from eclipse-theia/theia
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a view for displaying all the configured llamafiles. Configured llamafiles can be started and killed. One llamafile can be set as active, then being used in the chat. The chat integration is currently hardcoded to use the active llamafile language model. This should be changed as soon as the chat integration has a dropdown to select the language model (#42). A follow up will be created to describe the next steps.
- Loading branch information
Showing
19 changed files
with
724 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** @type {import('eslint').Linter.Config} */ | ||
module.exports = { | ||
extends: [ | ||
'../../configs/build.eslintrc.json' | ||
], | ||
parserOptions: { | ||
tsconfigRootDir: __dirname, | ||
project: 'tsconfig.json' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# AI Llamafile integration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "@theia/ai-llamafile", | ||
"version": "1.49.0", | ||
"description": "Theia - Llamafile Integration", | ||
"dependencies": { | ||
"@theia/core": "1.49.0", | ||
"@theia/filesystem": "1.49.0", | ||
"@theia/workspace": "1.49.0", | ||
"minimatch": "^5.1.0", | ||
"tslib": "^2.6.2", | ||
"@theia/ai-core": "1.49.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"theiaExtensions": [ | ||
{ | ||
"frontend": "lib/browser/ai-llamafile-frontend-module", | ||
"backend": "lib/node/ai-llamafile-backend-module" | ||
} | ||
], | ||
"keywords": [ | ||
"theia-extension" | ||
], | ||
"license": "EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/eclipse-theia/theia.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/eclipse-theia/theia/issues" | ||
}, | ||
"homepage": "https://github.com/eclipse-theia/theia", | ||
"files": [ | ||
"lib", | ||
"src" | ||
], | ||
"scripts": { | ||
"build": "theiaext build", | ||
"clean": "theiaext clean", | ||
"compile": "theiaext compile", | ||
"lint": "theiaext lint", | ||
"test": "theiaext test", | ||
"watch": "theiaext watch" | ||
}, | ||
"devDependencies": { | ||
"@theia/ext-scripts": "1.49.0" | ||
}, | ||
"nyc": { | ||
"extends": "../../configs/nyc.json" | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
packages/ai-llamafile/src/browser/ai-llamafile-frontend-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2024 EclipseSource GmbH. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
import { CommandContribution } from '@theia/core'; | ||
import { ContainerModule } from '@theia/core/shared/inversify'; | ||
import { LlamafileCommandContribution, NewLlamafileConfigQuickInputProvider } from './llamafile-command-contribution'; | ||
import { bindViewContribution, WidgetFactory } from '@theia/core/lib/browser'; | ||
import { LlamafileViewContribution } from './llamafile-view-contribution'; | ||
import { LlamafileListWidget } from './llamafile-list-widget'; | ||
import { LlamafileServerManager, LlamafileServerManagerPath } from '../common/llamafile-server-manager'; | ||
import { RemoteConnectionProvider, ServiceConnectionProvider } from '@theia/core/lib/browser/messaging/service-connection-provider'; | ||
|
||
export default new ContainerModule(bind => { | ||
bind(NewLlamafileConfigQuickInputProvider).toSelf().inSingletonScope(); | ||
bind(LlamafileListWidget).toSelf(); | ||
bind(WidgetFactory).toDynamicValue(context => ({ | ||
id: LlamafileListWidget.ID, | ||
createWidget: () => context.container.get<LlamafileListWidget>(LlamafileListWidget), | ||
})).inSingletonScope(); | ||
bind(CommandContribution).to(LlamafileCommandContribution).inSingletonScope(); | ||
bindViewContribution(bind, LlamafileViewContribution); | ||
bind(LlamafileServerManager).toDynamicValue(ctx => { | ||
const connection = ctx.container.get<ServiceConnectionProvider>(RemoteConnectionProvider); | ||
return connection.createProxy<LlamafileServerManager>(LlamafileServerManagerPath); | ||
}); | ||
}); |
109 changes: 109 additions & 0 deletions
109
packages/ai-llamafile/src/browser/llamafile-command-contribution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2024 EclipseSource GmbH. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
import { CommandContribution, CommandRegistry } from '@theia/core'; | ||
import { inject, injectable } from '@theia/core/shared/inversify'; | ||
import { QuickInputService } from '@theia/core/lib/browser'; | ||
import { FileDialogService, OpenFileDialogProps } from '@theia/filesystem/lib/browser'; | ||
import { LlamafileListItem } from './llamafile-list-widget'; | ||
|
||
export const CREATE_LANGUAGE_MODEL = { | ||
id: 'core.keyboard.languagemodel', | ||
label: 'Create Language Model', | ||
}; | ||
|
||
export const NewLlamafileEntryInput = { | ||
id: 'llamafile.input.new.entry', | ||
label: 'New Llamafile Entry', | ||
}; | ||
|
||
@injectable() | ||
export class NewLlamafileConfigQuickInputProvider { | ||
|
||
@inject(QuickInputService) | ||
protected readonly quickInputService: QuickInputService; | ||
|
||
@inject(FileDialogService) | ||
protected readonly fileDialogService: FileDialogService; | ||
|
||
async askForNameAndPath(): Promise<LlamafileListItem> { | ||
// Get the name input | ||
const name = await this.quickInputService.input({ | ||
prompt: 'Enter a name' | ||
}); | ||
|
||
if (!name) { | ||
throw new Error('Name input was canceled.'); | ||
} | ||
|
||
// Get the path input using a file system picker | ||
const path = await this.askForPath(); | ||
|
||
if (!path) { | ||
throw new Error('Path selection was canceled.'); | ||
} | ||
|
||
const port = await this.quickInputService.input({ | ||
prompt: 'Enter a port' | ||
}); | ||
|
||
if (!port || isNaN(Number(port))) { | ||
throw new Error('Port input was canceled.'); | ||
} | ||
|
||
return { name, path, port: Number(port), started: false, active: false }; | ||
} | ||
|
||
private async askForPath(): Promise<string | undefined> { | ||
const props: OpenFileDialogProps = { | ||
title: 'Select a file', | ||
canSelectFiles: true, | ||
canSelectFolders: false, | ||
filters: { | ||
'Llamafile': ['llamafile'] | ||
}, | ||
canSelectMany: false | ||
}; | ||
|
||
const uri = await this.fileDialogService.showOpenDialog(props); | ||
|
||
if (uri) { | ||
return uri.toString(); | ||
} | ||
|
||
return undefined; | ||
} | ||
} | ||
|
||
@injectable() | ||
export class LlamafileCommandContribution implements CommandContribution { | ||
|
||
@inject(NewLlamafileConfigQuickInputProvider) | ||
protected readonly quickInputProvider: NewLlamafileConfigQuickInputProvider; | ||
|
||
registerCommands(commandRegistry: CommandRegistry): void { | ||
commandRegistry.registerCommand(NewLlamafileEntryInput, { | ||
execute: async () => { | ||
try { | ||
return await this.quickInputProvider.askForNameAndPath(); | ||
} catch (error) { | ||
console.error('Input process was canceled or failed.', error); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.