@jupyterlite/ai 0.3.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.
Files changed (42) hide show
  1. package/lib/chat-handler.d.ts +3 -3
  2. package/lib/chat-handler.js +13 -10
  3. package/lib/completion-provider.d.ts +5 -18
  4. package/lib/completion-provider.js +8 -34
  5. package/lib/index.d.ts +2 -2
  6. package/lib/index.js +44 -42
  7. package/lib/llm-models/index.d.ts +3 -2
  8. package/lib/llm-models/index.js +42 -2
  9. package/lib/provider.d.ts +44 -16
  10. package/lib/provider.js +97 -41
  11. package/lib/settings/instructions.d.ts +2 -0
  12. package/lib/settings/instructions.js +44 -0
  13. package/lib/settings/panel.d.ts +70 -0
  14. package/lib/settings/panel.js +190 -0
  15. package/lib/settings/schemas/base.json +7 -0
  16. package/lib/settings/schemas/index.d.ts +3 -0
  17. package/lib/settings/schemas/index.js +11 -0
  18. package/lib/tokens.d.ts +103 -0
  19. package/lib/tokens.js +5 -0
  20. package/package.json +5 -1
  21. package/schema/provider-registry.json +17 -0
  22. package/src/chat-handler.ts +16 -13
  23. package/src/completion-provider.ts +13 -37
  24. package/src/index.ts +59 -44
  25. package/src/llm-models/index.ts +49 -2
  26. package/src/provider.ts +100 -43
  27. package/src/settings/instructions.ts +48 -0
  28. package/src/settings/panel.tsx +257 -0
  29. package/src/settings/schemas/index.ts +15 -0
  30. package/src/tokens.ts +112 -0
  31. package/style/base.css +4 -0
  32. package/lib/llm-models/utils.d.ts +0 -16
  33. package/lib/llm-models/utils.js +0 -86
  34. package/lib/token.d.ts +0 -13
  35. package/lib/token.js +0 -2
  36. package/schema/ai-provider.json +0 -17
  37. package/src/llm-models/utils.ts +0 -90
  38. package/src/token.ts +0 -19
  39. /package/lib/{_provider-settings/anthropic.json → settings/schemas/_generated/Anthropic.json} +0 -0
  40. /package/lib/{_provider-settings/chromeAI.json → settings/schemas/_generated/ChromeAI.json} +0 -0
  41. /package/lib/{_provider-settings/mistralAI.json → settings/schemas/_generated/MistralAI.json} +0 -0
  42. /package/lib/{_provider-settings/openAI.json → settings/schemas/_generated/OpenAI.json} +0 -0
