@jupyterlite/ai 0.7.0 → 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/lib/base-completer.d.ts +23 -1
- package/lib/base-completer.js +14 -1
- package/lib/chat-handler.d.ts +4 -6
- package/lib/chat-handler.js +22 -22
- package/lib/completion-provider.js +1 -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 -9
- package/lib/default-providers/Anthropic/completer.js +4 -13
- package/lib/default-providers/ChromeAI/completer.d.ts +4 -9
- package/lib/default-providers/ChromeAI/completer.js +4 -13
- 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 -11
- package/lib/default-providers/MistralAI/completer.js +41 -50
- 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 +4 -9
- package/lib/default-providers/Ollama/completer.js +7 -13
- package/lib/default-providers/Ollama/settings-schema.json +1 -4
- package/lib/default-providers/OpenAI/completer.d.ts +4 -9
- package/lib/default-providers/OpenAI/completer.js +7 -13
- package/lib/default-providers/OpenAI/settings-schema.json +88 -128
- package/lib/default-providers/WebLLM/completer.d.ts +3 -9
- package/lib/default-providers/WebLLM/completer.js +4 -13
- package/lib/default-providers/WebLLM/settings-schema.json +1 -3
- package/lib/default-providers/index.js +23 -19
- package/lib/index.d.ts +1 -0
- package/lib/index.js +68 -14
- package/lib/provider.d.ts +39 -11
- package/lib/provider.js +166 -81
- package/lib/settings/index.d.ts +1 -0
- package/lib/settings/index.js +1 -0
- package/lib/settings/panel.d.ts +116 -8
- package/lib/settings/panel.js +117 -22
- package/lib/settings/textarea.d.ts +2 -0
- package/lib/settings/textarea.js +18 -0
- package/lib/tokens.d.ts +24 -20
- package/lib/tokens.js +2 -1
- package/package.json +10 -9
- package/schema/chat.json +1 -1
- package/schema/provider-registry.json +11 -5
- package/schema/system-prompts.json +22 -0
- package/src/base-completer.ts +39 -1
- package/src/chat-handler.ts +23 -25
- package/src/completion-provider.ts +1 -1
- package/src/default-prompts.ts +33 -0
- package/src/default-providers/Anthropic/completer.ts +5 -16
- package/src/default-providers/ChromeAI/completer.ts +5 -16
- 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 -60
- package/src/default-providers/MistralAI/instructions.ts +2 -0
- package/src/default-providers/Ollama/completer.ts +8 -16
- package/src/default-providers/OpenAI/completer.ts +8 -16
- package/src/default-providers/WebLLM/completer.ts +5 -16
- package/src/default-providers/index.ts +23 -20
- package/src/index.ts +95 -15
- package/src/provider.ts +198 -94
- package/src/settings/index.ts +1 -0
- package/src/settings/panel.tsx +262 -34
- package/src/settings/textarea.tsx +33 -0
- package/src/tokens.ts +26 -22
- package/style/base.css +29 -0
|
@@ -42,10 +42,7 @@
|
|
|
42
42
|
"description": "The type of the content part."
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
|
-
"required": [
|
|
46
|
-
"text",
|
|
47
|
-
"type"
|
|
48
|
-
],
|
|
45
|
+
"required": ["text", "type"],
|
|
49
46
|
"additionalProperties": false,
|
|
50
47
|
"description": "Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation)."
|
|
51
48
|
}
|
|
@@ -63,10 +60,7 @@
|
|
|
63
60
|
"description": "An optional name for the participant. Provides the model information to differentiate between participants of the same role."
|
|
64
61
|
}
|
|
65
62
|
},
|
|
66
|
-
"required": [
|
|
67
|
-
"content",
|
|
68
|
-
"role"
|
|
69
|
-
],
|
|
63
|
+
"required": ["content", "role"],
|
|
70
64
|
"additionalProperties": false,
|
|
71
65
|
"description": "Developer-provided instructions that the model should follow, regardless of messages sent by the user. With o1 models and newer, `developer` messages replace the previous `system` messages."
|
|
72
66
|
},
|
|
@@ -93,10 +87,7 @@
|
|
|
93
87
|
"description": "The type of the content part."
|
|
94
88
|
}
|
|
95
89
|
},
|
|
96
|
-
"required": [
|
|
97
|
-
"text",
|
|
98
|
-
"type"
|
|
99
|
-
],
|
|
90
|
+
"required": ["text", "type"],
|
|
100
91
|
"additionalProperties": false,
|
|
101
92
|
"description": "Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation)."
|
|
102
93
|
}
|
|
@@ -114,10 +105,7 @@
|
|
|
114
105
|
"description": "An optional name for the participant. Provides the model information to differentiate between participants of the same role."
|
|
115
106
|
}
|
|
116
107
|
},
|
|
117
|
-
"required": [
|
|
118
|
-
"content",
|
|
119
|
-
"role"
|
|
120
|
-
],
|
|
108
|
+
"required": ["content", "role"],
|
|
121
109
|
"additionalProperties": false,
|
|
122
110
|
"description": "Developer-provided instructions that the model should follow, regardless of messages sent by the user. With o1 models and newer, use `developer` messages for this purpose instead."
|
|
123
111
|
},
|
|
@@ -146,10 +134,7 @@
|
|
|
146
134
|
"description": "The type of the content part."
|
|
147
135
|
}
|
|
148
136
|
},
|
|
149
|
-
"required": [
|
|
150
|
-
"text",
|
|
151
|
-
"type"
|
|
152
|
-
],
|
|
137
|
+
"required": ["text", "type"],
|
|
153
138
|
"additionalProperties": false,
|
|
154
139
|
"description": "Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation)."
|
|
155
140
|
},
|
|
@@ -165,17 +150,11 @@
|
|
|
165
150
|
},
|
|
166
151
|
"detail": {
|
|
167
152
|
"type": "string",
|
|
168
|
-
"enum": [
|
|
169
|
-
"auto",
|
|
170
|
-
"low",
|
|
171
|
-
"high"
|
|
172
|
-
],
|
|
153
|
+
"enum": ["auto", "low", "high"],
|
|
173
154
|
"description": "Specifies the detail level of the image. Learn more in the [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding)."
|
|
174
155
|
}
|
|
175
156
|
},
|
|
176
|
-
"required": [
|
|
177
|
-
"url"
|
|
178
|
-
],
|
|
157
|
+
"required": ["url"],
|
|
179
158
|
"additionalProperties": false
|
|
180
159
|
},
|
|
181
160
|
"type": {
|
|
@@ -184,10 +163,7 @@
|
|
|
184
163
|
"description": "The type of the content part."
|
|
185
164
|
}
|
|
186
165
|
},
|
|
187
|
-
"required": [
|
|
188
|
-
"image_url",
|
|
189
|
-
"type"
|
|
190
|
-
],
|
|
166
|
+
"required": ["image_url", "type"],
|
|
191
167
|
"additionalProperties": false,
|
|
192
168
|
"description": "Learn about [image inputs](https://platform.openai.com/docs/guides/vision)."
|
|
193
169
|
},
|
|
@@ -203,17 +179,11 @@
|
|
|
203
179
|
},
|
|
204
180
|
"format": {
|
|
205
181
|
"type": "string",
|
|
206
|
-
"enum": [
|
|
207
|
-
"wav",
|
|
208
|
-
"mp3"
|
|
209
|
-
],
|
|
182
|
+
"enum": ["wav", "mp3"],
|
|
210
183
|
"description": "The format of the encoded audio data. Currently supports \"wav\" and \"mp3\"."
|
|
211
184
|
}
|
|
212
185
|
},
|
|
213
|
-
"required": [
|
|
214
|
-
"data",
|
|
215
|
-
"format"
|
|
216
|
-
],
|
|
186
|
+
"required": ["data", "format"],
|
|
217
187
|
"additionalProperties": false
|
|
218
188
|
},
|
|
219
189
|
"type": {
|
|
@@ -222,12 +192,40 @@
|
|
|
222
192
|
"description": "The type of the content part. Always `input_audio`."
|
|
223
193
|
}
|
|
224
194
|
},
|
|
225
|
-
"required": [
|
|
226
|
-
"input_audio",
|
|
227
|
-
"type"
|
|
228
|
-
],
|
|
195
|
+
"required": ["input_audio", "type"],
|
|
229
196
|
"additionalProperties": false,
|
|
230
197
|
"description": "Learn about [audio inputs](https://platform.openai.com/docs/guides/audio)."
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
"type": "object",
|
|
201
|
+
"properties": {
|
|
202
|
+
"file": {
|
|
203
|
+
"type": "object",
|
|
204
|
+
"properties": {
|
|
205
|
+
"file_data": {
|
|
206
|
+
"type": "string",
|
|
207
|
+
"description": "The base64 encoded file data, used when passing the file to the model as a string."
|
|
208
|
+
},
|
|
209
|
+
"file_id": {
|
|
210
|
+
"type": "string",
|
|
211
|
+
"description": "The ID of an uploaded file to use as input."
|
|
212
|
+
},
|
|
213
|
+
"filename": {
|
|
214
|
+
"type": "string",
|
|
215
|
+
"description": "The name of the file, used when passing the file to the model as a string."
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
"additionalProperties": false
|
|
219
|
+
},
|
|
220
|
+
"type": {
|
|
221
|
+
"type": "string",
|
|
222
|
+
"const": "file",
|
|
223
|
+
"description": "The type of the content part. Always `file`."
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
"required": ["file", "type"],
|
|
227
|
+
"additionalProperties": false,
|
|
228
|
+
"description": "Learn about [file inputs](https://platform.openai.com/docs/guides/text) for text generation."
|
|
231
229
|
}
|
|
232
230
|
],
|
|
233
231
|
"description": "Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation)."
|
|
@@ -246,10 +244,7 @@
|
|
|
246
244
|
"description": "An optional name for the participant. Provides the model information to differentiate between participants of the same role."
|
|
247
245
|
}
|
|
248
246
|
},
|
|
249
|
-
"required": [
|
|
250
|
-
"content",
|
|
251
|
-
"role"
|
|
252
|
-
],
|
|
247
|
+
"required": ["content", "role"],
|
|
253
248
|
"additionalProperties": false,
|
|
254
249
|
"description": "Messages sent by an end user, containing prompts or additional context information."
|
|
255
250
|
},
|
|
@@ -271,9 +266,7 @@
|
|
|
271
266
|
"description": "Unique identifier for a previous audio response from the model."
|
|
272
267
|
}
|
|
273
268
|
},
|
|
274
|
-
"required": [
|
|
275
|
-
"id"
|
|
276
|
-
],
|
|
269
|
+
"required": ["id"],
|
|
277
270
|
"additionalProperties": false,
|
|
278
271
|
"description": "Data about a previous audio response from the model. [Learn more](https://platform.openai.com/docs/guides/audio)."
|
|
279
272
|
},
|
|
@@ -305,10 +298,7 @@
|
|
|
305
298
|
"description": "The type of the content part."
|
|
306
299
|
}
|
|
307
300
|
},
|
|
308
|
-
"required": [
|
|
309
|
-
"text",
|
|
310
|
-
"type"
|
|
311
|
-
],
|
|
301
|
+
"required": ["text", "type"],
|
|
312
302
|
"additionalProperties": false,
|
|
313
303
|
"description": "Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation)."
|
|
314
304
|
},
|
|
@@ -325,10 +315,7 @@
|
|
|
325
315
|
"description": "The type of the content part."
|
|
326
316
|
}
|
|
327
317
|
},
|
|
328
|
-
"required": [
|
|
329
|
-
"refusal",
|
|
330
|
-
"type"
|
|
331
|
-
],
|
|
318
|
+
"required": ["refusal", "type"],
|
|
332
319
|
"additionalProperties": false
|
|
333
320
|
}
|
|
334
321
|
]
|
|
@@ -354,10 +341,7 @@
|
|
|
354
341
|
"description": "The name of the function to call."
|
|
355
342
|
}
|
|
356
343
|
},
|
|
357
|
-
"required": [
|
|
358
|
-
"arguments",
|
|
359
|
-
"name"
|
|
360
|
-
],
|
|
344
|
+
"required": ["arguments", "name"],
|
|
361
345
|
"additionalProperties": false,
|
|
362
346
|
"deprecated": "Deprecated and replaced by `tool_calls`. The name and arguments of a\nfunction that should be called, as generated by the model."
|
|
363
347
|
},
|
|
@@ -372,10 +356,7 @@
|
|
|
372
356
|
"description": "An optional name for the participant. Provides the model information to differentiate between participants of the same role."
|
|
373
357
|
},
|
|
374
358
|
"refusal": {
|
|
375
|
-
"type": [
|
|
376
|
-
"string",
|
|
377
|
-
"null"
|
|
378
|
-
],
|
|
359
|
+
"type": ["string", "null"],
|
|
379
360
|
"description": "The refusal message by the assistant."
|
|
380
361
|
},
|
|
381
362
|
"tool_calls": {
|
|
@@ -399,10 +380,7 @@
|
|
|
399
380
|
"description": "The name of the function to call."
|
|
400
381
|
}
|
|
401
382
|
},
|
|
402
|
-
"required": [
|
|
403
|
-
"arguments",
|
|
404
|
-
"name"
|
|
405
|
-
],
|
|
383
|
+
"required": ["arguments", "name"],
|
|
406
384
|
"additionalProperties": false,
|
|
407
385
|
"description": "The function that the model called."
|
|
408
386
|
},
|
|
@@ -412,19 +390,13 @@
|
|
|
412
390
|
"description": "The type of the tool. Currently, only `function` is supported."
|
|
413
391
|
}
|
|
414
392
|
},
|
|
415
|
-
"required": [
|
|
416
|
-
"id",
|
|
417
|
-
"function",
|
|
418
|
-
"type"
|
|
419
|
-
],
|
|
393
|
+
"required": ["id", "function", "type"],
|
|
420
394
|
"additionalProperties": false
|
|
421
395
|
},
|
|
422
396
|
"description": "The tool calls generated by the model, such as function calls."
|
|
423
397
|
}
|
|
424
398
|
},
|
|
425
|
-
"required": [
|
|
426
|
-
"role"
|
|
427
|
-
],
|
|
399
|
+
"required": ["role"],
|
|
428
400
|
"additionalProperties": false,
|
|
429
401
|
"description": "Messages sent by the model in response to user messages."
|
|
430
402
|
},
|
|
@@ -451,10 +423,7 @@
|
|
|
451
423
|
"description": "The type of the content part."
|
|
452
424
|
}
|
|
453
425
|
},
|
|
454
|
-
"required": [
|
|
455
|
-
"text",
|
|
456
|
-
"type"
|
|
457
|
-
],
|
|
426
|
+
"required": ["text", "type"],
|
|
458
427
|
"additionalProperties": false,
|
|
459
428
|
"description": "Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation)."
|
|
460
429
|
}
|
|
@@ -472,21 +441,14 @@
|
|
|
472
441
|
"description": "Tool call that this message is responding to."
|
|
473
442
|
}
|
|
474
443
|
},
|
|
475
|
-
"required": [
|
|
476
|
-
"content",
|
|
477
|
-
"role",
|
|
478
|
-
"tool_call_id"
|
|
479
|
-
],
|
|
444
|
+
"required": ["content", "role", "tool_call_id"],
|
|
480
445
|
"additionalProperties": false
|
|
481
446
|
},
|
|
482
447
|
{
|
|
483
448
|
"type": "object",
|
|
484
449
|
"properties": {
|
|
485
450
|
"content": {
|
|
486
|
-
"type": [
|
|
487
|
-
"string",
|
|
488
|
-
"null"
|
|
489
|
-
],
|
|
451
|
+
"type": ["string", "null"],
|
|
490
452
|
"description": "The contents of the function message."
|
|
491
453
|
},
|
|
492
454
|
"name": {
|
|
@@ -499,11 +461,7 @@
|
|
|
499
461
|
"description": "The role of the messages author, in this case `function`."
|
|
500
462
|
}
|
|
501
463
|
},
|
|
502
|
-
"required": [
|
|
503
|
-
"content",
|
|
504
|
-
"name",
|
|
505
|
-
"role"
|
|
506
|
-
],
|
|
464
|
+
"required": ["content", "name", "role"],
|
|
507
465
|
"additionalProperties": false,
|
|
508
466
|
"deprecated": true
|
|
509
467
|
}
|
|
@@ -524,10 +482,7 @@
|
|
|
524
482
|
"type": "array",
|
|
525
483
|
"items": {
|
|
526
484
|
"type": "string",
|
|
527
|
-
"enum": [
|
|
528
|
-
"text",
|
|
529
|
-
"audio"
|
|
530
|
-
]
|
|
485
|
+
"enum": ["text", "audio"]
|
|
531
486
|
},
|
|
532
487
|
"description": "Output types that you would like the model to generate for this request. Most models are capable of generating text, which is the default:\n\n`[\"text\"]`\n\nThe `gpt-4o-audio-preview` model can also be used to [generate audio](https://platform.openai.com/docs/guides/audio). To request that this model generate both text and audio responses, you can use:\n\n`[\"text\", \"audio\"]`"
|
|
533
488
|
},
|
|
@@ -536,43 +491,48 @@
|
|
|
536
491
|
"properties": {
|
|
537
492
|
"format": {
|
|
538
493
|
"type": "string",
|
|
539
|
-
"enum": [
|
|
540
|
-
"wav",
|
|
541
|
-
"mp3",
|
|
542
|
-
"flac",
|
|
543
|
-
"opus",
|
|
544
|
-
"pcm16"
|
|
545
|
-
],
|
|
494
|
+
"enum": ["wav", "aac", "mp3", "flac", "opus", "pcm16"],
|
|
546
495
|
"description": "Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`, `opus`, or `pcm16`."
|
|
547
496
|
},
|
|
548
497
|
"voice": {
|
|
549
|
-
"
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
498
|
+
"anyOf": [
|
|
499
|
+
{
|
|
500
|
+
"type": "string"
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
"type": "string",
|
|
504
|
+
"enum": [
|
|
505
|
+
"alloy",
|
|
506
|
+
"ash",
|
|
507
|
+
"ballad",
|
|
508
|
+
"coral",
|
|
509
|
+
"echo",
|
|
510
|
+
"fable",
|
|
511
|
+
"onyx",
|
|
512
|
+
"nova",
|
|
513
|
+
"sage",
|
|
514
|
+
"shimmer",
|
|
515
|
+
"verse"
|
|
516
|
+
]
|
|
517
|
+
}
|
|
559
518
|
],
|
|
560
|
-
"description": "The voice the model uses to respond. Supported voices are `ash`, `ballad`, `coral`, `
|
|
519
|
+
"description": "The voice the model uses to respond. Supported voices are `alloy`, `ash`, `ballad`, `coral`, `echo`, `fable`, `nova`, `onyx`, `sage`, and `shimmer`."
|
|
561
520
|
}
|
|
562
521
|
},
|
|
563
|
-
"required": [
|
|
564
|
-
"format",
|
|
565
|
-
"voice"
|
|
566
|
-
],
|
|
522
|
+
"required": ["format", "voice"],
|
|
567
523
|
"additionalProperties": false,
|
|
568
524
|
"description": "Parameters for audio output. Required when audio output is requested with `modalities: [\"audio\"]`. [Learn more](https://platform.openai.com/docs/guides/audio)."
|
|
569
525
|
},
|
|
570
526
|
"reasoningEffort": {
|
|
571
|
-
"
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
527
|
+
"anyOf": [
|
|
528
|
+
{
|
|
529
|
+
"type": ["string", "null"],
|
|
530
|
+
"enum": ["low", "medium", "high", null],
|
|
531
|
+
"description": "**o-series models only**\n\nConstrains effort on reasoning for [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently supported values are `low`, `medium`, and `high`. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response."
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
"type": "null"
|
|
535
|
+
}
|
|
576
536
|
],
|
|
577
537
|
"description": "Constrains effort on reasoning for reasoning models. Currently supported values are low, medium, and high. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response."
|
|
578
538
|
},
|
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
import { CompletionHandler, IInlineCompletionContext } from '@jupyterlab/completer';
|
|
2
2
|
import { ChatWebLLM } from '@langchain/community/chat_models/webllm';
|
|
3
|
-
import { BaseCompleter
|
|
4
|
-
export declare class WebLLMCompleter
|
|
3
|
+
import { BaseCompleter } from '../../base-completer';
|
|
4
|
+
export declare class WebLLMCompleter extends BaseCompleter {
|
|
5
5
|
constructor(options: BaseCompleter.IOptions);
|
|
6
6
|
/**
|
|
7
7
|
* Initialize the WebLLM model
|
|
8
8
|
*/
|
|
9
9
|
private _initializeModel;
|
|
10
|
-
/**
|
|
11
|
-
* Getter and setter for the initial prompt.
|
|
12
|
-
*/
|
|
13
|
-
get prompt(): string;
|
|
14
|
-
set prompt(value: string);
|
|
15
10
|
get provider(): ChatWebLLM;
|
|
16
11
|
fetch(request: CompletionHandler.IRequest, context: IInlineCompletionContext): Promise<{
|
|
17
12
|
items: {
|
|
18
13
|
insertText: string;
|
|
19
14
|
}[];
|
|
20
15
|
}>;
|
|
21
|
-
|
|
22
|
-
private _prompt;
|
|
16
|
+
protected _completer: ChatWebLLM;
|
|
23
17
|
private _isInitialized;
|
|
24
18
|
private _isInitializing;
|
|
25
19
|
private _initError;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
2
|
import { ChatWebLLM } from '@langchain/community/chat_models/webllm';
|
|
3
|
-
import {
|
|
3
|
+
import { BaseCompleter } from '../../base-completer';
|
|
4
4
|
/**
|
|
5
5
|
* Regular expression to match the '```' string at the start of a string.
|
|
6
6
|
* So the completions returned by the LLM can still be kept after removing the code block formatting.
|
|
@@ -20,8 +20,9 @@ const CODE_BLOCK_START_REGEX = /^```(?:[a-zA-Z]+)?\n?/;
|
|
|
20
20
|
* Regular expression to match the '```' string at the end of a string.
|
|
21
21
|
*/
|
|
22
22
|
const CODE_BLOCK_END_REGEX = /```$/;
|
|
23
|
-
export class WebLLMCompleter {
|
|
23
|
+
export class WebLLMCompleter extends BaseCompleter {
|
|
24
24
|
constructor(options) {
|
|
25
|
+
super(options);
|
|
25
26
|
const model = options.settings.model;
|
|
26
27
|
// provide model separately since ChatWebLLM expects it
|
|
27
28
|
this._completer = new ChatWebLLM({
|
|
@@ -57,15 +58,6 @@ export class WebLLMCompleter {
|
|
|
57
58
|
console.error('Failed to initialize WebLLM model:', error);
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
|
-
/**
|
|
61
|
-
* Getter and setter for the initial prompt.
|
|
62
|
-
*/
|
|
63
|
-
get prompt() {
|
|
64
|
-
return this._prompt;
|
|
65
|
-
}
|
|
66
|
-
set prompt(value) {
|
|
67
|
-
this._prompt = value;
|
|
68
|
-
}
|
|
69
61
|
get provider() {
|
|
70
62
|
return this._completer;
|
|
71
63
|
}
|
|
@@ -99,7 +91,7 @@ export class WebLLMCompleter {
|
|
|
99
91
|
const prompt = text.slice(0, cursorOffset);
|
|
100
92
|
const trimmedPrompt = prompt.trim();
|
|
101
93
|
const messages = [
|
|
102
|
-
new SystemMessage(this.
|
|
94
|
+
new SystemMessage(this.systemPrompt),
|
|
103
95
|
new HumanMessage(trimmedPrompt)
|
|
104
96
|
];
|
|
105
97
|
try {
|
|
@@ -128,7 +120,6 @@ export class WebLLMCompleter {
|
|
|
128
120
|
}
|
|
129
121
|
}
|
|
130
122
|
_completer;
|
|
131
|
-
_prompt = COMPLETION_SYSTEM_PROMPT;
|
|
132
123
|
_isInitialized = false;
|
|
133
124
|
_isInitializing = false;
|
|
134
125
|
_initError = null;
|
|
@@ -2,12 +2,14 @@ import { Notification } from '@jupyterlab/apputils';
|
|
|
2
2
|
import { ChatAnthropic } from '@langchain/anthropic';
|
|
3
3
|
import { ChatWebLLM } from '@langchain/community/chat_models/webllm';
|
|
4
4
|
import { ChromeAI } from '@langchain/community/experimental/llms/chrome_ai';
|
|
5
|
+
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
|
|
5
6
|
import { ChatMistralAI } from '@langchain/mistralai';
|
|
6
7
|
import { ChatOllama } from '@langchain/ollama';
|
|
7
8
|
import { ChatOpenAI } from '@langchain/openai';
|
|
8
9
|
// Import completers
|
|
9
10
|
import { AnthropicCompleter } from './Anthropic/completer';
|
|
10
11
|
import { ChromeCompleter } from './ChromeAI/completer';
|
|
12
|
+
import { GeminiCompleter } from './Gemini/completer';
|
|
11
13
|
import { CodestralCompleter } from './MistralAI/completer';
|
|
12
14
|
import { OllamaCompleter } from './Ollama/completer';
|
|
13
15
|
import { OpenAICompleter } from './OpenAI/completer';
|
|
@@ -15,12 +17,14 @@ import { WebLLMCompleter } from './WebLLM/completer';
|
|
|
15
17
|
// Import Settings
|
|
16
18
|
import AnthropicSettings from './Anthropic/settings-schema.json';
|
|
17
19
|
import ChromeAISettings from './ChromeAI/settings-schema.json';
|
|
20
|
+
import GeminiSettings from './Gemini/settings-schema.json';
|
|
18
21
|
import MistralAISettings from './MistralAI/settings-schema.json';
|
|
19
22
|
import OllamaAISettings from './Ollama/settings-schema.json';
|
|
20
23
|
import OpenAISettings from './OpenAI/settings-schema.json';
|
|
21
24
|
import WebLLMSettings from './WebLLM/settings-schema.json';
|
|
22
25
|
// Import instructions
|
|
23
26
|
import ChromeAIInstructions, { compatibilityCheck as chromeAICompatibilityCheck } from './ChromeAI/instructions';
|
|
27
|
+
import GeminiInstructions from './Gemini/instructions';
|
|
24
28
|
import MistralAIInstructions from './MistralAI/instructions';
|
|
25
29
|
import OllamaInstructions from './Ollama/instructions';
|
|
26
30
|
import WebLLMInstructions, { compatibilityCheck as webLLMCompatibilityCheck } from './WebLLM/instructions';
|
|
@@ -30,7 +34,7 @@ import { IAIProviderRegistry } from '../tokens';
|
|
|
30
34
|
const AIProviders = [
|
|
31
35
|
{
|
|
32
36
|
name: 'Anthropic',
|
|
33
|
-
|
|
37
|
+
chat: ChatAnthropic,
|
|
34
38
|
completer: AnthropicCompleter,
|
|
35
39
|
settingsSchema: AnthropicSettings,
|
|
36
40
|
errorMessage: (error) => error.error.error.message
|
|
@@ -39,7 +43,7 @@ const AIProviders = [
|
|
|
39
43
|
name: 'ChromeAI',
|
|
40
44
|
// TODO: fix
|
|
41
45
|
// @ts-expect-error: missing properties
|
|
42
|
-
|
|
46
|
+
chat: ChromeAI,
|
|
43
47
|
completer: ChromeCompleter,
|
|
44
48
|
instructions: ChromeAIInstructions,
|
|
45
49
|
settingsSchema: ChromeAISettings,
|
|
@@ -47,21 +51,28 @@ const AIProviders = [
|
|
|
47
51
|
},
|
|
48
52
|
{
|
|
49
53
|
name: 'MistralAI',
|
|
50
|
-
|
|
54
|
+
chat: ChatMistralAI,
|
|
51
55
|
completer: CodestralCompleter,
|
|
52
56
|
instructions: MistralAIInstructions,
|
|
53
57
|
settingsSchema: MistralAISettings
|
|
54
58
|
},
|
|
55
59
|
{
|
|
56
60
|
name: 'Ollama',
|
|
57
|
-
|
|
61
|
+
chat: ChatOllama,
|
|
58
62
|
completer: OllamaCompleter,
|
|
59
63
|
instructions: OllamaInstructions,
|
|
60
64
|
settingsSchema: OllamaAISettings
|
|
61
65
|
},
|
|
66
|
+
{
|
|
67
|
+
name: 'Gemini',
|
|
68
|
+
chat: ChatGoogleGenerativeAI,
|
|
69
|
+
completer: GeminiCompleter,
|
|
70
|
+
instructions: GeminiInstructions,
|
|
71
|
+
settingsSchema: GeminiSettings
|
|
72
|
+
},
|
|
62
73
|
{
|
|
63
74
|
name: 'OpenAI',
|
|
64
|
-
|
|
75
|
+
chat: ChatOpenAI,
|
|
65
76
|
completer: OpenAICompleter,
|
|
66
77
|
settingsSchema: OpenAISettings
|
|
67
78
|
}
|
|
@@ -78,30 +89,23 @@ const webLLMProviderPlugin = {
|
|
|
78
89
|
activate: (app, registry) => {
|
|
79
90
|
registry.add({
|
|
80
91
|
name: 'WebLLM',
|
|
81
|
-
|
|
92
|
+
chat: ChatWebLLM,
|
|
82
93
|
completer: WebLLMCompleter,
|
|
83
94
|
settingsSchema: WebLLMSettings,
|
|
84
95
|
instructions: WebLLMInstructions,
|
|
85
96
|
compatibilityCheck: webLLMCompatibilityCheck,
|
|
86
97
|
exposeChatModel: true
|
|
87
98
|
});
|
|
88
|
-
registry.providerChanged.connect(async (sender,
|
|
89
|
-
const {
|
|
90
|
-
if (currentChatModel === null) {
|
|
91
|
-
Notification.emit(chatError, 'error', {
|
|
92
|
-
autoClose: 2000
|
|
93
|
-
});
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
99
|
+
registry.providerChanged.connect(async (sender, role) => {
|
|
100
|
+
const { currentChatModel } = registry;
|
|
96
101
|
// TODO: implement a proper way to handle models that may need to be initialized before being used.
|
|
97
102
|
// Mostly applies to WebLLM and ChromeAI as they may need to download the model in the browser first.
|
|
98
|
-
if (currentName === 'WebLLM') {
|
|
103
|
+
if (registry.currentName(role) === 'WebLLM') {
|
|
104
|
+
// Leaving this check here, but it should never happen, this check is done in
|
|
105
|
+
// the provider registry, and the current name is set to 'None' if there is a
|
|
106
|
+
// compatibility error.
|
|
99
107
|
const compatibilityError = await webLLMCompatibilityCheck();
|
|
100
108
|
if (compatibilityError) {
|
|
101
|
-
Notification.dismiss();
|
|
102
|
-
Notification.emit(compatibilityError, 'error', {
|
|
103
|
-
autoClose: 2000
|
|
104
|
-
});
|
|
105
109
|
return;
|
|
106
110
|
}
|
|
107
111
|
const model = currentChatModel;
|
package/lib/index.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ import { IAIProviderRegistry } from './tokens';
|
|
|
4
4
|
declare const _default: (JupyterFrontEndPlugin<void> | JupyterFrontEndPlugin<IChatCommandRegistry> | JupyterFrontEndPlugin<IAIProviderRegistry>)[];
|
|
5
5
|
export default _default;
|
|
6
6
|
export { IAIProviderRegistry } from './tokens';
|
|
7
|
+
export * from './base-completer';
|