Skip to content

Test settings #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,24 @@ jobs:
path: |
ui-tests/test-results
ui-tests/playwright-report

js:
name: js
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Base Setup
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1

- name: Install nodejs dependencies
run: |
set -eux
pip install "jupyterlab>=4.4.0"
jlpm install

- name: Execute tests
run: |
jlpm test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,6 @@ Untitled*.ipynb
# Integration tests
ui-tests/test-results/
ui-tests/playwright-report/

# jest test reports
junit.xml
6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* Copyright (c) Jupyter Development Team.
* Distributed under the terms of the Modified BSD License.
*/

module.exports = require('@jupyterlab/testing/lib/babel-config');
30 changes: 30 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) Jupyter Development Team.
* Distributed under the terms of the Modified BSD License.
*/

const jestJupyterLab = require('@jupyterlab/testing/lib/jest-config');

const esModules = [
'@codemirror',
'@jupyterlab/',
'exenv-es6',
'lib0',
'nanoid',
'vscode-ws-jsonrpc'
].join('|');

const baseConfig = jestJupyterLab(__dirname);

module.exports = {
...baseConfig,
automock: false,
collectCoverageFrom: [
'src/**/*.{ts,tsx}',
'!src/**/*.d.ts',
'!src/**/.ipynb_checkpoints/*'
],
coverageReporters: ['lcov', 'text'],
testRegex: 'src/.*/.*.spec.ts[x]?$',
transformIgnorePatterns: [`/node_modules/(?!${esModules}).+`]
};
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"settings:check": "node ./scripts/settings-checker.js",
"stylelint": "jlpm stylelint:check --fix",
"stylelint:check": "stylelint --cache \"style/**/*.css\"",
"test": "jest --coverage",
"watch": "run-p watch:src watch:labextension",
"watch:src": "tsc -w --sourceMap",
"watch:labextension": "jupyter labextension watch ."
Expand Down Expand Up @@ -90,8 +91,10 @@
},
"devDependencies": {
"@jupyterlab/builder": "^4.4.0",
"@jupyterlab/testing": "^4.4.0",
"@stylistic/eslint-plugin": "^3.0.1",
"@types/chrome": "^0.0.304",
"@types/jest": "^29.2.0",
"@types/json-schema": "^7.0.11",
"@types/react": "^18.0.26",
"@types/react-addons-linked-state-mixin": "^0.14.22",
Expand All @@ -102,6 +105,8 @@
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.2.0",
"json-schema-library": "^10.1.2",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.0",
"rimraf": "^5.0.1",
Expand Down
100 changes: 100 additions & 0 deletions src/__tests__/provider-settings.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { compileSchema, SchemaNode } from 'json-schema-library';
import { ReadableStream } from 'web-streams-polyfill';
// @ts-expect-error
globalThis.ReadableStream = ReadableStream;
// if (typeof global.ReadableStream === undefined) {
// global.ReadableStream = ReadableStream;
// }

import { ChatAnthropic } from '@langchain/anthropic';
// import { ChatWebLLM } from '@langchain/community/chat_models/webllm';
import { ChromeAI } from '@langchain/community/experimental/llms/chrome_ai';
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
import { ChatMistralAI } from '@langchain/mistralai';
import { ChatOllama } from '@langchain/ollama';
import { ChatOpenAI } from '@langchain/openai';

// Import Settings
import AnthropicSettings from '../default-providers/Anthropic/settings-schema.json';
import ChromeAISettings from '../default-providers/ChromeAI/settings-schema.json';
import GeminiSettings from '../default-providers/Gemini/settings-schema.json';
import MistralAISettings from '../default-providers/MistralAI/settings-schema.json';
import OllamaAISettings from '../default-providers/Ollama/settings-schema.json';
import OpenAISettings from '../default-providers/OpenAI/settings-schema.json';
// import WebLLMSettings from '../default-providers/WebLLM/settings-schema.json';
import { IAIProvider, IType } from '../tokens';
import {
BaseChatModel,
BaseChatModelCallOptions
} from '@langchain/core/language_models/chat_models';
import { AIMessageChunk } from '@langchain/core/messages';

interface IAIProviderWithChat extends IAIProvider {
chat: IType<BaseChatModel<BaseChatModelCallOptions, AIMessageChunk>>;
}
const AIProviders: IAIProviderWithChat[] = [
{
name: 'Anthropic',
chat: ChatAnthropic,
settingsSchema: AnthropicSettings
},
{
name: 'ChromeAI',
// TODO: fix
// @ts-expect-error: missing properties
chat: ChromeAI,
settingsSchema: ChromeAISettings
},
{
name: 'MistralAI',
chat: ChatMistralAI,
settingsSchema: MistralAISettings
},
{
name: 'Ollama',
chat: ChatOllama,
settingsSchema: OllamaAISettings
},
{
name: 'Gemini',
chat: ChatGoogleGenerativeAI,
settingsSchema: GeminiSettings
},
{
name: 'OpenAI',
chat: ChatOpenAI,
settingsSchema: OpenAISettings
}
// {
// name: 'WebLLM',
// chat: ChatWebLLM,
// settingsSchema: WebLLMSettings
// }
];

it('test provider settings', () => {
AIProviders.forEach(provider => {
console.log(`PROVIDER: ${provider.name}`);
const schema: SchemaNode = compileSchema(provider.settingsSchema);
const defaultSettings = schema.getData(undefined, {
addOptionalProps: true
});

// Set a value for apiKey to avoid errors at instantiation.
if (defaultSettings.apiKey !== undefined) {
defaultSettings.apiKey = 'abc';
}
const model = new provider.chat(defaultSettings);

Object.entries(defaultSettings).forEach(([key, value]) => {
try {
// @ts-expect-error
expect(JSON.stringify(model[key])).toEqual(JSON.stringify(value));
} catch (err) {
// @ts-expect-error
err.message = `${err.message}\nproperty: ${key}\n`;
throw err; // throw the error so test fails as expected
}
});
});
});
13 changes: 0 additions & 13 deletions src/default-providers/Anthropic/settings-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
"type": "number",
"description": "A maximum number of tokens to generate before stopping."
},
"maxTokensToSample": {
"type": "number",
"description": "A maximum number of tokens to generate before stopping.",
"deprecated": "Use \"maxTokens\" instead."
},
"stopSequences": {
"type": "array",
"items": {
Expand All @@ -34,18 +29,10 @@
"type": "boolean",
"description": "Whether to stream the results or not"
},
"anthropicApiKey": {
"type": "string",
"description": "Anthropic API key"
},
"apiKey": {
"type": "string",
"description": "Anthropic API key"
},
"anthropicApiUrl": {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"type": "string",
"description": "Anthropic API URL"
},
"modelName": {
"type": "string",
"deprecated": "Use \"model\" instead"
Expand Down
4 changes: 0 additions & 4 deletions src/default-providers/ChromeAI/settings-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"concurrency": {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this one.

"type": "number",
"deprecated": "Use `maxConcurrency` instead"
},
"topK": {
"type": "number"
},
Expand Down
4 changes: 0 additions & 4 deletions src/default-providers/Gemini/settings-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
"description": "Model name to use (e.g., gemini-pro, gemini-2.0-flash, etc.)",
"default": "gemini-pro"
},
"baseURL": {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"type": "string",
"description": "Base URL for the Google AI API"
},
"safetySettings": {
"type": "array",
"description": "Safety settings for content filtering",
Expand Down
9 changes: 2 additions & 7 deletions src/default-providers/MistralAI/settings-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,14 @@
"description": "The API key to use.",
"default": ""
},
"modelName": {
"type": "string",
"description": "The name of the model to use. Alias for `model`",
"default": "mistral-small-latest"
},
"model": {
"type": "string",
"description": "The name of the model to use.",
"default": "mistral-small-latest"
},
"endpoint": {
"serverURL": {
"type": "string",
"description": "Override the default endpoint."
"description": "Override the default server URL used by the Mistral SDK."
},
"temperature": {
"type": "number",
Expand Down
11 changes: 0 additions & 11 deletions src/default-providers/Ollama/settings-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@
"type": ["string", "number"],
"default": "5m"
},
"stop": {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be nice to keep it.
Short explanation about stop words (I didn't know what it was used for): https://datasciencedude.com/how-to-easily-get-stop-words-for-your-language-learning-model#heading-what-are-stop-words-and-why-are-they-important

"type": "array",
"items": {
"type": "string"
}
},
"disableStreaming": {
"type": "boolean",
"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."
Expand All @@ -113,11 +107,6 @@
"description": "The host URL of the Ollama server.",
"default": ""
},
"headers": {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"type": "object",
"additionalProperties": false,
"description": "Optional HTTP Headers to include in the request."
},
"checkOrPullModel": {
"type": "boolean",
"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.",
Expand Down
Loading
Loading