Skip to content

Commit 0eb6e11

Browse files
authored
Update @jupyter/chat to 0.5.0 (#7)
* Update @jupyter/chat to 0.5.0 * Add the code cell * lint * Import styles from jupyter-chat
1 parent e2c2386 commit 0eb6e11

File tree

6 files changed

+603
-176
lines changed

6 files changed

+603
-176
lines changed

package.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@
5353
"watch:labextension": "jupyter labextension watch ."
5454
},
5555
"dependencies": {
56-
"@jupyter/chat": "^0.1.0",
57-
"@jupyterlab/application": "^4.0.0",
58-
"@jupyterlab/apputils": "^4.0.0",
59-
"@jupyterlab/completer": "^4.0.0",
60-
"@jupyterlab/settingregistry": "^4.0.0",
56+
"@jupyter/chat": "^0.5.0",
57+
"@jupyterlab/application": "^4.2.0",
58+
"@jupyterlab/apputils": "^4.3.0",
59+
"@jupyterlab/completer": "^4.2.0",
60+
"@jupyterlab/notebook": "^4.2.0",
61+
"@jupyterlab/rendermime": "^4.2.0",
62+
"@jupyterlab/settingregistry": "^4.2.0",
6163
"@lumino/coreutils": "^2.1.2",
6264
"@lumino/polling": "^2.1.2",
6365
"@mistralai/mistralai": "^0.5.0"

schema/chat.json

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
"type": "boolean",
99
"default": false,
1010
"readOnly": false
11+
},
12+
"enableCodeToolbar": {
13+
"description": "Whether to enable or not the code toolbar.",
14+
"type": "boolean",
15+
"default": true,
16+
"readOnly": false
1117
}
1218
},
1319
"additionalProperties": false

src/handler.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ export class CodestralHandler extends ChatModel {
2323
this._mistralClient = options.mistralClient;
2424
}
2525

26-
async addMessage(message: INewMessage): Promise<boolean> {
26+
async sendMessage(message: INewMessage): Promise<boolean> {
2727
message.id = UUID.uuid4();
2828
const msg: IChatMessage = {
2929
id: message.id,
3030
body: message.body,
31-
sender: 'User',
31+
sender: { username: 'User' },
3232
time: Date.now(),
3333
type: 'msg'
3434
};
@@ -38,7 +38,7 @@ export class CodestralHandler extends ChatModel {
3838
model: 'codestral-latest',
3939
messages: this._history.messages.map(msg => {
4040
return {
41-
role: msg.sender === 'User' ? 'user' : 'assistant',
41+
role: msg.sender.username === 'User' ? 'user' : 'assistant',
4242
content: msg.body
4343
};
4444
})
@@ -50,7 +50,7 @@ export class CodestralHandler extends ChatModel {
5050
const botMsg: IChatMessage = {
5151
id: UUID.uuid4(),
5252
body: botMessage.content as string,
53-
sender: 'Codestral',
53+
sender: { username: 'Codestral' },
5454
time: Date.now(),
5555
type: 'msg'
5656
};

src/index.ts

+31-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1+
import {
2+
ActiveCellManager,
3+
buildChatSidebar,
4+
buildErrorWidget,
5+
IActiveCellManager
6+
} from '@jupyter/chat';
17
import {
28
JupyterFrontEnd,
39
JupyterFrontEndPlugin
410
} from '@jupyterlab/application';
11+
import { ReactWidget, IThemeManager } from '@jupyterlab/apputils';
512
import { ICompletionProviderManager } from '@jupyterlab/completer';
13+
import { INotebookTracker } from '@jupyterlab/notebook';
14+
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
615
import { ISettingRegistry } from '@jupyterlab/settingregistry';
716
import { CodestralProvider } from './provider';
8-
9-
import { buildChatSidebar, buildErrorWidget } from '@jupyter/chat';
10-
import { ReactWidget, IThemeManager } from '@jupyterlab/apputils';
11-
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
12-
1317
import MistralClient from '@mistralai/mistralai';
1418

1519
import { CodestralHandler } from './handler';
@@ -52,22 +56,36 @@ const chatPlugin: JupyterFrontEndPlugin<void> = {
5256
id: 'jupyterlab-codestral:chat',
5357
description: 'Codestral chat extension',
5458
autoStart: true,
55-
optional: [ISettingRegistry, IThemeManager],
59+
optional: [INotebookTracker, ISettingRegistry, IThemeManager],
5660
requires: [IRenderMimeRegistry],
5761
activate: async (
5862
app: JupyterFrontEnd,
5963
rmRegistry: IRenderMimeRegistry,
64+
notebookTracker: INotebookTracker | null,
6065
settingsRegistry: ISettingRegistry | null,
6166
themeManager: IThemeManager | null
6267
) => {
63-
const chatHandler = new CodestralHandler({ mistralClient });
68+
let activeCellManager: IActiveCellManager | null = null;
69+
if (notebookTracker) {
70+
activeCellManager = new ActiveCellManager({
71+
tracker: notebookTracker,
72+
shell: app.shell
73+
});
74+
}
75+
76+
const chatHandler = new CodestralHandler({
77+
mistralClient,
78+
activeCellManager: activeCellManager
79+
});
6480

6581
let sendWithShiftEnter = false;
82+
let enableCodeToolbar = true;
6683

6784
function loadSetting(setting: ISettingRegistry.ISettings): void {
6885
sendWithShiftEnter = setting.get('sendWithShiftEnter')
6986
.composite as boolean;
70-
chatHandler.config = { sendWithShiftEnter };
87+
enableCodeToolbar = setting.get('enableCodeToolbar').composite as boolean;
88+
chatHandler.config = { sendWithShiftEnter, enableCodeToolbar };
7189
}
7290

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

90108
let chatWidget: ReactWidget | null = null;
91109
try {
92-
chatWidget = buildChatSidebar(chatHandler, themeManager, rmRegistry);
110+
chatWidget = buildChatSidebar({
111+
model: chatHandler,
112+
themeManager,
113+
rmRegistry
114+
});
93115
chatWidget.title.caption = 'Codestral Chat';
94116
} catch (e) {
95117
chatWidget = buildErrorWidget(themeManager);

style/base.css

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
44
https://jupyterlab.readthedocs.io/en/stable/developer/css.html
55
*/
6+
7+
@import url('@jupyter/chat/style/index.css');

0 commit comments

Comments
 (0)