-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed #14411 Signed-off-by: Jonas Helming <[email protected]>
- Loading branch information
1 parent
72b700d
commit 6bfaa2d
Showing
17 changed files
with
563 additions
and
0 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
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,32 @@ | ||
<div align='center'> | ||
|
||
<br /> | ||
|
||
<img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' /> | ||
|
||
<h2>ECLIPSE THEIA - Hugging Face AI EXTENSION</h2> | ||
|
||
<hr /> | ||
|
||
</div> | ||
|
||
## Description | ||
|
||
The `@theia/ai-huggingface` integrates Hugging Face's models with Theia AI. | ||
The Hugging Face API key and the models to use can be configured via preferences. | ||
Alternatively, the Hugging Face API key can also be provided via the `HUGGINGFACE_API_KEY` environment variable. | ||
|
||
## Additional Information | ||
|
||
- [Theia - GitHub](https://github.com/eclipse-theia/theia) | ||
- [Theia - Website](https://theia-ide.org/) | ||
|
||
## License | ||
|
||
- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/) | ||
- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp) | ||
|
||
## Trademark | ||
|
||
"Theia" is a trademark of the Eclipse Foundation | ||
https://www.eclipse.org/theia |
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,49 @@ | ||
{ | ||
"name": "@theia/ai-huggingface", | ||
"version": "1.55.0", | ||
"description": "Theia - Hugging Face Integration", | ||
"dependencies": { | ||
"@theia/core": "1.55.0", | ||
"@huggingface/inference": "^2.0.0", | ||
"@theia/ai-core": "1.55.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"theiaExtensions": [ | ||
{ | ||
"frontend": "lib/browser/huggingface-frontend-module", | ||
"backend": "lib/node/huggingface-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.55.0" | ||
}, | ||
"nyc": { | ||
"extends": "../../configs/nyc.json" | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
packages/ai-hugging-face/src/browser/huggingface-frontend-application-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,66 @@ | ||
// ***************************************************************************** | ||
// 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 { FrontendApplicationContribution, PreferenceService } from '@theia/core/lib/browser'; | ||
import { inject, injectable } from '@theia/core/shared/inversify'; | ||
import { HuggingFaceLanguageModelsManager, HuggingFaceModelDescription } from '../common'; | ||
import { API_KEY_PREF, MODELS_PREF } from './huggingface-preferences'; | ||
|
||
@injectable() | ||
export class HuggingFaceFrontendApplicationContribution implements FrontendApplicationContribution { | ||
|
||
@inject(PreferenceService) | ||
protected preferenceService: PreferenceService; | ||
|
||
@inject(HuggingFaceLanguageModelsManager) | ||
protected manager: HuggingFaceLanguageModelsManager; | ||
|
||
protected prevModels: string[] = []; | ||
|
||
onStart(): void { | ||
this.preferenceService.ready.then(() => { | ||
const apiKey = this.preferenceService.get<string>(API_KEY_PREF, undefined); | ||
this.manager.setApiKey(apiKey); | ||
|
||
const models = this.preferenceService.get<string[]>(MODELS_PREF, []); | ||
this.manager.createOrUpdateLanguageModels(...models.map(createHuggingFaceModelDescription)); | ||
this.prevModels = [...models]; | ||
|
||
this.preferenceService.onPreferenceChanged(event => { | ||
if (event.preferenceName === API_KEY_PREF) { | ||
this.manager.setApiKey(event.newValue); | ||
} else if (event.preferenceName === MODELS_PREF) { | ||
const oldModels = new Set(this.prevModels); | ||
const newModels = new Set(event.newValue as string[]); | ||
|
||
const modelsToRemove = [...oldModels].filter(model => !newModels.has(model)); | ||
const modelsToAdd = [...newModels].filter(model => !oldModels.has(model)); | ||
|
||
this.manager.removeLanguageModels(...modelsToRemove.map(model => `huggingface/${model}`)); | ||
this.manager.createOrUpdateLanguageModels(...modelsToAdd.map(createHuggingFaceModelDescription)); | ||
this.prevModels = [...event.newValue]; | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
function createHuggingFaceModelDescription(modelId: string): HuggingFaceModelDescription { | ||
return { | ||
id: `huggingface/${modelId}`, | ||
model: modelId | ||
}; | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/ai-hugging-face/src/browser/huggingface-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,31 @@ | ||
// ***************************************************************************** | ||
// 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 { ContainerModule } from '@theia/core/shared/inversify'; | ||
import { HuggingFacePreferencesSchema } from './huggingface-preferences'; | ||
import { FrontendApplicationContribution, PreferenceContribution, RemoteConnectionProvider, ServiceConnectionProvider } from '@theia/core/lib/browser'; | ||
import { HuggingFaceFrontendApplicationContribution } from './huggingface-frontend-application-contribution'; | ||
import { HUGGINGFACE_LANGUAGE_MODELS_MANAGER_PATH, HuggingFaceLanguageModelsManager } from '../common'; | ||
|
||
export default new ContainerModule(bind => { | ||
bind(PreferenceContribution).toConstantValue({ schema: HuggingFacePreferencesSchema }); | ||
bind(HuggingFaceFrontendApplicationContribution).toSelf().inSingletonScope(); | ||
bind(FrontendApplicationContribution).toService(HuggingFaceFrontendApplicationContribution); | ||
bind(HuggingFaceLanguageModelsManager).toDynamicValue(ctx => { | ||
const provider = ctx.container.get<ServiceConnectionProvider>(RemoteConnectionProvider); | ||
return provider.createProxy<HuggingFaceLanguageModelsManager>(HUGGINGFACE_LANGUAGE_MODELS_MANAGER_PATH); | ||
}).inSingletonScope(); | ||
}); |
42 changes: 42 additions & 0 deletions
42
packages/ai-hugging-face/src/browser/huggingface-preferences.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,42 @@ | ||
// ***************************************************************************** | ||
// 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 { PreferenceSchema } from '@theia/core/lib/browser/preferences/preference-contribution'; | ||
import { AI_CORE_PREFERENCES_TITLE } from '@theia/ai-core/lib/browser/ai-core-preferences'; | ||
|
||
export const API_KEY_PREF = 'ai-features.huggingFace.apiKey'; | ||
export const MODELS_PREF = 'ai-features.huggingFace.models'; | ||
|
||
export const HuggingFacePreferencesSchema: PreferenceSchema = { | ||
type: 'object', | ||
properties: { | ||
[API_KEY_PREF]: { | ||
type: 'string', | ||
markdownDescription: 'Enter an API Key for your Hugging Face Account. **Please note:** By using this preference the Hugging Face API key will be stored in clear text\ | ||
on the machine running Theia. Use the environment variable `HUGGINGFACE_API_KEY` to set the key securely.', | ||
title: AI_CORE_PREFERENCES_TITLE, | ||
}, | ||
[MODELS_PREF]: { | ||
type: 'array', | ||
description: 'Hugging Face models to use', | ||
title: AI_CORE_PREFERENCES_TITLE, | ||
default: ['bigcode/starcoder'], | ||
items: { | ||
type: 'string' | ||
} | ||
} | ||
} | ||
}; |
36 changes: 36 additions & 0 deletions
36
packages/ai-hugging-face/src/common/huggingface-language-models-manager.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,36 @@ | ||
// ***************************************************************************** | ||
// 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 | ||
// ***************************************************************************** | ||
|
||
export const HUGGINGFACE_LANGUAGE_MODELS_MANAGER_PATH = '/services/huggingface/language-model-manager'; | ||
export const HuggingFaceLanguageModelsManager = Symbol('HuggingFaceLanguageModelsManager'); | ||
|
||
export interface HuggingFaceModelDescription { | ||
/** | ||
* The identifier of the model which will be shown in the UI. | ||
*/ | ||
id: string; | ||
/** | ||
* The model ID as used by the Hugging Face API. | ||
*/ | ||
model: string; | ||
} | ||
|
||
export interface HuggingFaceLanguageModelsManager { | ||
apiKey: string | undefined; | ||
setApiKey(key: string | undefined): void; | ||
createOrUpdateLanguageModels(...models: HuggingFaceModelDescription[]): Promise<void>; | ||
removeLanguageModels(...modelIds: string[]): void; | ||
} |
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,16 @@ | ||
// ***************************************************************************** | ||
// 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 | ||
// ***************************************************************************** | ||
export * from './huggingface-language-models-manager'; |
30 changes: 30 additions & 0 deletions
30
packages/ai-hugging-face/src/node/huggingface-backend-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,30 @@ | ||
// ***************************************************************************** | ||
// 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 { ContainerModule } from '@theia/core/shared/inversify'; | ||
import { HUGGINGFACE_LANGUAGE_MODELS_MANAGER_PATH, HuggingFaceLanguageModelsManager } from '../common/huggingface-language-models-manager'; | ||
import { ConnectionHandler, RpcConnectionHandler } from '@theia/core'; | ||
import { HuggingFaceLanguageModelsManagerImpl } from './huggingface-language-models-manager-impl'; | ||
|
||
export const HuggingFaceModelFactory = Symbol('HuggingFaceModelFactory'); | ||
|
||
export default new ContainerModule(bind => { | ||
bind(HuggingFaceLanguageModelsManagerImpl).toSelf().inSingletonScope(); | ||
bind(HuggingFaceLanguageModelsManager).toService(HuggingFaceLanguageModelsManagerImpl); | ||
bind(ConnectionHandler).toDynamicValue(ctx => | ||
new RpcConnectionHandler(HUGGINGFACE_LANGUAGE_MODELS_MANAGER_PATH, () => ctx.container.get(HuggingFaceLanguageModelsManager)) | ||
).inSingletonScope(); | ||
}); |
Oops, something went wrong.