@jupyterlite/ai 0.6.2 → 0.8.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 +1 -1
- package/lib/base-completer.d.ts +22 -5
- package/lib/base-completer.js +14 -1
- package/lib/chat-handler.d.ts +23 -11
- package/lib/chat-handler.js +66 -45
- package/lib/completion-provider.d.ts +2 -2
- package/lib/completion-provider.js +5 -4
- package/lib/components/stop-button.d.ts +0 -1
- package/lib/default-prompts.d.ts +2 -0
- package/lib/default-prompts.js +31 -0
- package/lib/default-providers/Anthropic/completer.d.ts +4 -11
- package/lib/default-providers/Anthropic/completer.js +5 -16
- package/lib/default-providers/ChromeAI/completer.d.ts +4 -11
- package/lib/default-providers/ChromeAI/completer.js +5 -16
- package/lib/default-providers/ChromeAI/instructions.d.ts +4 -0
- package/lib/default-providers/ChromeAI/instructions.js +18 -0
- package/lib/default-providers/ChromeAI/settings-schema.json +0 -3
- package/lib/default-providers/Gemini/completer.d.ts +12 -0
- package/lib/default-providers/Gemini/completer.js +48 -0
- package/lib/default-providers/Gemini/instructions.d.ts +2 -0
- package/lib/default-providers/Gemini/instructions.js +9 -0
- package/lib/default-providers/Gemini/settings-schema.json +64 -0
- package/lib/default-providers/MistralAI/completer.d.ts +10 -13
- package/lib/default-providers/MistralAI/completer.js +42 -52
- package/lib/default-providers/MistralAI/instructions.d.ts +1 -1
- package/lib/default-providers/MistralAI/instructions.js +2 -0
- package/lib/default-providers/Ollama/completer.d.ts +12 -0
- package/lib/default-providers/Ollama/completer.js +43 -0
- package/lib/default-providers/Ollama/instructions.d.ts +2 -0
- package/lib/default-providers/Ollama/instructions.js +70 -0
- package/lib/default-providers/Ollama/settings-schema.json +143 -0
- package/lib/default-providers/OpenAI/completer.d.ts +4 -11
- package/lib/default-providers/OpenAI/completer.js +8 -16
- package/lib/default-providers/OpenAI/settings-schema.json +88 -128
- package/lib/default-providers/WebLLM/completer.d.ts +21 -0
- package/lib/default-providers/WebLLM/completer.js +127 -0
- package/lib/default-providers/WebLLM/instructions.d.ts +6 -0
- package/lib/default-providers/WebLLM/instructions.js +32 -0
- package/lib/default-providers/WebLLM/settings-schema.json +19 -0
- package/lib/default-providers/index.js +127 -8
- package/lib/index.d.ts +3 -2
- package/lib/index.js +80 -36
- package/lib/provider.d.ts +48 -22
- package/lib/provider.js +254 -101
- package/lib/settings/index.d.ts +1 -1
- package/lib/settings/index.js +1 -1
- package/lib/settings/panel.d.ts +151 -14
- package/lib/settings/panel.js +334 -145
- package/lib/settings/textarea.d.ts +2 -0
- package/lib/settings/textarea.js +18 -0
- package/lib/tokens.d.ts +45 -22
- package/lib/tokens.js +2 -1
- package/lib/types/ai-model.d.ts +24 -0
- package/lib/types/ai-model.js +5 -0
- package/package.json +19 -15
- package/schema/chat.json +1 -1
- package/schema/provider-registry.json +8 -8
- package/schema/system-prompts.json +22 -0
- package/src/base-completer.ts +38 -6
- package/src/chat-handler.ts +62 -31
- package/src/completion-provider.ts +3 -3
- package/src/default-prompts.ts +33 -0
- package/src/default-providers/Anthropic/completer.ts +5 -21
- package/src/default-providers/ChromeAI/completer.ts +5 -21
- package/src/default-providers/ChromeAI/instructions.ts +21 -0
- package/src/default-providers/Gemini/completer.ts +61 -0
- package/src/default-providers/Gemini/instructions.ts +9 -0
- package/src/default-providers/MistralAI/completer.ts +47 -65
- package/src/default-providers/MistralAI/instructions.ts +2 -0
- package/src/default-providers/Ollama/completer.ts +54 -0
- package/src/default-providers/Ollama/instructions.ts +70 -0
- package/src/default-providers/OpenAI/completer.ts +8 -21
- package/src/default-providers/WebLLM/completer.ts +151 -0
- package/src/default-providers/WebLLM/instructions.ts +33 -0
- package/src/default-providers/index.ts +158 -18
- package/src/index.ts +108 -40
- package/src/provider.ts +300 -109
- package/src/settings/index.ts +1 -1
- package/src/settings/panel.tsx +463 -101
- package/src/settings/textarea.tsx +33 -0
- package/src/tokens.ts +49 -24
- package/src/types/ai-model.ts +37 -0
- package/src/types/service-worker.d.ts +6 -0
- package/style/base.css +34 -0
- package/lib/settings/settings-connector.d.ts +0 -31
- package/lib/settings/settings-connector.js +0 -61
- package/src/settings/settings-connector.ts +0 -88
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
|
|
2
|
+
import { AIMessage, SystemMessage } from '@langchain/core/messages';
|
|
3
|
+
import { BaseCompleter } from '../../base-completer';
|
|
4
|
+
export class GeminiCompleter extends BaseCompleter {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
super(options);
|
|
7
|
+
this._completer = new ChatGoogleGenerativeAI({
|
|
8
|
+
model: 'gemini-pro',
|
|
9
|
+
...options.settings
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
async fetch(request, context) {
|
|
13
|
+
const { text, offset: cursorOffset } = request;
|
|
14
|
+
const prompt = text.slice(0, cursorOffset);
|
|
15
|
+
const trimmedPrompt = prompt.trim();
|
|
16
|
+
const messages = [
|
|
17
|
+
new SystemMessage(this.systemPrompt),
|
|
18
|
+
new AIMessage(trimmedPrompt)
|
|
19
|
+
];
|
|
20
|
+
try {
|
|
21
|
+
const response = await this._completer.invoke(messages);
|
|
22
|
+
const items = [];
|
|
23
|
+
// Gemini can return string or complex content, a list of string/images/other.
|
|
24
|
+
if (typeof response.content === 'string') {
|
|
25
|
+
items.push({
|
|
26
|
+
insertText: response.content
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
response.content.forEach(content => {
|
|
31
|
+
if (content.type !== 'text') {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
items.push({
|
|
35
|
+
insertText: content.text,
|
|
36
|
+
filterText: prompt.substring(trimmedPrompt.length)
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return { items };
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error('Error fetching completions', error);
|
|
44
|
+
return { items: [] };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
_completer;
|
|
48
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: "\n<i class=\"fas fa-exclamation-triangle\"></i> This extension is still very much experimental. It is not an official Google extension.\n\n1. Go to <https://aistudio.google.com> and create an API key.\n\n2. Open the JupyterLab settings and go to the **Ai providers** section to select the `Gemini`\n provider and add your API key (required).\n3. Open the chat, or use the inline completer.\n";
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default `
|
|
2
|
+
<i class="fas fa-exclamation-triangle"></i> This extension is still very much experimental. It is not an official Google extension.
|
|
3
|
+
|
|
4
|
+
1. Go to <https://aistudio.google.com> and create an API key.
|
|
5
|
+
|
|
6
|
+
2. Open the JupyterLab settings and go to the **Ai providers** section to select the \`Gemini\`
|
|
7
|
+
provider and add your API key (required).
|
|
8
|
+
3. Open the chat, or use the inline completer.
|
|
9
|
+
`;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"properties": {
|
|
5
|
+
"temperature": {
|
|
6
|
+
"type": "number",
|
|
7
|
+
"description": "Amount of randomness injected into the response. Ranges from 0 to 1. Use temp closer to 0 for analytical / multiple choice, and temp closer to 1 for creative and generative tasks."
|
|
8
|
+
},
|
|
9
|
+
"topK": {
|
|
10
|
+
"type": "number",
|
|
11
|
+
"description": "Only sample from the top K options for each subsequent token. Used to remove \"long tail\" low probability responses."
|
|
12
|
+
},
|
|
13
|
+
"topP": {
|
|
14
|
+
"type": "number",
|
|
15
|
+
"description": "Nucleus sampling parameter. Only the smallest set of most probable tokens with probabilities that add up to top_p or higher are kept for generation."
|
|
16
|
+
},
|
|
17
|
+
"maxOutputTokens": {
|
|
18
|
+
"type": "number",
|
|
19
|
+
"description": "The maximum number of tokens to generate in the response."
|
|
20
|
+
},
|
|
21
|
+
"stopSequences": {
|
|
22
|
+
"type": "array",
|
|
23
|
+
"items": {
|
|
24
|
+
"type": "string"
|
|
25
|
+
},
|
|
26
|
+
"description": "A list of strings upon which to stop generating. You probably want something like [\"\\n\\nHuman:\"] for chat conversations."
|
|
27
|
+
},
|
|
28
|
+
"streaming": {
|
|
29
|
+
"type": "boolean",
|
|
30
|
+
"description": "Whether to stream the results or not"
|
|
31
|
+
},
|
|
32
|
+
"apiKey": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"description": "Google AI Studio API key"
|
|
35
|
+
},
|
|
36
|
+
"model": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"description": "Model name to use (e.g., gemini-pro, gemini-2.0-flash, etc.)",
|
|
39
|
+
"default": "gemini-pro"
|
|
40
|
+
},
|
|
41
|
+
"baseURL": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"description": "Base URL for the Google AI API"
|
|
44
|
+
},
|
|
45
|
+
"safetySettings": {
|
|
46
|
+
"type": "array",
|
|
47
|
+
"description": "Safety settings for content filtering",
|
|
48
|
+
"items": {
|
|
49
|
+
"type": "object",
|
|
50
|
+
"properties": {
|
|
51
|
+
"category": {
|
|
52
|
+
"type": "string"
|
|
53
|
+
},
|
|
54
|
+
"threshold": {
|
|
55
|
+
"type": "string"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"additionalProperties": false,
|
|
62
|
+
"description": "Input to Google Generative AI Chat class.",
|
|
63
|
+
"definitions": {}
|
|
64
|
+
}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { CompletionHandler, IInlineCompletionContext } from '@jupyterlab/completer';
|
|
2
|
-
import {
|
|
3
|
-
import { BaseCompleter
|
|
4
|
-
export declare class CodestralCompleter
|
|
2
|
+
import { MistralAI } from '@langchain/mistralai';
|
|
3
|
+
import { BaseCompleter } from '../../base-completer';
|
|
4
|
+
export declare class CodestralCompleter extends BaseCompleter {
|
|
5
5
|
constructor(options: BaseCompleter.IOptions);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
private _throttler;
|
|
14
|
-
private _completer;
|
|
15
|
-
private _prompt;
|
|
6
|
+
fetch(request: CompletionHandler.IRequest, context: IInlineCompletionContext): Promise<{
|
|
7
|
+
items: {
|
|
8
|
+
insertText: string;
|
|
9
|
+
}[];
|
|
10
|
+
}>;
|
|
11
|
+
private _controller;
|
|
12
|
+
protected _completer: MistralAI;
|
|
16
13
|
}
|
|
@@ -1,62 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* The Mistral API has a rate limit of 1 request per second
|
|
7
|
-
*/
|
|
8
|
-
const INTERVAL = 1000;
|
|
9
|
-
export class CodestralCompleter {
|
|
1
|
+
import { MistralAI } from '@langchain/mistralai';
|
|
2
|
+
import { BaseCompleter } from '../../base-completer';
|
|
3
|
+
const CODE_BLOCK_START_REGEX = /^```(?:[a-zA-Z]+)?\n?/;
|
|
4
|
+
const CODE_BLOCK_END_REGEX = /```$/;
|
|
5
|
+
export class CodestralCompleter extends BaseCompleter {
|
|
10
6
|
constructor(options) {
|
|
11
|
-
|
|
12
|
-
this._completer = new
|
|
13
|
-
this._throttler = new Throttler(async (messages) => {
|
|
14
|
-
const response = await this._completer.invoke(messages);
|
|
15
|
-
// Extract results of completion request.
|
|
16
|
-
const items = [];
|
|
17
|
-
if (typeof response.content === 'string') {
|
|
18
|
-
items.push({
|
|
19
|
-
insertText: response.content
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
response.content.forEach(content => {
|
|
24
|
-
if (content.type !== 'text') {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
items.push({
|
|
28
|
-
insertText: content.text
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
return { items };
|
|
33
|
-
}, { limit: INTERVAL });
|
|
34
|
-
}
|
|
35
|
-
get completer() {
|
|
36
|
-
return this._completer;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Getter and setter for the initial prompt.
|
|
40
|
-
*/
|
|
41
|
-
get prompt() {
|
|
42
|
-
return this._prompt;
|
|
43
|
-
}
|
|
44
|
-
set prompt(value) {
|
|
45
|
-
this._prompt = value;
|
|
7
|
+
super(options);
|
|
8
|
+
this._completer = new MistralAI({ ...options.settings });
|
|
46
9
|
}
|
|
47
10
|
async fetch(request, context) {
|
|
48
|
-
const { text, offset: cursorOffset } = request;
|
|
49
|
-
const prompt = text.slice(0, cursorOffset);
|
|
50
|
-
const messages = [
|
|
51
|
-
new SystemMessage(this._prompt),
|
|
52
|
-
new HumanMessage(prompt)
|
|
53
|
-
];
|
|
54
11
|
try {
|
|
55
|
-
|
|
12
|
+
const { text, offset: cursorOffset } = request;
|
|
13
|
+
const prompt = this.systemPrompt.concat(text.slice(0, cursorOffset));
|
|
14
|
+
const suffix = text.slice(cursorOffset);
|
|
15
|
+
this._controller.abort();
|
|
16
|
+
this._controller = new AbortController();
|
|
17
|
+
const response = await this._completer.completionWithRetry({
|
|
18
|
+
prompt,
|
|
19
|
+
model: this._completer.model,
|
|
20
|
+
suffix
|
|
21
|
+
}, { signal: this._controller.signal }, false);
|
|
22
|
+
const items = response.choices.map(choice => {
|
|
23
|
+
const messageContent = choice.message.content;
|
|
24
|
+
let content = '';
|
|
25
|
+
if (typeof messageContent === 'string') {
|
|
26
|
+
content = messageContent
|
|
27
|
+
.replace(CODE_BLOCK_START_REGEX, '')
|
|
28
|
+
.replace(CODE_BLOCK_END_REGEX, '');
|
|
29
|
+
}
|
|
30
|
+
else if (Array.isArray(messageContent)) {
|
|
31
|
+
// Handle ContentChunk[] case - extract text content
|
|
32
|
+
content = messageContent
|
|
33
|
+
.filter(chunk => chunk.type === 'text')
|
|
34
|
+
.map(chunk => chunk.text || '')
|
|
35
|
+
.join('')
|
|
36
|
+
.replace(CODE_BLOCK_START_REGEX, '')
|
|
37
|
+
.replace(CODE_BLOCK_END_REGEX, '');
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
insertText: content
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
return { items };
|
|
56
44
|
}
|
|
57
45
|
catch (error) {
|
|
58
|
-
|
|
46
|
+
// the request may be aborted
|
|
59
47
|
return { items: [] };
|
|
60
48
|
}
|
|
61
49
|
}
|
|
50
|
+
_controller = new AbortController();
|
|
51
|
+
_completer;
|
|
62
52
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "\n<i class=\"fas fa-exclamation-triangle\"></i> This extension is still very much experimental. It is not an official MistralAI extension.\n\n1. Go to <https://console.mistral.ai/api-keys/> and create an API key.\n\n <img src=\"https://raw.githubusercontent.com/jupyterlite/ai/refs/heads/main/img/1-api-key.png\" alt=\"Screenshot showing how to create an API key\" width=\"500px\">\n\n2. Open the JupyterLab settings and go to the **Ai providers** section to select the `MistralAI`\n provider and the API key (required).\n\n <img src=\"https://raw.githubusercontent.com/jupyterlite/ai/refs/heads/main/img/2-jupyterlab-settings.png\" alt=\"Screenshot showing how to add the API key to the settings\" width=\"500px\">\n\n3. Open the chat, or use the inline completer\n\n <img src=\"https://raw.githubusercontent.com/jupyterlite/ai/refs/heads/main/img/3-usage.png\" alt=\"Screenshot showing how to use the chat\" width=\"500px\">\n";
|
|
1
|
+
declare const _default: "\n<i class=\"fas fa-exclamation-triangle\"></i> This extension is still very much experimental. It is not an official MistralAI extension.\n\n1. Go to <https://console.mistral.ai/api-keys/> and create an API key.\n\n <img src=\"https://raw.githubusercontent.com/jupyterlite/ai/refs/heads/main/img/1-api-key.png\" alt=\"Screenshot showing how to create an API key\" width=\"500px\">\n\n2. Open the JupyterLab settings and go to the **Ai providers** section to select the `MistralAI`\n provider and the API key (required).\n\n <img src=\"https://raw.githubusercontent.com/jupyterlite/ai/refs/heads/main/img/2-jupyterlab-settings.png\" alt=\"Screenshot showing how to add the API key to the settings\" width=\"500px\">\n\n**Note:** When using MistralAI for completions, only a subset of models are available. Please check [this resource](https://docs.mistral.ai/api/#tag/fim) to see the list of supported models for completions.\n\n3. Open the chat, or use the inline completer\n\n <img src=\"https://raw.githubusercontent.com/jupyterlite/ai/refs/heads/main/img/3-usage.png\" alt=\"Screenshot showing how to use the chat\" width=\"500px\">\n";
|
|
2
2
|
export default _default;
|
|
@@ -10,6 +10,8 @@ export default `
|
|
|
10
10
|
|
|
11
11
|
<img src="https://raw.githubusercontent.com/jupyterlite/ai/refs/heads/main/img/2-jupyterlab-settings.png" alt="Screenshot showing how to add the API key to the settings" width="500px">
|
|
12
12
|
|
|
13
|
+
**Note:** When using MistralAI for completions, only a subset of models are available. Please check [this resource](https://docs.mistral.ai/api/#tag/fim) to see the list of supported models for completions.
|
|
14
|
+
|
|
13
15
|
3. Open the chat, or use the inline completer
|
|
14
16
|
|
|
15
17
|
<img src="https://raw.githubusercontent.com/jupyterlite/ai/refs/heads/main/img/3-usage.png" alt="Screenshot showing how to use the chat" width="500px">
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CompletionHandler, IInlineCompletionContext } from '@jupyterlab/completer';
|
|
2
|
+
import { ChatOllama } from '@langchain/ollama';
|
|
3
|
+
import { BaseCompleter } from '../../base-completer';
|
|
4
|
+
export declare class OllamaCompleter extends BaseCompleter {
|
|
5
|
+
constructor(options: BaseCompleter.IOptions);
|
|
6
|
+
fetch(request: CompletionHandler.IRequest, context: IInlineCompletionContext): Promise<{
|
|
7
|
+
items: {
|
|
8
|
+
insertText: string;
|
|
9
|
+
}[];
|
|
10
|
+
}>;
|
|
11
|
+
protected _completer: ChatOllama;
|
|
12
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AIMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
|
+
import { ChatOllama } from '@langchain/ollama';
|
|
3
|
+
import { BaseCompleter } from '../../base-completer';
|
|
4
|
+
export class OllamaCompleter extends BaseCompleter {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
super(options);
|
|
7
|
+
this._completer = new ChatOllama({ ...options.settings });
|
|
8
|
+
}
|
|
9
|
+
async fetch(request, context) {
|
|
10
|
+
const { text, offset: cursorOffset } = request;
|
|
11
|
+
const prompt = text.slice(0, cursorOffset);
|
|
12
|
+
const messages = [
|
|
13
|
+
new SystemMessage(this.systemPrompt),
|
|
14
|
+
new AIMessage(prompt)
|
|
15
|
+
];
|
|
16
|
+
try {
|
|
17
|
+
const response = await this._completer.invoke(messages);
|
|
18
|
+
const items = [];
|
|
19
|
+
if (typeof response.content === 'string') {
|
|
20
|
+
items.push({
|
|
21
|
+
insertText: response.content
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
response.content.forEach(content => {
|
|
26
|
+
if (content.type !== 'text') {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
items.push({
|
|
30
|
+
insertText: content.text,
|
|
31
|
+
filterText: prompt.substring(prompt.length)
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return { items };
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error('Error fetching completions', error);
|
|
39
|
+
return { items: [] };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
_completer;
|
|
43
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: "\nOllama allows to run large language models locally on your machine.\nTo use it you need to install the Ollama CLI and pull the model you want to use.\n\n1. Install the Ollama CLI by following the instructions at <https://ollama.com/download>\n\n2. Pull the model you want to use by running the following command in your terminal:\n\n ```bash\n ollama pull <model-name>\n ```\n\n For example, to pull the Llama 2 model, run:\n\n ```bash\n ollama pull llama2\n ```\n\n3. Once the model is pulled, you can use it in your application by running the following command:\n\n ```bash\n ollama serve\n ```\n\n4. This model will be available in the extension, using the model name you used in the command above.\n\n<details>\n<summary>Deploying Lite/Lab on external server</summary>\n\nSee https://objectgraph.com/blog/ollama-cors/ for more details.\n\nOn Linux, you can run the following commands:\n\n1. Check if CORS is enabled on the server. You can do this by running the following command in your terminal:\n\n ```bash\n curl -X OPTIONS http://localhost:11434 -H \"Origin: http://example.com\" -H \"Access-Control-Request-Method: GET\" -I\n ```\n\n If CORS is disabled, you will see a response like this:\n\n ```bash\n HTTP/1.1 403 Forbidden\n Date: Wed, 09 Oct 2024 10:12:15 GMT\n Content-Length: 0\n ```\n\n2. If CORS is not enabled, update _/etc/systemd/system/ollama.service_ with:\n\n ```bash\n [Service]\n Environment=\"OLLAMA_HOST=0.0.0.0\"\n Environment=\"OLLAMA_ORIGINS=*\"\n ```\n\n3. Restart the service:\n\n ```bash\n sudo systemctl daemon-reload\n sudo systemctl restart ollama\n ```\n\n4. Check if CORS is enabled on the server again by running the following command in your terminal:\n\n ```bash\n curl -X OPTIONS http://localhost:11434 -H \"Origin: http://example.com\" -H \"Access-Control-Request-Method: GET\" -I\n ```\n\n</details>\n";
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export default `
|
|
2
|
+
Ollama allows to run large language models locally on your machine.
|
|
3
|
+
To use it you need to install the Ollama CLI and pull the model you want to use.
|
|
4
|
+
|
|
5
|
+
1. Install the Ollama CLI by following the instructions at <https://ollama.com/download>
|
|
6
|
+
|
|
7
|
+
2. Pull the model you want to use by running the following command in your terminal:
|
|
8
|
+
|
|
9
|
+
\`\`\`bash
|
|
10
|
+
ollama pull <model-name>
|
|
11
|
+
\`\`\`
|
|
12
|
+
|
|
13
|
+
For example, to pull the Llama 2 model, run:
|
|
14
|
+
|
|
15
|
+
\`\`\`bash
|
|
16
|
+
ollama pull llama2
|
|
17
|
+
\`\`\`
|
|
18
|
+
|
|
19
|
+
3. Once the model is pulled, you can use it in your application by running the following command:
|
|
20
|
+
|
|
21
|
+
\`\`\`bash
|
|
22
|
+
ollama serve
|
|
23
|
+
\`\`\`
|
|
24
|
+
|
|
25
|
+
4. This model will be available in the extension, using the model name you used in the command above.
|
|
26
|
+
|
|
27
|
+
<details>
|
|
28
|
+
<summary>Deploying Lite/Lab on external server</summary>
|
|
29
|
+
|
|
30
|
+
See https://objectgraph.com/blog/ollama-cors/ for more details.
|
|
31
|
+
|
|
32
|
+
On Linux, you can run the following commands:
|
|
33
|
+
|
|
34
|
+
1. Check if CORS is enabled on the server. You can do this by running the following command in your terminal:
|
|
35
|
+
|
|
36
|
+
\`\`\`bash
|
|
37
|
+
curl -X OPTIONS http://localhost:11434 -H "Origin: http://example.com" -H "Access-Control-Request-Method: GET" -I
|
|
38
|
+
\`\`\`
|
|
39
|
+
|
|
40
|
+
If CORS is disabled, you will see a response like this:
|
|
41
|
+
|
|
42
|
+
\`\`\`bash
|
|
43
|
+
HTTP/1.1 403 Forbidden
|
|
44
|
+
Date: Wed, 09 Oct 2024 10:12:15 GMT
|
|
45
|
+
Content-Length: 0
|
|
46
|
+
\`\`\`
|
|
47
|
+
|
|
48
|
+
2. If CORS is not enabled, update _/etc/systemd/system/ollama.service_ with:
|
|
49
|
+
|
|
50
|
+
\`\`\`bash
|
|
51
|
+
[Service]
|
|
52
|
+
Environment="OLLAMA_HOST=0.0.0.0"
|
|
53
|
+
Environment="OLLAMA_ORIGINS=*"
|
|
54
|
+
\`\`\`
|
|
55
|
+
|
|
56
|
+
3. Restart the service:
|
|
57
|
+
|
|
58
|
+
\`\`\`bash
|
|
59
|
+
sudo systemctl daemon-reload
|
|
60
|
+
sudo systemctl restart ollama
|
|
61
|
+
\`\`\`
|
|
62
|
+
|
|
63
|
+
4. Check if CORS is enabled on the server again by running the following command in your terminal:
|
|
64
|
+
|
|
65
|
+
\`\`\`bash
|
|
66
|
+
curl -X OPTIONS http://localhost:11434 -H "Origin: http://example.com" -H "Access-Control-Request-Method: GET" -I
|
|
67
|
+
\`\`\`
|
|
68
|
+
|
|
69
|
+
</details>
|
|
70
|
+
`;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"properties": {
|
|
5
|
+
"numa": {
|
|
6
|
+
"type": "boolean"
|
|
7
|
+
},
|
|
8
|
+
"numCtx": {
|
|
9
|
+
"type": "number"
|
|
10
|
+
},
|
|
11
|
+
"numBatch": {
|
|
12
|
+
"type": "number"
|
|
13
|
+
},
|
|
14
|
+
"numGpu": {
|
|
15
|
+
"type": "number"
|
|
16
|
+
},
|
|
17
|
+
"mainGpu": {
|
|
18
|
+
"type": "number"
|
|
19
|
+
},
|
|
20
|
+
"lowVram": {
|
|
21
|
+
"type": "boolean"
|
|
22
|
+
},
|
|
23
|
+
"f16Kv": {
|
|
24
|
+
"type": "boolean"
|
|
25
|
+
},
|
|
26
|
+
"logitsAll": {
|
|
27
|
+
"type": "boolean"
|
|
28
|
+
},
|
|
29
|
+
"vocabOnly": {
|
|
30
|
+
"type": "boolean"
|
|
31
|
+
},
|
|
32
|
+
"useMmap": {
|
|
33
|
+
"type": "boolean"
|
|
34
|
+
},
|
|
35
|
+
"useMlock": {
|
|
36
|
+
"type": "boolean"
|
|
37
|
+
},
|
|
38
|
+
"embeddingOnly": {
|
|
39
|
+
"type": "boolean"
|
|
40
|
+
},
|
|
41
|
+
"numThread": {
|
|
42
|
+
"type": "number"
|
|
43
|
+
},
|
|
44
|
+
"numKeep": {
|
|
45
|
+
"type": "number"
|
|
46
|
+
},
|
|
47
|
+
"seed": {
|
|
48
|
+
"type": "number"
|
|
49
|
+
},
|
|
50
|
+
"numPredict": {
|
|
51
|
+
"type": "number"
|
|
52
|
+
},
|
|
53
|
+
"topK": {
|
|
54
|
+
"type": "number"
|
|
55
|
+
},
|
|
56
|
+
"topP": {
|
|
57
|
+
"type": "number"
|
|
58
|
+
},
|
|
59
|
+
"tfsZ": {
|
|
60
|
+
"type": "number"
|
|
61
|
+
},
|
|
62
|
+
"typicalP": {
|
|
63
|
+
"type": "number"
|
|
64
|
+
},
|
|
65
|
+
"repeatLastN": {
|
|
66
|
+
"type": "number"
|
|
67
|
+
},
|
|
68
|
+
"temperature": {
|
|
69
|
+
"type": "number"
|
|
70
|
+
},
|
|
71
|
+
"repeatPenalty": {
|
|
72
|
+
"type": "number"
|
|
73
|
+
},
|
|
74
|
+
"presencePenalty": {
|
|
75
|
+
"type": "number"
|
|
76
|
+
},
|
|
77
|
+
"frequencyPenalty": {
|
|
78
|
+
"type": "number"
|
|
79
|
+
},
|
|
80
|
+
"mirostat": {
|
|
81
|
+
"type": "number"
|
|
82
|
+
},
|
|
83
|
+
"mirostatTau": {
|
|
84
|
+
"type": "number"
|
|
85
|
+
},
|
|
86
|
+
"mirostatEta": {
|
|
87
|
+
"type": "number"
|
|
88
|
+
},
|
|
89
|
+
"penalizeNewline": {
|
|
90
|
+
"type": "boolean"
|
|
91
|
+
},
|
|
92
|
+
"keepAlive": {
|
|
93
|
+
"type": ["string", "number"],
|
|
94
|
+
"default": "5m"
|
|
95
|
+
},
|
|
96
|
+
"stop": {
|
|
97
|
+
"type": "array",
|
|
98
|
+
"items": {
|
|
99
|
+
"type": "string"
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
"disableStreaming": {
|
|
103
|
+
"type": "boolean",
|
|
104
|
+
"description": "Whether to disable streaming.\n\nIf streaming is bypassed, then `stream()` will defer to `invoke()`.\n\n- If true, will always bypass streaming case.\n- If false (default), will always use streaming case if available."
|
|
105
|
+
},
|
|
106
|
+
"model": {
|
|
107
|
+
"type": "string",
|
|
108
|
+
"description": "The model to invoke. If the model does not exist, it will be pulled.",
|
|
109
|
+
"default": ""
|
|
110
|
+
},
|
|
111
|
+
"baseUrl": {
|
|
112
|
+
"type": "string",
|
|
113
|
+
"description": "The host URL of the Ollama server.",
|
|
114
|
+
"default": ""
|
|
115
|
+
},
|
|
116
|
+
"headers": {
|
|
117
|
+
"type": "object",
|
|
118
|
+
"additionalProperties": false,
|
|
119
|
+
"description": "Optional HTTP Headers to include in the request."
|
|
120
|
+
},
|
|
121
|
+
"checkOrPullModel": {
|
|
122
|
+
"type": "boolean",
|
|
123
|
+
"description": "Whether or not to check the model exists on the local machine before invoking it. If set to `true`, the model will be pulled if it does not exist.",
|
|
124
|
+
"default": false
|
|
125
|
+
},
|
|
126
|
+
"streaming": {
|
|
127
|
+
"type": "boolean"
|
|
128
|
+
},
|
|
129
|
+
"format": {
|
|
130
|
+
"anyOf": [
|
|
131
|
+
{
|
|
132
|
+
"type": "string"
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"type": "object"
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
"additionalProperties": false,
|
|
141
|
+
"description": "Input to chat model class.",
|
|
142
|
+
"definitions": {}
|
|
143
|
+
}
|
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import { CompletionHandler, IInlineCompletionContext } from '@jupyterlab/completer';
|
|
2
|
-
import {
|
|
3
|
-
import { BaseCompleter
|
|
4
|
-
export declare class OpenAICompleter
|
|
2
|
+
import { ChatOpenAI } from '@langchain/openai';
|
|
3
|
+
import { BaseCompleter } from '../../base-completer';
|
|
4
|
+
export declare class OpenAICompleter extends BaseCompleter {
|
|
5
5
|
constructor(options: BaseCompleter.IOptions);
|
|
6
|
-
get completer(): BaseChatModel;
|
|
7
|
-
/**
|
|
8
|
-
* Getter and setter for the initial prompt.
|
|
9
|
-
*/
|
|
10
|
-
get prompt(): string;
|
|
11
|
-
set prompt(value: string);
|
|
12
6
|
fetch(request: CompletionHandler.IRequest, context: IInlineCompletionContext): Promise<{
|
|
13
7
|
items: {
|
|
14
8
|
insertText: string;
|
|
15
9
|
}[];
|
|
16
10
|
}>;
|
|
17
|
-
|
|
18
|
-
private _prompt;
|
|
11
|
+
protected _completer: ChatOpenAI;
|
|
19
12
|
}
|
|
@@ -1,27 +1,18 @@
|
|
|
1
1
|
import { AIMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
2
|
import { ChatOpenAI } from '@langchain/openai';
|
|
3
|
-
import {
|
|
4
|
-
export class OpenAICompleter {
|
|
3
|
+
import { BaseCompleter } from '../../base-completer';
|
|
4
|
+
export class OpenAICompleter extends BaseCompleter {
|
|
5
5
|
constructor(options) {
|
|
6
|
-
|
|
6
|
+
super(options);
|
|
7
7
|
this._completer = new ChatOpenAI({ ...options.settings });
|
|
8
8
|
}
|
|
9
|
-
get completer() {
|
|
10
|
-
return this._completer;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Getter and setter for the initial prompt.
|
|
14
|
-
*/
|
|
15
|
-
get prompt() {
|
|
16
|
-
return this._prompt;
|
|
17
|
-
}
|
|
18
|
-
set prompt(value) {
|
|
19
|
-
this._prompt = value;
|
|
20
|
-
}
|
|
21
9
|
async fetch(request, context) {
|
|
22
10
|
const { text, offset: cursorOffset } = request;
|
|
23
11
|
const prompt = text.slice(0, cursorOffset);
|
|
24
|
-
const messages = [
|
|
12
|
+
const messages = [
|
|
13
|
+
new SystemMessage(this.systemPrompt),
|
|
14
|
+
new AIMessage(prompt)
|
|
15
|
+
];
|
|
25
16
|
try {
|
|
26
17
|
const response = await this._completer.invoke(messages);
|
|
27
18
|
const items = [];
|
|
@@ -48,4 +39,5 @@ export class OpenAICompleter {
|
|
|
48
39
|
return { items: [] };
|
|
49
40
|
}
|
|
50
41
|
}
|
|
42
|
+
_completer;
|
|
51
43
|
}
|