Skip to content

feat: Adding Attach button #118

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions schema/chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
"title": "AI persona name",
"description": "The name of the AI persona",
"default": "Jupyternaut"
},
"enableFileAttachment": {
"type": "boolean",
"title": "Enable file attachment support",
"default": false,
"description": "This allow you to sending attached files along with your message. ⚠️ This may send large content to the LLM, consuming many tokens."
}
},
"additionalProperties": false
Expand Down
6 changes: 3 additions & 3 deletions src/chat-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export const welcomeMessage = (providers: string[]) => `
#### Ask JupyterLite AI


The provider to use can be set in the <button data-commandLinker-command="settingeditor:open" data-commandLinker-args='{"query": "AI provider"}' href="#">settings editor</button>, by selecting it from
the <img src="${AI_AVATAR}" width="16" height="16"> _AI provider_ settings.
The provider to use can be set in the <button data-commandLinker-command="settingeditor:open" data-commandLinker-args='{"query": "AI providers"}' href="#">settings editor</button>, by selecting it from
the <img src="${AI_AVATAR}" width="16" height="16"> _AI providers_ settings.

The current providers that are available are _${providers.sort().join('_, _')}_.

To clear the chat, you can use the \`/clear\` command from the chat input.
- To clear the chat, you can use the \`/clear\` command from the chat input.
`;

export type ConnectionMessage = {
Expand Down
26 changes: 20 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { IFormRendererRegistry } from '@jupyterlab/ui-components';
import { ReadonlyPartialJSONObject } from '@lumino/coreutils';
import { ISecretsManager, SecretsManager } from 'jupyter-secrets-manager';
import { IDocumentManager } from '@jupyterlab/docmanager';

import { ChatHandler, welcomeMessage } from './chat-handler';
import { CompletionProvider } from './completion-provider';
Expand Down Expand Up @@ -50,7 +51,8 @@ const chatPlugin: JupyterFrontEndPlugin<void> = {
INotebookTracker,
ISettingRegistry,
IThemeManager,
ILayoutRestorer
ILayoutRestorer,
IDocumentManager
],
activate: async (
app: JupyterFrontEnd,
Expand All @@ -60,7 +62,8 @@ const chatPlugin: JupyterFrontEndPlugin<void> = {
notebookTracker: INotebookTracker | null,
settingsRegistry: ISettingRegistry | null,
themeManager: IThemeManager | null,
restorer: ILayoutRestorer | null
restorer: ILayoutRestorer | null,
docManager: IDocumentManager | null
) => {
let activeCellManager: IActiveCellManager | null = null;
if (notebookTracker) {
Expand All @@ -72,22 +75,33 @@ const chatPlugin: JupyterFrontEndPlugin<void> = {

const chatHandler = new ChatHandler({
providerRegistry,
activeCellManager
activeCellManager,
documentManager: docManager ?? undefined
});

let sendWithShiftEnter = false;
let enableCodeToolbar = true;
let enableFileAttachment = false;
let personaName = 'AI';

function loadSetting(setting: ISettingRegistry.ISettings): void {
sendWithShiftEnter = setting.get('sendWithShiftEnter')
.composite as boolean;
enableCodeToolbar = setting.get('enableCodeToolbar').composite as boolean;
personaName = setting.get('personaName').composite as string;
?.composite as boolean;
enableCodeToolbar = setting.get('enableCodeToolbar')
?.composite as boolean;
personaName = setting.get('personaName')?.composite as string;
enableFileAttachment = setting.get('enableFileAttachment')
?.composite as boolean;

// set the properties
chatHandler.config = { sendWithShiftEnter, enableCodeToolbar };
chatHandler.personaName = personaName;

if (enableFileAttachment) {
inputToolbarRegistry.show('attach');
} else {
inputToolbarRegistry.hide('attach');
}
}

Promise.all([app.restored, settingsRegistry?.load(chatPlugin.id)])
Expand Down
Loading