Skip to content

Commit 2acd903

Browse files
committed
Make instructions usable from the provider registry
1 parent 1b26e6b commit 2acd903

File tree

6 files changed

+27
-11
lines changed

6 files changed

+27
-11
lines changed

scripts/settings-generator.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,19 @@ Object.entries(providers).forEach(([name, desc], index) => {
140140
});
141141

142142
// Build the index.ts file
143-
const indexContent = [];
143+
const indexContent = ['import { IDict } from \'../../token\';', ''];
144144
Object.keys(providers).forEach(name => {
145145
indexContent.push(`import ${name} from './_generated/${name}.json';`);
146146
});
147147

148-
indexContent.push('', 'const ProviderSettings: { [name: string]: any } = {');
148+
indexContent.push('', 'const ProviderSettings: IDict<any> = {');
149149

150150
Object.keys(providers).forEach((name, index) => {
151151
indexContent.push(
152152
` ${name}` + (index < Object.keys(providers).length - 1 ? ',' : '')
153153
);
154154
});
155-
indexContent.push('};', '', 'export default ProviderSettings;', '');
155+
indexContent.push('};', '', 'export { ProviderSettings };', '');
156156
fs.writeFile(
157157
path.join(schemasDir, 'index.ts'),
158158
indexContent.join('\n'),

src/llm-models/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { CodestralCompleter } from './codestral-completer';
88
import { ChromeCompleter } from './chrome-completer';
99
import { OpenAICompleter } from './openai-completer';
1010

11-
import ProviderSettings from '../settings/schemas';
11+
import { instructions } from '../settings/instructions';
12+
import { ProviderSettings } from '../settings/schemas';
1213

1314
import { IAIProvider } from '../token';
1415

@@ -28,12 +29,14 @@ const AIProviders: IAIProvider[] = [
2829
// @ts-expect-error: missing properties
2930
chatModel: ChromeAI,
3031
completer: ChromeCompleter,
32+
instructions: instructions.ChromeAI,
3133
settings: ProviderSettings.ChromeAI
3234
},
3335
{
3436
name: 'MistralAI',
3537
chatModel: ChatMistralAI,
3638
completer: CodestralCompleter,
39+
instructions: instructions.MistralAI,
3740
settings: ProviderSettings.MistralAI
3841
},
3942
{

src/provider.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,20 @@ export class AIProviderRegistry implements IAIProviderRegistry {
7878
}
7979

8080
/**
81-
* Get the settings schema.
81+
* Get the settings schema of a given provider.
8282
*/
83-
settingsSchema(provider: string): JSONSchema7 {
83+
getSettingsSchema(provider: string): JSONSchema7 {
8484
return (this._providers.get(provider)?.settings?.properties ||
8585
{}) as JSONSchema7;
8686
}
8787

88+
/**
89+
* Get the instructions of a given provider.
90+
*/
91+
getInstructions(provider: string): string | undefined {
92+
return this._providers.get(provider)?.instructions;
93+
}
94+
8895
/**
8996
* Format an error message from a provider.
9097
*/

src/settings/instructions.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
export interface IDict<T = any> {
2-
[key: string]: T;
3-
}
1+
import { IDict } from '../token';
42

53
const chromeAiInstructions = `
64
<i class="fas fa-exclamation-triangle"></i> Support for ChromeAI is still experimental and only available in Google Chrome.

src/settings/panel.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import validator from '@rjsf/validator-ajv8';
88
import { JSONSchema7 } from 'json-schema';
99
import React from 'react';
1010

11-
import { IDict, instructions } from './instructions';
11+
import { instructions } from './instructions';
1212
import baseSettings from './schemas/base.json';
13-
import ProviderSettings from './schemas';
13+
import { ProviderSettings } from './schemas';
14+
import { IDict } from '../token';
1415

1516
const MD_MIME_TYPE = 'text/markdown';
1617
const STORAGE_NAME = '@jupyterlite/ai:settings';

src/token.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
22
import { Token } from '@lumino/coreutils';
33
import { ISignal } from '@lumino/signaling';
4+
import { JSONSchema7 } from 'json-schema';
45

56
import { IBaseCompleter } from './llm-models';
67

8+
export interface IDict<T = any> {
9+
[key: string]: T;
10+
}
11+
712
export interface IType<T> {
813
new (...args: any[]): T;
914
}
@@ -24,6 +29,8 @@ export interface IAIProviderRegistry {
2429
name: string;
2530
completer: IBaseCompleter | null;
2631
chatModel: BaseChatModel | null;
32+
getSettingsSchema(provider: string): JSONSchema7;
33+
getInstructions(provider: string): string | undefined;
2734
formatErrorMessage(error: any): string;
2835
providerChanged: ISignal<IAIProviderRegistry, void>;
2936
chatError: string;

0 commit comments

Comments
 (0)