Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update @jupyter/chat to 0.5.0 #7

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@
"watch:labextension": "jupyter labextension watch ."
},
"dependencies": {
"@jupyter/chat": "^0.1.0",
"@jupyterlab/application": "^4.0.0",
"@jupyterlab/apputils": "^4.0.0",
"@jupyterlab/completer": "^4.0.0",
"@jupyterlab/settingregistry": "^4.0.0",
"@jupyter/chat": "^0.5.0",
"@jupyterlab/application": "^4.2.0",
"@jupyterlab/apputils": "^4.3.0",
"@jupyterlab/completer": "^4.2.0",
"@jupyterlab/notebook": "^4.2.0",
"@jupyterlab/rendermime": "^4.2.0",
"@jupyterlab/settingregistry": "^4.2.0",
"@lumino/coreutils": "^2.1.2",
"@lumino/polling": "^2.1.2",
"@mistralai/mistralai": "^0.5.0"
Expand Down
6 changes: 6 additions & 0 deletions schema/chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"type": "boolean",
"default": false,
"readOnly": false
},
"enableCodeToolbar": {
"description": "Whether to enable or not the code toolbar.",
"type": "boolean",
"default": true,
"readOnly": false
}
},
"additionalProperties": false
Expand Down
8 changes: 4 additions & 4 deletions src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ export class CodestralHandler extends ChatModel {
this._mistralClient = options.mistralClient;
}

async addMessage(message: INewMessage): Promise<boolean> {
async sendMessage(message: INewMessage): Promise<boolean> {
message.id = UUID.uuid4();
const msg: IChatMessage = {
id: message.id,
body: message.body,
sender: 'User',
sender: { username: 'User' },
time: Date.now(),
type: 'msg'
};
Expand All @@ -38,7 +38,7 @@ export class CodestralHandler extends ChatModel {
model: 'codestral-latest',
messages: this._history.messages.map(msg => {
return {
role: msg.sender === 'User' ? 'user' : 'assistant',
role: msg.sender.username === 'User' ? 'user' : 'assistant',
content: msg.body
};
})
Expand All @@ -50,7 +50,7 @@ export class CodestralHandler extends ChatModel {
const botMsg: IChatMessage = {
id: UUID.uuid4(),
body: botMessage.content as string,
sender: 'Codestral',
sender: { username: 'Codestral' },
time: Date.now(),
type: 'msg'
};
Expand Down
40 changes: 31 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import {
ActiveCellManager,
buildChatSidebar,
buildErrorWidget,
IActiveCellManager
} from '@jupyter/chat';
import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { ReactWidget, IThemeManager } from '@jupyterlab/apputils';
import { ICompletionProviderManager } from '@jupyterlab/completer';
import { INotebookTracker } from '@jupyterlab/notebook';
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { CodestralProvider } from './provider';

import { buildChatSidebar, buildErrorWidget } from '@jupyter/chat';
import { ReactWidget, IThemeManager } from '@jupyterlab/apputils';
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';

import MistralClient from '@mistralai/mistralai';

import { CodestralHandler } from './handler';
Expand Down Expand Up @@ -52,22 +56,36 @@ const chatPlugin: JupyterFrontEndPlugin<void> = {
id: 'jupyterlab-codestral:chat',
description: 'Codestral chat extension',
autoStart: true,
optional: [ISettingRegistry, IThemeManager],
optional: [INotebookTracker, ISettingRegistry, IThemeManager],
requires: [IRenderMimeRegistry],
activate: async (
app: JupyterFrontEnd,
rmRegistry: IRenderMimeRegistry,
notebookTracker: INotebookTracker | null,
settingsRegistry: ISettingRegistry | null,
themeManager: IThemeManager | null
) => {
const chatHandler = new CodestralHandler({ mistralClient });
let activeCellManager: IActiveCellManager | null = null;
if (notebookTracker) {
activeCellManager = new ActiveCellManager({
tracker: notebookTracker,
shell: app.shell
});
}

const chatHandler = new CodestralHandler({
mistralClient,
activeCellManager: activeCellManager
});

let sendWithShiftEnter = false;
let enableCodeToolbar = true;

function loadSetting(setting: ISettingRegistry.ISettings): void {
sendWithShiftEnter = setting.get('sendWithShiftEnter')
.composite as boolean;
chatHandler.config = { sendWithShiftEnter };
enableCodeToolbar = setting.get('enableCodeToolbar').composite as boolean;
chatHandler.config = { sendWithShiftEnter, enableCodeToolbar };
}

Promise.all([app.restored, settingsRegistry?.load(chatPlugin.id)])
Expand All @@ -89,7 +107,11 @@ const chatPlugin: JupyterFrontEndPlugin<void> = {

let chatWidget: ReactWidget | null = null;
try {
chatWidget = buildChatSidebar(chatHandler, themeManager, rmRegistry);
chatWidget = buildChatSidebar({
model: chatHandler,
themeManager,
rmRegistry
});
chatWidget.title.caption = 'Codestral Chat';
} catch (e) {
chatWidget = buildErrorWidget(themeManager);
Expand Down
2 changes: 2 additions & 0 deletions style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

https://jupyterlab.readthedocs.io/en/stable/developer/css.html
*/

@import url('@jupyter/chat/style/index.css');
Loading
Loading