@jupyterlite/ai 0.2.0 → 0.3.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/_provider-settings/anthropic.json +70 -0
- package/lib/_provider-settings/chromeAI.json +21 -0
- package/lib/_provider-settings/mistralAI.json +75 -0
- package/lib/_provider-settings/openAI.json +668 -0
- package/lib/chat-handler.d.ts +12 -0
- package/lib/chat-handler.js +70 -21
- package/lib/completion-provider.d.ts +3 -3
- package/lib/icons.d.ts +2 -0
- package/lib/icons.js +15 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +61 -6
- 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/openai-completer.d.ts +19 -0
- package/lib/llm-models/openai-completer.js +51 -0
- package/lib/llm-models/utils.d.ts +1 -0
- package/lib/llm-models/utils.js +57 -0
- package/lib/provider.d.ts +11 -0
- package/lib/provider.js +26 -0
- package/lib/slash-commands.d.ts +16 -0
- package/lib/slash-commands.js +25 -0
- package/package.json +23 -104
- package/schema/ai-provider.json +4 -8
- package/schema/chat.json +8 -0
- package/src/chat-handler.ts +91 -34
- package/src/completion-provider.ts +3 -3
- package/src/icons.ts +18 -0
- package/src/index.ts +67 -5
- 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/openai-completer.ts +67 -0
- package/src/llm-models/svg.d.ts +9 -0
- package/src/llm-models/utils.ts +49 -0
- package/src/provider.ts +38 -0
- package/src/slash-commands.tsx +55 -0
- package/style/icons/jupyternaut-lite.svg +7 -0
package/src/provider.ts
CHANGED
|
@@ -8,6 +8,34 @@ import { CompletionProvider } from './completion-provider';
|
|
|
8
8
|
import { getChatModel, IBaseCompleter } from './llm-models';
|
|
9
9
|
import { IAIProvider } from './token';
|
|
10
10
|
|
|
11
|
+
export const chatSystemPrompt = (options: AIProvider.IPromptOptions) => `
|
|
12
|
+
You are Jupyternaut, a conversational assistant living in JupyterLab to help users.
|
|
13
|
+
You are not a language model, but rather an application built on a foundation model from ${options.provider_name}.
|
|
14
|
+
You are talkative and you provide lots of specific details from the foundation model's context.
|
|
15
|
+
You may use Markdown to format your response.
|
|
16
|
+
If your response includes code, they must be enclosed in Markdown fenced code blocks (with triple backticks before and after).
|
|
17
|
+
If your response includes mathematical notation, they must be expressed in LaTeX markup and enclosed in LaTeX delimiters.
|
|
18
|
+
All dollar quantities (of USD) must be formatted in LaTeX, with the \`$\` symbol escaped by a single backslash \`\\\`.
|
|
19
|
+
- Example prompt: \`If I have \\\\$100 and spend \\\\$20, how much money do I have left?\`
|
|
20
|
+
- **Correct** response: \`You have \\(\\$80\\) remaining.\`
|
|
21
|
+
- **Incorrect** response: \`You have $80 remaining.\`
|
|
22
|
+
If you do not know the answer to a question, answer truthfully by responding that you do not know.
|
|
23
|
+
The following is a friendly conversation between you and a human.
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
export const COMPLETION_SYSTEM_PROMPT = `
|
|
27
|
+
You are an application built to provide helpful code completion suggestions.
|
|
28
|
+
You should only produce code. Keep comments to minimum, use the
|
|
29
|
+
programming language comment syntax. Produce clean code.
|
|
30
|
+
The code is written in JupyterLab, a data analysis and code development
|
|
31
|
+
environment which can execute code extended with additional syntax for
|
|
32
|
+
interactive features, such as magics.
|
|
33
|
+
Only give raw strings back, do not format the response using backticks.
|
|
34
|
+
The output should be a single string, and should correspond to what a human users
|
|
35
|
+
would write.
|
|
36
|
+
Do not include the prompt in the output, only the string that should be appended to the current input.
|
|
37
|
+
`;
|
|
38
|
+
|
|
11
39
|
export class AIProvider implements IAIProvider {
|
|
12
40
|
constructor(options: AIProvider.IOptions) {
|
|
13
41
|
this._completionProvider = new CompletionProvider({
|
|
@@ -110,6 +138,16 @@ export namespace AIProvider {
|
|
|
110
138
|
requestCompletion: () => void;
|
|
111
139
|
}
|
|
112
140
|
|
|
141
|
+
/**
|
|
142
|
+
* The options for the Chat system prompt.
|
|
143
|
+
*/
|
|
144
|
+
export interface IPromptOptions {
|
|
145
|
+
/**
|
|
146
|
+
* The provider name.
|
|
147
|
+
*/
|
|
148
|
+
provider_name: string;
|
|
149
|
+
}
|
|
150
|
+
|
|
113
151
|
/**
|
|
114
152
|
* This function indicates whether a key is writable in an object.
|
|
115
153
|
* https://stackoverflow.com/questions/54724875/can-we-check-whether-property-is-readonly-in-typescript
|
|
@@ -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
|
+
}
|
|
@@ -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>
|