Skip to content

Commit

Permalink
Config V2 (#353)
Browse files Browse the repository at this point in the history
* config manager initial draft

* implement basic client for new config manager

* implement JL4 unit testing (do not backport)

* implement chat settings save

* implement client API key deletion

* greatly improve error banner handling in settings

* implement API key edit and delete in settings UI

* ensure API keys are not empty

* reduce top and side padding in settings UI

* pre-commit

* fix integer field type error from rebase

* fix api key edit/delete react bugs

* improve UI error formatting

* implement last_read check on settings form

* fix local model ID not showing

* remove outdated comment

* ensure no empty field dictionaries in config

* fix minor typo
  • Loading branch information
dlqqq authored Sep 7, 2023
1 parent 94b8ef7 commit fc711c7
Show file tree
Hide file tree
Showing 28 changed files with 2,262 additions and 2,438 deletions.
File renamed without changes.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"dev-uninstall": "lerna run dev-uninstall --stream",
"lint": "jlpm && lerna run prettier && lerna run eslint",
"lint:check": "lerna run prettier:check && lerna run eslint:check",
"watch": "lerna run watch --parallel --stream"
"watch": "lerna run watch --parallel --stream",
"test": "lerna run test"
},
"devDependencies": {
"@jupyterlab/builder": "^4",
Expand Down
1 change: 1 addition & 0 deletions packages/jupyter-ai/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,4 @@ dmypy.json

# Coverage reports
coverage/*
junit.xml
41 changes: 12 additions & 29 deletions packages/jupyter-ai/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,29 @@
const jestJupyterLab = require('@jupyterlab/testutils/lib/jest-config');

const esModules = [
'@codemirror',
'@jupyter/ydoc',
'@jupyterlab/',
'lib0',
'y\\-protocols',
'y\\-websocket',
'nanoid',
'vscode-ws-jsonrpc',
'y-protocols',
'y-websocket',
'yjs'
].join('|');

const jlabConfig = jestJupyterLab(__dirname);

const {
moduleFileExtensions,
moduleNameMapper,
preset,
setupFilesAfterEnv,
setupFiles,
testPathIgnorePatterns,
transform
} = jlabConfig;
const baseConfig = jestJupyterLab(__dirname);

module.exports = {
moduleFileExtensions,
moduleNameMapper,
preset,
setupFilesAfterEnv,
setupFiles,
testPathIgnorePatterns,
transform,
...baseConfig,
automock: false,
collectCoverageFrom: [
'src/**/*.{ts,tsx}',
'!src/**/*.d.ts',
'!src/**/.ipynb_checkpoints/*'
// TODO: re-enable coverage reports when we have more comprehensive testing
// 'src/**/*.{ts,tsx}',
// '!src/**/*.d.ts',
// '!src/**/.ipynb_checkpoints/*'
],
coverageDirectory: 'coverage',
coverageReporters: ['lcov', 'text'],
globals: {
'ts-jest': {
tsconfig: 'tsconfig.json'
}
},
testRegex: 'src/.*/.*.spec.ts[x]?$',
transformIgnorePatterns: [`/node_modules/(?!${esModules}).+`]
};
4 changes: 2 additions & 2 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def reply(self, response, human_msg: Optional[HumanChatMessage] = None):
break

def get_llm_chain(self):
lm_provider = self.config_manager.get_lm_provider()
lm_provider_params = self.config_manager.get_lm_provider_params()
lm_provider = self.config_manager.lm_provider
lm_provider_params = self.config_manager.lm_provider_params

curr_lm_id = (
f'{self.llm.id}:{lm_provider_params["model_id"]}' if self.llm else None
Expand Down
5 changes: 1 addition & 4 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,7 @@ async def aget_relevant_documents(
return docs

def get_embedding_provider(self):
em_provider_cls = self.config_manager.get_em_provider()
em_provider_args = self.config_manager.get_em_provider_params()

return em_provider_cls, em_provider_args
return self.config_manager.em_provider, self.config_manager.em_provider_params

def get_embedding_model(self):
em_provider_cls, em_provider_args = self.get_embedding_provider()
Expand Down
42 changes: 42 additions & 0 deletions packages/jupyter-ai/jupyter_ai/config/config_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"title": "Jupyter AI configuration",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$comment": "Default values are sourced from `config_manager.py`.",
"type": "object",
"properties": {
"model_provider_id": {
"$comment": "Language model global ID.",
"type": ["string", "null"],
"default": null,
"readOnly": false
},
"embeddings_provider_id": {
"$comment": "Embedding model global ID.",
"type": ["string", "null"],
"default": null,
"readOnly": false
},
"api_keys": {
"$comment": "Dictionary of API keys, mapping key names to key values.",
"type": "object",
"default": {}
},
"send_with_shift_enter": {
"$comment": "Whether to send a message via Shift-Enter instead of Enter.",
"type": "boolean",
"default": false,
"readOnly": false
},
"fields": {
"$comment": "Dictionary of model-specific fields, mapping LM GIDs to sub-dictionaries of field key-value pairs.",
"type": "object",
"default": {},
"patternProperties": {
"^.*$": {
"anyOf": [{ "type": "object" }]
}
},
"additionalProperties": false
}
}
}
Loading

0 comments on commit fc711c7

Please sign in to comment.