-
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.
feat: Ollama integration for Theia AI
Integrates Ollama language models into Theia via the new 'ai-ollama' package. The endpoint and models can be configured via the preferences.
- Loading branch information
Showing
21 changed files
with
696 additions
and
11 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,30 @@ | ||
<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 - Ollama EXTENSION</h2> | ||
|
||
<hr /> | ||
|
||
</div> | ||
|
||
## Description | ||
|
||
The `@theia/ai-ollama` integrates Ollama's models with Theia AI. | ||
|
||
## 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,53 @@ | ||
{ | ||
"name": "@theia/ai-ollama", | ||
"version": "1.53.0", | ||
"description": "Theia - Ollama Integration", | ||
"dependencies": { | ||
"@theia/core": "1.53.0", | ||
"@theia/filesystem": "1.53.0", | ||
"@theia/workspace": "1.53.0", | ||
"minimatch": "^5.1.0", | ||
"tslib": "^2.6.2", | ||
"ollama": "^0.5.8", | ||
"@theia/ai-core": "1.53.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"theiaExtensions": [ | ||
{ | ||
"frontend": "lib/browser/ollama-frontend-module", | ||
"backend": "lib/node/ollama-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.53.0" | ||
}, | ||
"nyc": { | ||
"extends": "../../configs/nyc.json" | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
packages/ai-ollama/src/browser/ollama-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,59 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2024 TypeFox 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 { OllamaLanguageModelsManager } from '../common'; | ||
import { HOST_PREF, MODELS_PREF } from './ollama-preferences'; | ||
|
||
@injectable() | ||
export class OllamaFrontendApplicationContribution implements FrontendApplicationContribution { | ||
|
||
@inject(PreferenceService) | ||
protected preferenceService: PreferenceService; | ||
|
||
@inject(OllamaLanguageModelsManager) | ||
protected manager: OllamaLanguageModelsManager; | ||
|
||
protected prevModels: string[] = []; | ||
|
||
onStart(): void { | ||
this.preferenceService.ready.then(() => { | ||
const host = this.preferenceService.get<string>(HOST_PREF, 'http://localhost:11434'); | ||
this.manager.setHost(host); | ||
|
||
const models = this.preferenceService.get<string[]>(MODELS_PREF, []); | ||
this.manager.createLanguageModels(...models); | ||
this.prevModels = [...models]; | ||
|
||
this.preferenceService.onPreferenceChanged(event => { | ||
if (event.preferenceName === HOST_PREF) { | ||
this.manager.setHost(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); | ||
this.manager.createLanguageModels(...modelsToAdd); | ||
this.prevModels = [...event.newValue]; | ||
} | ||
}); | ||
}); | ||
} | ||
} |
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 TypeFox 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 { OllamaPreferencesSchema } from './ollama-preferences'; | ||
import { FrontendApplicationContribution, PreferenceContribution, RemoteConnectionProvider, ServiceConnectionProvider } from '@theia/core/lib/browser'; | ||
import { OllamaFrontendApplicationContribution } from './ollama-frontend-application-contribution'; | ||
import { OLLAMA_LANGUAGE_MODELS_MANAGER_PATH, OllamaLanguageModelsManager } from '../common'; | ||
|
||
export default new ContainerModule(bind => { | ||
bind(PreferenceContribution).toConstantValue({ schema: OllamaPreferencesSchema }); | ||
bind(OllamaFrontendApplicationContribution).toSelf().inSingletonScope(); | ||
bind(FrontendApplicationContribution).toService(OllamaFrontendApplicationContribution); | ||
bind(OllamaLanguageModelsManager).toDynamicValue(ctx => { | ||
const provider = ctx.container.get<ServiceConnectionProvider>(RemoteConnectionProvider); | ||
return provider.createProxy<OllamaLanguageModelsManager>(OLLAMA_LANGUAGE_MODELS_MANAGER_PATH); | ||
}).inSingletonScope(); | ||
}); |
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,41 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2024 TypeFox 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 HOST_PREF = 'ai-features.ollama.host'; | ||
export const MODELS_PREF = 'ai-features.ollama.models'; | ||
|
||
export const OllamaPreferencesSchema: PreferenceSchema = { | ||
type: 'object', | ||
properties: { | ||
[HOST_PREF]: { | ||
type: 'string', | ||
title: AI_CORE_PREFERENCES_TITLE, | ||
description: 'Ollama Host', | ||
default: 'http://localhost:11434' | ||
}, | ||
[MODELS_PREF]: { | ||
type: 'array', | ||
title: AI_CORE_PREFERENCES_TITLE, | ||
default: ['llama3', 'gemma2'], | ||
items: { | ||
type: 'string' | ||
} | ||
} | ||
} | ||
}; |
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 TypeFox 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 './ollama-language-models-manager'; |
23 changes: 23 additions & 0 deletions
23
packages/ai-ollama/src/common/ollama-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,23 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2024 TypeFox 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 OLLAMA_LANGUAGE_MODELS_MANAGER_PATH = '/services/ollama/language-model-manager'; | ||
export const OllamaLanguageModelsManager = Symbol('OllamaLanguageModelsManager'); | ||
export interface OllamaLanguageModelsManager { | ||
host: string | undefined; | ||
setHost(host: string | undefined): void; | ||
createLanguageModels(...modelIds: string[]): 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,30 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2024 TypeFox 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 { OLLAMA_LANGUAGE_MODELS_MANAGER_PATH, OllamaLanguageModelsManager } from '../common/ollama-language-models-manager'; | ||
import { ConnectionHandler, RpcConnectionHandler } from '@theia/core'; | ||
import { OllamaLanguageModelsManagerImpl } from './ollama-language-models-manager-impl'; | ||
|
||
export const OllamaModelFactory = Symbol('OllamaModelFactory'); | ||
|
||
export default new ContainerModule(bind => { | ||
bind(OllamaLanguageModelsManagerImpl).toSelf().inSingletonScope(); | ||
bind(OllamaLanguageModelsManager).toService(OllamaLanguageModelsManagerImpl); | ||
bind(ConnectionHandler).toDynamicValue(ctx => | ||
new RpcConnectionHandler(OLLAMA_LANGUAGE_MODELS_MANAGER_PATH, () => ctx.container.get(OllamaLanguageModelsManager)) | ||
).inSingletonScope(); | ||
}); |
Oops, something went wrong.