@@ -0,0 +1,257 @@
1
+ import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
2
+ import { ISettingRegistry } from '@jupyterlab/settingregistry';
3
+ import { FormComponent, IFormRenderer } from '@jupyterlab/ui-components';
4
+ import { JSONExt } from '@lumino/coreutils';
5
+ import { IChangeEvent } from '@rjsf/core';
6
+ import type { FieldProps } from '@rjsf/utils';
7
+ import validator from '@rjsf/validator-ajv8';
8
+ import { JSONSchema7 } from 'json-schema';
9
+ import React from 'react';
10
+
11
+ import baseSettings from './schemas/base.json';
12
+ import { IAIProviderRegistry, IDict } from '../tokens';
13
+
14
+ const MD_MIME_TYPE = 'text/markdown';
15
+ const STORAGE_NAME = '@jupyterlite/ai:settings';
16
+ const INSTRUCTION_CLASS = 'jp-AISettingsInstructions';
17
+
18
+ export const aiSettingsRenderer = (options: {
19
+ providerRegistry: IAIProviderRegistry;
20
+ rmRegistry?: IRenderMimeRegistry;
21
+ }): IFormRenderer => {
22
+ return {
23
+ fieldRenderer: (props: FieldProps) => {
24
+ props.formContext = { ...props.formContext, ...options };
25
+ return <AiSettings {...props} />;
26
+ }
27
+ };
28
+ };
29
+
30
+ export interface ISettingsFormStates {
31
+ schema: JSONSchema7;
32
+ instruction: HTMLElement | null;
33
+ }
34
+
35
+ const WrappedFormComponent = (props: any): JSX.Element => {
36
+ return <FormComponent {...props} validator={validator} />;
37
+ };
38
+
39
+ export class AiSettings extends React.Component<
40
+ FieldProps,
41
+ ISettingsFormStates
42
+ > {
43
+ constructor(props: FieldProps) {
44
+ super(props);
45
+ if (!props.formContext.providerRegistry) {
46
+ throw new Error(
47
+ 'The provider registry is needed to enable the jupyterlite-ai settings panel'
48
+ );
49
+ }
50
+ this._providerRegistry = props.formContext.providerRegistry;
51
+ this._rmRegistry = props.formContext.rmRegistry ?? null;
52
+ this._settings = props.formContext.settings;
53
+
54
+ // Initialize the providers schema.
55
+ const providerSchema = JSONExt.deepCopy(baseSettings) as any;
56
+ providerSchema.properties.provider = {
57
+ type: 'string',
58
+ title: 'Provider',
59
+ description: 'The AI provider to use for chat and completion',
60
+ default: 'None',
61
+ enum: ['None'].concat(this._providerRegistry.providers)
62
+ };
63
+ this._providerSchema = providerSchema as JSONSchema7;
64
+
65
+ // Check if there is saved values in local storage, otherwise use the settings from
66
+ // the setting registry (led to default if there are no user settings).
67
+ const storageSettings = localStorage.getItem(STORAGE_NAME);
68
+ if (storageSettings === null) {
69
+ const labSettings = this._settings.get('AIprovider').composite;
70
+ if (labSettings && Object.keys(labSettings).includes('provider')) {
71
+ // Get the provider name.
72
+ const provider = Object.entries(labSettings).find(
73
+ v => v[0] === 'provider'
74
+ )?.[1] as string;
75
+ // Save the settings.
76
+ const settings: any = {
77
+ _current: provider
78
+ };
79
+ settings[provider] = labSettings;
80
+ localStorage.setItem(STORAGE_NAME, JSON.stringify(settings));
81
+ }
82
+ }
83
+
84
+ // Initialize the settings from the saved ones.
85
+ this._provider = this.getCurrentProvider();
86
+ this._currentSettings = this.getSettings();
87
+
88
+ // Initialize the schema.
89
+ const schema = this._buildSchema();
90
+ this.state = { schema, instruction: null };
91
+
92
+ this._renderInstruction();
93
+
94
+ // Update the setting registry.
95
+ this._settings
96
+ .set('AIprovider', this._currentSettings)
97
+ .catch(console.error);
98
+ }
99
+
100
+ /**
101
+ * Get the current provider from the local storage.
102
+ */
103
+ getCurrentProvider(): string {
104
+ const settings = JSON.parse(localStorage.getItem(STORAGE_NAME) || '{}');
105
+ return settings['_current'] ?? 'None';
106
+ }
107
+
108
+ /**
109
+ * Save the current provider to the local storage.
110
+ */
111
+ saveCurrentProvider(): void {
112
+ const settings = JSON.parse(localStorage.getItem(STORAGE_NAME) || '{}');
113
+ settings['_current'] = this._provider;
114
+ localStorage.setItem(STORAGE_NAME, JSON.stringify(settings));
115
+ }
116
+
117
+ /**
118
+ * Get settings from local storage for a given provider.
119
+ */
120
+ getSettings(): IDict<any> {
121
+ const settings = JSON.parse(localStorage.getItem(STORAGE_NAME) || '{}');
122
+ return settings[this._provider] ?? { provider: this._provider };
123
+ }
124
+
125
+ /**
126
+ * Save settings in local storage for a given provider.
127
+ */
128
+ saveSettings(value: IDict<any>) {
129
+ const settings = JSON.parse(localStorage.getItem(STORAGE_NAME) ?? '{}');
130
+ settings[this._provider] = value;
131
+ localStorage.setItem(STORAGE_NAME, JSON.stringify(settings));
132
+ }
133
+
134
+ /**
135
+ * Update the UI schema of the form.
136
+ * Currently use to hide API keys.
137
+ */
138
+ private _updateUiSchema(key: string) {
139
+ if (key.toLowerCase().includes('key')) {
140
+ this._uiSchema[key] = { 'ui:widget': 'password' };
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Build the schema for a given provider.
146
+ */
147
+ private _buildSchema(): JSONSchema7 {
148
+ const schema = JSONExt.deepCopy(baseSettings) as any;
149
+ this._uiSchema = {};
150
+ const settingsSchema = this._providerRegistry.getSettingsSchema(
151
+ this._provider
152
+ );
153
+
154
+ if (settingsSchema) {
155
+ Object.entries(settingsSchema).forEach(([key, value]) => {
156
+ schema.properties[key] = value;
157
+ this._updateUiSchema(key);
158
+ });
159
+ }
160
+ return schema as JSONSchema7;
161
+ }
162
+
163
+ /**
164
+ * Update the schema state for the given provider, that trigger the re-rendering of
165
+ * the component.
166
+ */
167
+ private _updateSchema() {
168
+ const schema = this._buildSchema();
169
+ this.setState({ schema });
170
+ }
171
+
172
+ /**
173
+ * Render the markdown instructions for the current provider.
174
+ */
175
+ private async _renderInstruction(): Promise<void> {
176
+ let instructions = this._providerRegistry.getInstructions(this._provider);
177
+ if (!this._rmRegistry || !instructions) {
178
+ this.setState({ instruction: null });
179
+ return;
180
+ }
181
+ instructions = `---\n\n${instructions}\n\n---`;
182
+ const renderer = this._rmRegistry.createRenderer(MD_MIME_TYPE);
183
+ const model = this._rmRegistry.createModel({
184
+ data: { [MD_MIME_TYPE]: instructions }
185
+ });
186
+ await renderer.renderModel(model);
187
+ this.setState({ instruction: renderer.node });
188
+ }
189
+
190
+ /**
191
+ * Triggered when the provider hes changed, to update the schema and values.
192
+ * Update the Jupyterlab settings accordingly.
193
+ */
194
+ private _onProviderChanged = (e: IChangeEvent) => {
195
+ const provider = e.formData.provider;
196
+ if (provider === this._currentSettings.provider) {
197
+ return;
198
+ }
199
+ this._provider = provider;
200
+ this.saveCurrentProvider();
201
+ this._currentSettings = this.getSettings();
202
+ this._updateSchema();
203
+ this._renderInstruction();
204
+ this._settings
205
+ .set('AIprovider', { provider: this._provider, ...this._currentSettings })
206
+ .catch(console.error);
207
+ };
208
+
209
+ /**
210
+ * Triggered when the form value has changed, to update the current settings and save
211
+ * it in local storage.
212
+ * Update the Jupyterlab settings accordingly.
213
+ */
214
+ private _onFormChange = (e: IChangeEvent) => {
215
+ this._currentSettings = JSONExt.deepCopy(e.formData);
216
+ this.saveSettings(this._currentSettings);
217
+ this._settings
218
+ .set('AIprovider', { provider: this._provider, ...this._currentSettings })
219
+ .catch(console.error);
220
+ };
221
+
222
+ render(): JSX.Element {
223
+ return (
224
+ <>
225
+ <WrappedFormComponent
226
+ formData={{ provider: this._provider }}
227
+ schema={this._providerSchema}
228
+ onChange={this._onProviderChanged}
229
+ />
230
+ {this.state.instruction !== null && (
231
+ <details>
232
+ <summary className={INSTRUCTION_CLASS}>Instructions</summary>
233
+ <span
234
+ ref={node =>
235
+ node && node.replaceChildren(this.state.instruction!)
236
+ }
237
+ />
238
+ </details>
239
+ )}
240
+ <WrappedFormComponent
241
+ formData={this._currentSettings}
242
+ schema={this.state.schema}
243
+ onChange={this._onFormChange}
244
+ uiSchema={this._uiSchema}
245
+ />
246
+ </>
247
+ );
248
+ }
249
+
250
+ private _providerRegistry: IAIProviderRegistry;
251
+ private _provider: string;
252
+ private _providerSchema: JSONSchema7;
253
+ private _rmRegistry: IRenderMimeRegistry | null;
254
+ private _currentSettings: IDict<any> = { provider: 'None' };
255
+ private _uiSchema: IDict<any> = {};
256
+ private _settings: ISettingRegistry.ISettings;
257
+ }
@@ -0,0 +1,15 @@
1
+ import { IDict } from '../../tokens';
2
+
3
+ import ChromeAI from './_generated/ChromeAI.json';
4
+ import MistralAI from './_generated/MistralAI.json';
5
+ import Anthropic from './_generated/Anthropic.json';
6
+ import OpenAI from './_generated/OpenAI.json';
7
+
8
+ const ProviderSettings: IDict<any> = {
9
+ ChromeAI,
10
+ MistralAI,
11
+ Anthropic,
12
+ OpenAI
13
+ };
14
+
15
+ export { ProviderSettings };
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
@@ -5,3 +5,7 @@
5
5
  */
6
6
 
7
7
  @import url('@jupyter/chat/style/index.css');
8
+
9
+ .jp-AISettingsInstructions {
10
+ font-size: var(--jp-content-font-size1);
11
+ }
@@ -1,16 +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;
16
- export declare function getSettings(name: string): any;
@@ -1,86 +0,0 @@
1
- import { ChatAnthropic } from '@langchain/anthropic';
2
- import { ChromeAI } from '@langchain/community/experimental/llms/chrome_ai';
3
- import { ChatMistralAI } from '@langchain/mistralai';
4
- import { ChatOpenAI } from '@langchain/openai';
5
- import { AnthropicCompleter } from './anthropic-completer';
6
- import { CodestralCompleter } from './codestral-completer';
7
- import { ChromeCompleter } from './chrome-completer';
8
- import { OpenAICompleter } from './openai-completer';
9
- import chromeAI from '../_provider-settings/chromeAI.json';
10
- import mistralAI from '../_provider-settings/mistralAI.json';
11
- import anthropic from '../_provider-settings/anthropic.json';
12
- import openAI from '../_provider-settings/openAI.json';
13
- /**
14
- * Get an LLM completer from the name.
15
- */
16
- export function getCompleter(name, settings) {
17
- if (name === 'MistralAI') {
18
- return new CodestralCompleter({ settings });
19
- }
20
- else if (name === 'Anthropic') {
21
- return new AnthropicCompleter({ settings });
22
- }
23
- else if (name === 'ChromeAI') {
24
- return new ChromeCompleter({ settings });
25
- }
26
- else if (name === 'OpenAI') {
27
- return new OpenAICompleter({ settings });
28
- }
29
- return null;
30
- }
31
- /**
32
- * Get an LLM chat model from the name.
33
- */
34
- export function getChatModel(name, settings) {
35
- if (name === 'MistralAI') {
36
- return new ChatMistralAI({ ...settings });
37
- }
38
- else if (name === 'Anthropic') {
39
- return new ChatAnthropic({ ...settings });
40
- }
41
- else if (name === 'ChromeAI') {
42
- // TODO: fix
43
- // @ts-expect-error: missing properties
44
- return new ChromeAI({ ...settings });
45
- }
46
- else if (name === 'OpenAI') {
47
- return new ChatOpenAI({ ...settings });
48
- }
49
- return null;
50
- }
51
- /**
52
- * Get the error message from provider.
53
- */
54
- export function getErrorMessage(name, error) {
55
- if (name === 'MistralAI') {
56
- return error.message;
57
- }
58
- else if (name === 'Anthropic') {
59
- return error.error.error.message;
60
- }
61
- else if (name === 'ChromeAI') {
62
- return error.message;
63
- }
64
- else if (name === 'OpenAI') {
65
- return error.message;
66
- }
67
- return 'Unknown provider';
68
- }
69
- /*
70
- * Get an LLM completer from the name.
71
- */
72
- export function getSettings(name) {
73
- if (name === 'MistralAI') {
74
- return mistralAI.properties;
75
- }
76
- else if (name === 'Anthropic') {
77
- return anthropic.properties;
78
- }
79
- else if (name === 'ChromeAI') {
80
- return chromeAI.properties;
81
- }
82
- else if (name === 'OpenAI') {
83
- return openAI.properties;
84
- }
85
- return null;
86
- }
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
@@ -1,2 +0,0 @@
1
- import { Token } from '@lumino/coreutils';
2
- export const IAIProvider = new Token('@jupyterlite/ai:AIProvider', 'Provider for chat and completion LLM provider');
@@ -1,17 +0,0 @@
1
- {
2
- "title": "AI provider",
3
- "description": "Provider settings",
4
- "jupyter.lab.setting-icon": "@jupyterlite/ai:jupyternaut-lite",
5
- "jupyter.lab.setting-icon-label": "JupyterLite AI Chat",
6
- "type": "object",
7
- "properties": {
8
- "provider": {
9
- "type": "string",
10
- "title": "The AI provider",
11
- "description": "The AI provider to use for chat and completion",
12
- "default": "None",
13
- "enum": ["None", "Anthropic", "ChromeAI", "MistralAI", "OpenAI"]
14
- }
15
- },
16
- "additionalProperties": true
17
- }
@@ -1,90 +0,0 @@
1
- import { ChatAnthropic } from '@langchain/anthropic';
2
- import { ChromeAI } from '@langchain/community/experimental/llms/chrome_ai';
3
- import { BaseChatModel } from '@langchain/core/language_models/chat_models';
4
- import { ChatMistralAI } from '@langchain/mistralai';
5
- import { ChatOpenAI } from '@langchain/openai';
6
-
7
- import { IBaseCompleter } from './base-completer';
8
- import { AnthropicCompleter } from './anthropic-completer';
9
- import { CodestralCompleter } from './codestral-completer';
10
- import { ReadonlyPartialJSONObject } from '@lumino/coreutils';
11
- import { ChromeCompleter } from './chrome-completer';
12
- import { OpenAICompleter } from './openai-completer';
13
-
14
- import chromeAI from '../_provider-settings/chromeAI.json';
15
- import mistralAI from '../_provider-settings/mistralAI.json';
16
- import anthropic from '../_provider-settings/anthropic.json';
17
- import openAI from '../_provider-settings/openAI.json';
18
-
19
- /**
20
- * Get an LLM completer from the name.
21
- */
22
- export function getCompleter(
23
- name: string,
24
- settings: ReadonlyPartialJSONObject
25
- ): IBaseCompleter | null {
26
- if (name === 'MistralAI') {
27
- return new CodestralCompleter({ settings });
28
- } else if (name === 'Anthropic') {
29
- return new AnthropicCompleter({ settings });
30
- } else if (name === 'ChromeAI') {
31
- return new ChromeCompleter({ settings });
32
- } else if (name === 'OpenAI') {
33
- return new OpenAICompleter({ settings });
34
- }
35
- return null;
36
- }
37
-
38
- /**
39
- * Get an LLM chat model from the name.
40
- */
41
- export function getChatModel(
42
- name: string,
43
- settings: ReadonlyPartialJSONObject
44
- ): BaseChatModel | null {
45
- if (name === 'MistralAI') {
46
- return new ChatMistralAI({ ...settings });
47
- } else if (name === 'Anthropic') {
48
- return new ChatAnthropic({ ...settings });
49
- } else if (name === 'ChromeAI') {
50
- // TODO: fix
51
- // @ts-expect-error: missing properties
52
- return new ChromeAI({ ...settings });
53
- } else if (name === 'OpenAI') {
54
- return new ChatOpenAI({ ...settings });
55
- }
56
- return null;
57
- }
58
-
59
- /**
60
- * Get the error message from provider.
61
- */
62
- export function getErrorMessage(name: string, error: any): string {
63
- if (name === 'MistralAI') {
64
- return error.message;
65
- } else if (name === 'Anthropic') {
66
- return error.error.error.message;
67
- } else if (name === 'ChromeAI') {
68
- return error.message;
69
- } else if (name === 'OpenAI') {
70
- return error.message;
71
- }
72
- return 'Unknown provider';
73
- }
74
-
75
- /*
76
- * Get an LLM completer from the name.
77
- */
78
- export function getSettings(name: string): any {
79
- if (name === 'MistralAI') {
80
- return mistralAI.properties;
81
- } else if (name === 'Anthropic') {
82
- return anthropic.properties;
83
- } else if (name === 'ChromeAI') {
84
- return chromeAI.properties;
85
- } else if (name === 'OpenAI') {
86
- return openAI.properties;
87
- }
88
-
89
- return null;
90
- }
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
- );