@jupyterlite/ai 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -9
- package/lib/chat-handler.d.ts +15 -3
- package/lib/chat-handler.js +80 -28
- package/lib/completion-provider.d.ts +5 -18
- package/lib/completion-provider.js +8 -34
- package/lib/icons.d.ts +2 -0
- package/lib/icons.js +15 -0
- package/lib/index.d.ts +3 -2
- package/lib/index.js +79 -22
- package/lib/llm-models/anthropic-completer.d.ts +19 -0
- package/lib/llm-models/anthropic-completer.js +57 -0
- package/lib/llm-models/base-completer.d.ts +6 -2
- package/lib/llm-models/chrome-completer.d.ts +19 -0
- package/lib/llm-models/chrome-completer.js +67 -0
- package/lib/llm-models/codestral-completer.d.ts +9 -8
- package/lib/llm-models/codestral-completer.js +37 -54
- package/lib/llm-models/index.d.ts +3 -2
- package/lib/llm-models/index.js +42 -2
- package/lib/llm-models/openai-completer.d.ts +19 -0
- package/lib/llm-models/openai-completer.js +51 -0
- package/lib/provider.d.ts +54 -15
- package/lib/provider.js +123 -41
- package/lib/settings/instructions.d.ts +2 -0
- package/lib/settings/instructions.js +44 -0
- package/lib/settings/panel.d.ts +70 -0
- package/lib/settings/panel.js +190 -0
- package/lib/settings/schemas/_generated/Anthropic.json +70 -0
- package/lib/settings/schemas/_generated/ChromeAI.json +21 -0
- package/lib/settings/schemas/_generated/MistralAI.json +75 -0
- package/lib/settings/schemas/_generated/OpenAI.json +668 -0
- package/lib/settings/schemas/base.json +7 -0
- package/lib/settings/schemas/index.d.ts +3 -0
- package/lib/settings/schemas/index.js +11 -0
- package/lib/slash-commands.d.ts +16 -0
- package/lib/slash-commands.js +25 -0
- package/lib/tokens.d.ts +103 -0
- package/lib/tokens.js +5 -0
- package/package.json +27 -104
- package/schema/chat.json +8 -0
- package/schema/provider-registry.json +17 -0
- package/src/chat-handler.ts +103 -43
- package/src/completion-provider.ts +13 -37
- package/src/icons.ts +18 -0
- package/src/index.ts +101 -24
- package/src/llm-models/anthropic-completer.ts +75 -0
- package/src/llm-models/base-completer.ts +7 -2
- package/src/llm-models/chrome-completer.ts +88 -0
- package/src/llm-models/codestral-completer.ts +43 -69
- package/src/llm-models/index.ts +49 -2
- package/src/llm-models/openai-completer.ts +67 -0
- package/src/llm-models/svg.d.ts +9 -0
- package/src/provider.ts +138 -43
- package/src/settings/instructions.ts +48 -0
- package/src/settings/panel.tsx +257 -0
- package/src/settings/schemas/index.ts +15 -0
- package/src/slash-commands.tsx +55 -0
- package/src/tokens.ts +112 -0
- package/style/base.css +4 -0
- package/style/icons/jupyternaut-lite.svg +7 -0
- package/lib/llm-models/utils.d.ts +0 -15
- package/lib/llm-models/utils.js +0 -29
- package/lib/token.d.ts +0 -13
- package/lib/token.js +0 -2
- package/schema/ai-provider.json +0 -21
- package/src/llm-models/utils.ts +0 -41
- package/src/token.ts +0 -19
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TODO: reuse from Jupyter AI instead of copying?
|
|
3
|
+
* https://github.com/jupyterlab/jupyter-ai/blob/main/packages/jupyter-ai/src/slash-autocompletion.tsx
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Box, Typography } from '@mui/material';
|
|
7
|
+
import { AutocompleteCommand } from '@jupyter/chat';
|
|
8
|
+
|
|
9
|
+
import HideSource from '@mui/icons-material/HideSource';
|
|
10
|
+
|
|
11
|
+
import React from 'react';
|
|
12
|
+
|
|
13
|
+
const DEFAULT_SLASH_COMMAND_ICONS: Record<string, JSX.Element> = {
|
|
14
|
+
clear: <HideSource />
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type SlashCommandOption = AutocompleteCommand & {
|
|
18
|
+
id: string;
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Renders an option shown in the slash command autocomplete.
|
|
24
|
+
*/
|
|
25
|
+
export function renderSlashCommandOption(
|
|
26
|
+
optionProps: React.HTMLAttributes<HTMLLIElement>,
|
|
27
|
+
option: SlashCommandOption
|
|
28
|
+
): JSX.Element {
|
|
29
|
+
const icon =
|
|
30
|
+
option.id in DEFAULT_SLASH_COMMAND_ICONS
|
|
31
|
+
? DEFAULT_SLASH_COMMAND_ICONS[option.id]
|
|
32
|
+
: DEFAULT_SLASH_COMMAND_ICONS.unknown;
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<li {...optionProps}>
|
|
36
|
+
<Box sx={{ lineHeight: 0, marginRight: 4, opacity: 0.618 }}>{icon}</Box>
|
|
37
|
+
<Box sx={{ flexGrow: 1 }}>
|
|
38
|
+
<Typography
|
|
39
|
+
component="span"
|
|
40
|
+
sx={{
|
|
41
|
+
fontSize: 'var(--jp-ui-font-size1)'
|
|
42
|
+
}}
|
|
43
|
+
>
|
|
44
|
+
{option.label}
|
|
45
|
+
</Typography>
|
|
46
|
+
<Typography
|
|
47
|
+
component="span"
|
|
48
|
+
sx={{ opacity: 0.618, fontSize: 'var(--jp-ui-font-size0)' }}
|
|
49
|
+
>
|
|
50
|
+
{' — ' + option.description}
|
|
51
|
+
</Typography>
|
|
52
|
+
</Box>
|
|
53
|
+
</li>
|
|
54
|
+
);
|
|
55
|
+
}
|
package/src/tokens.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
+
import { ReadonlyPartialJSONObject, Token } from '@lumino/coreutils';
|
|
3
|
+
import { ISignal } from '@lumino/signaling';
|
|
4
|
+
import { JSONSchema7 } from 'json-schema';
|
|
5
|
+
|
|
6
|
+
import { IBaseCompleter } from './llm-models';
|
|
7
|
+
|
|
8
|
+
export interface IDict<T = any> {
|
|
9
|
+
[key: string]: T;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface IType<T> {
|
|
13
|
+
new (...args: any[]): T;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The provider interface.
|
|
18
|
+
*/
|
|
19
|
+
export interface IAIProvider {
|
|
20
|
+
/**
|
|
21
|
+
* The name of the provider.
|
|
22
|
+
*/
|
|
23
|
+
name: string;
|
|
24
|
+
/**
|
|
25
|
+
* The chat model class to use.
|
|
26
|
+
*/
|
|
27
|
+
chatModel?: IType<BaseChatModel>;
|
|
28
|
+
/**
|
|
29
|
+
* The completer class to use.
|
|
30
|
+
*/
|
|
31
|
+
completer?: IType<IBaseCompleter>;
|
|
32
|
+
/**
|
|
33
|
+
* the settings schema for the provider.
|
|
34
|
+
*/
|
|
35
|
+
settingsSchema?: any;
|
|
36
|
+
/**
|
|
37
|
+
* The instructions to be displayed in the settings, as helper to use the provider.
|
|
38
|
+
* A markdown renderer is used to render the instructions.
|
|
39
|
+
*/
|
|
40
|
+
instructions?: string;
|
|
41
|
+
/**
|
|
42
|
+
* A function that extract the error message from the provider API error.
|
|
43
|
+
* Default to `(error) => error.message`.
|
|
44
|
+
*/
|
|
45
|
+
errorMessage?: (error: any) => string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The provider registry interface.
|
|
50
|
+
*/
|
|
51
|
+
export interface IAIProviderRegistry {
|
|
52
|
+
/**
|
|
53
|
+
* Get the list of provider names.
|
|
54
|
+
*/
|
|
55
|
+
readonly providers: string[];
|
|
56
|
+
/**
|
|
57
|
+
* Add a new provider.
|
|
58
|
+
*/
|
|
59
|
+
add(provider: IAIProvider): void;
|
|
60
|
+
/**
|
|
61
|
+
* Get the current provider name.
|
|
62
|
+
*/
|
|
63
|
+
currentName: string;
|
|
64
|
+
/**
|
|
65
|
+
* Get the current completer of the completion provider.
|
|
66
|
+
*/
|
|
67
|
+
currentCompleter: IBaseCompleter | null;
|
|
68
|
+
/**
|
|
69
|
+
* Get the current llm chat model.
|
|
70
|
+
*/
|
|
71
|
+
currentChatModel: BaseChatModel | null;
|
|
72
|
+
/**
|
|
73
|
+
* Get the settings schema of a given provider.
|
|
74
|
+
*/
|
|
75
|
+
getSettingsSchema(provider: string): JSONSchema7;
|
|
76
|
+
/**
|
|
77
|
+
* Get the instructions of a given provider.
|
|
78
|
+
*/
|
|
79
|
+
getInstructions(provider: string): string | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Format an error message from the current provider.
|
|
82
|
+
*/
|
|
83
|
+
formatErrorMessage(error: any): string;
|
|
84
|
+
/**
|
|
85
|
+
* Set the providers (chat model and completer).
|
|
86
|
+
* Creates the providers if the name has changed, otherwise only updates their config.
|
|
87
|
+
*
|
|
88
|
+
* @param name - the name of the provider to use.
|
|
89
|
+
* @param settings - the settings for the models.
|
|
90
|
+
*/
|
|
91
|
+
setProvider(name: string, settings: ReadonlyPartialJSONObject): void;
|
|
92
|
+
/**
|
|
93
|
+
* A signal emitting when the provider or its settings has changed.
|
|
94
|
+
*/
|
|
95
|
+
readonly providerChanged: ISignal<IAIProviderRegistry, void>;
|
|
96
|
+
/**
|
|
97
|
+
* Get the current chat error;
|
|
98
|
+
*/
|
|
99
|
+
readonly chatError: string;
|
|
100
|
+
/**
|
|
101
|
+
* get the current completer error.
|
|
102
|
+
*/
|
|
103
|
+
readonly completerError: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The provider registry token.
|
|
108
|
+
*/
|
|
109
|
+
export const IAIProviderRegistry = new Token<IAIProviderRegistry>(
|
|
110
|
+
'@jupyterlite/ai:provider-registry',
|
|
111
|
+
'Provider for chat and completion LLM provider'
|
|
112
|
+
);
|
package/style/base.css
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<svg fill="none" version="1.1" viewBox="0 0 38 38" xmlns="http://www.w3.org/2000/svg">
|
|
3
|
+
<g>
|
|
4
|
+
<circle cx="19" cy="19" r="19" fill="#f7dc1e"/>
|
|
5
|
+
<path d="m19.948 6.8365c0.6344-0.21603 1.0908-0.81693 1.0908-1.5244 0-0.88916-0.7208-1.61-1.61-1.61s-1.61 0.72081-1.61 1.61c0 0.70739 0.4562 1.3082 1.0905 1.5243v1.1674h-0.5394c-6.2858 0-11.399 5.1132-11.399 11.399 0 6.2859 5.1133 11.399 11.399 11.399h1.398c6.2859 0 11.399-5.1132 11.399-11.399 0-6.2253-5.0159-11.301-11.219-11.397v-1.1687zm-1.5781 22.163h1.398c5.3669 0 9.7303-4.9787 9.7303-8.3455 0-5.3669-4.3634-9.7303-9.7303-9.7303h-1.398c-5.3668 0-9.7302 4.3634-9.7302 9.7303 0 3.3668 4.3634 8.3455 9.7302 8.3455zm14.522-5.003c0.7341 0 0.7375-0.5123 0.7422-1.2408v-1e-4c0.0012-0.1847 0.0025-0.3833 0.0158-0.591 0.0573-0.8624 0.0739-1.7008 0.0573-2.4892l-0.0033-0.119c-0.0373-1.3318-0.0436-1.5579-1.3047-1.8058l-0.1479-0.0246 0.0015 0.0495c0.0076 0.2465 0.0151 0.493 0.0151 0.739 0 1.8018-0.2712 3.5478-0.773 5.189-0.1363 0.4459 0.3433 0.8629 0.7534 0.6411l0.6436-0.3481zm-27.612 0c-0.73409 0-0.73741-0.5123-0.74215-1.2407-0.0012-0.1848-0.00249-0.3834-0.01581-0.5912-0.0573-0.8624-0.07392-1.7007-0.05731-2.4892l0.00336-0.1189c0.03721-1.3319 0.04352-1.5579 1.3047-1.8058l0.14784-0.0247-0.00151 0.0495c-0.00756 0.2465-0.01511 0.493-0.01511 0.739 0 1.8019 0.27119 3.5478 0.773 5.189 0.13634 0.4459-0.34326 0.8629-0.7534 0.6411l-0.64361-0.3481zm14.242-12.005c-4.6297 0-8.4776 2.9361-9.4584 6.7577-0.13379 0.5212 0.5513 0.6935 0.877 0.2653 1.3829-1.818 3.1418-2.153 4.7068-2.4511 2.1143-0.4027 3.8746-0.7379 3.8746-4.5719z" clip-rule="evenodd" fill="#000" fill-rule="evenodd"/>
|
|
6
|
+
</g>
|
|
7
|
+
</svg>
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
-
import { IBaseCompleter } from './base-completer';
|
|
3
|
-
import { ReadonlyPartialJSONObject } from '@lumino/coreutils';
|
|
4
|
-
/**
|
|
5
|
-
* Get an LLM completer from the name.
|
|
6
|
-
*/
|
|
7
|
-
export declare function getCompleter(name: string, settings: ReadonlyPartialJSONObject): IBaseCompleter | null;
|
|
8
|
-
/**
|
|
9
|
-
* Get an LLM chat model from the name.
|
|
10
|
-
*/
|
|
11
|
-
export declare function getChatModel(name: string, settings: ReadonlyPartialJSONObject): BaseChatModel | null;
|
|
12
|
-
/**
|
|
13
|
-
* Get the error message from provider.
|
|
14
|
-
*/
|
|
15
|
-
export declare function getErrorMessage(name: string, error: any): string;
|
package/lib/llm-models/utils.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { ChatMistralAI } from '@langchain/mistralai';
|
|
2
|
-
import { CodestralCompleter } from './codestral-completer';
|
|
3
|
-
/**
|
|
4
|
-
* Get an LLM completer from the name.
|
|
5
|
-
*/
|
|
6
|
-
export function getCompleter(name, settings) {
|
|
7
|
-
if (name === 'MistralAI') {
|
|
8
|
-
return new CodestralCompleter({ settings });
|
|
9
|
-
}
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Get an LLM chat model from the name.
|
|
14
|
-
*/
|
|
15
|
-
export function getChatModel(name, settings) {
|
|
16
|
-
if (name === 'MistralAI') {
|
|
17
|
-
return new ChatMistralAI({ ...settings });
|
|
18
|
-
}
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Get the error message from provider.
|
|
23
|
-
*/
|
|
24
|
-
export function getErrorMessage(name, error) {
|
|
25
|
-
if (name === 'MistralAI') {
|
|
26
|
-
return error.message;
|
|
27
|
-
}
|
|
28
|
-
return 'Unknown provider';
|
|
29
|
-
}
|
package/lib/token.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
-
import { Token } from '@lumino/coreutils';
|
|
3
|
-
import { ISignal } from '@lumino/signaling';
|
|
4
|
-
import { IBaseCompleter } from './llm-models';
|
|
5
|
-
export interface IAIProvider {
|
|
6
|
-
name: string;
|
|
7
|
-
completer: IBaseCompleter | null;
|
|
8
|
-
chatModel: BaseChatModel | null;
|
|
9
|
-
modelChange: ISignal<IAIProvider, void>;
|
|
10
|
-
chatError: string;
|
|
11
|
-
completerError: string;
|
|
12
|
-
}
|
|
13
|
-
export declare const IAIProvider: Token<IAIProvider>;
|
package/lib/token.js
DELETED
package/schema/ai-provider.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"title": "AI provider",
|
|
3
|
-
"description": "Provider settings",
|
|
4
|
-
"type": "object",
|
|
5
|
-
"properties": {
|
|
6
|
-
"provider": {
|
|
7
|
-
"type": "string",
|
|
8
|
-
"title": "The AI provider",
|
|
9
|
-
"description": "The AI provider to use for chat and completion",
|
|
10
|
-
"default": "None",
|
|
11
|
-
"enum": ["None", "MistralAI"]
|
|
12
|
-
},
|
|
13
|
-
"apiKey": {
|
|
14
|
-
"type": "string",
|
|
15
|
-
"title": "The Codestral API key",
|
|
16
|
-
"description": "The API key to use for Codestral",
|
|
17
|
-
"default": ""
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"additionalProperties": false
|
|
21
|
-
}
|
package/src/llm-models/utils.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
-
import { ChatMistralAI } from '@langchain/mistralai';
|
|
3
|
-
import { IBaseCompleter } from './base-completer';
|
|
4
|
-
import { CodestralCompleter } from './codestral-completer';
|
|
5
|
-
import { ReadonlyPartialJSONObject } from '@lumino/coreutils';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Get an LLM completer from the name.
|
|
9
|
-
*/
|
|
10
|
-
export function getCompleter(
|
|
11
|
-
name: string,
|
|
12
|
-
settings: ReadonlyPartialJSONObject
|
|
13
|
-
): IBaseCompleter | null {
|
|
14
|
-
if (name === 'MistralAI') {
|
|
15
|
-
return new CodestralCompleter({ settings });
|
|
16
|
-
}
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Get an LLM chat model from the name.
|
|
22
|
-
*/
|
|
23
|
-
export function getChatModel(
|
|
24
|
-
name: string,
|
|
25
|
-
settings: ReadonlyPartialJSONObject
|
|
26
|
-
): BaseChatModel | null {
|
|
27
|
-
if (name === 'MistralAI') {
|
|
28
|
-
return new ChatMistralAI({ ...settings });
|
|
29
|
-
}
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Get the error message from provider.
|
|
35
|
-
*/
|
|
36
|
-
export function getErrorMessage(name: string, error: any): string {
|
|
37
|
-
if (name === 'MistralAI') {
|
|
38
|
-
return error.message;
|
|
39
|
-
}
|
|
40
|
-
return 'Unknown provider';
|
|
41
|
-
}
|
package/src/token.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
-
import { Token } from '@lumino/coreutils';
|
|
3
|
-
import { ISignal } from '@lumino/signaling';
|
|
4
|
-
|
|
5
|
-
import { IBaseCompleter } from './llm-models';
|
|
6
|
-
|
|
7
|
-
export interface IAIProvider {
|
|
8
|
-
name: string;
|
|
9
|
-
completer: IBaseCompleter | null;
|
|
10
|
-
chatModel: BaseChatModel | null;
|
|
11
|
-
modelChange: ISignal<IAIProvider, void>;
|
|
12
|
-
chatError: string;
|
|
13
|
-
completerError: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const IAIProvider = new Token<IAIProvider>(
|
|
17
|
-
'@jupyterlite/ai:AIProvider',
|
|
18
|
-
'Provider for chat and completion LLM provider'
|
|
19
|
-
);
|