Skip to content
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

Update model fields immediately on save #1125

Merged
merged 5 commits into from
Dec 2, 2024
Merged

Update model fields immediately on save #1125

merged 5 commits into from
Dec 2, 2024

Conversation

dlqqq
Copy link
Member

@dlqqq dlqqq commented Nov 27, 2024

Description

Fixes usage of model fields by respecting the updated values immediately on save (without requiring a restart).

Model fields are used to specify provider-specific keyword arguments directly from Jupyter AI's Settings UI. These include Base API URL for OpenAI, Region name for Amazon Bedrock, etc.

Demo

Screen.Recording.2024-11-27.at.10.33.12.AM.mov

Details for contributors

  • Fixes a bug introduced by Setting default model providers #421: BaseProvider.get_model_parameters() would return the fields set by the existing config.json on init, instead of the user-specified overrides in the AiExtension.model_parameters trait.

    • This was due to the ConfigManager accidentally merging the existing config into self.settings["model_parameters"] instead of a deep copy of that dictionary.
  • Fixes a bug introduced by Distinguish between completion and chat models #711: Model fields were not being returned at all from the dictionary returned by ConfigManager.lm_provider_params.

  • Makes the allowed_providers, blocked_providers, allowed_models, blocked_models arguments to ConfigManager optional and default to None, as indicated by their type signatures.

    • This change will not have any impact on users, as Jupyter AI always provides these arguments on extension init. This is purely for the convenience of contributors authoring tests.
  • Adds unit test coverage for both aforementioned bugs.

Testing instructions

  • Make the following changes in config.py:
    • Change deepcopy(self._defaults.get(config_key)) to self._defaults.get(config_key) near line 240.
    • Remove the line **fields, near line 475.
  • Run pytest, and verify that the 2 added tests fail. This asserts that the tests actually capture the bugs introduced by Setting default model providers #421 and Distinguish between completion and chat models #711.
  • Revert the changes and re-run pytest, and verify the 2 added tests now pass.
  • Run Jupyter AI from this branch, and verify that model fields are updated immediately on save.

Copy link
Collaborator

@srdas srdas left a comment

Choose a reason for hiding this comment

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

  1. Tested the deepcopy change by removing the code for it and failing pytest. Reinstating it works as intended.
  2. Tested that the changes to model fields are saved and there is no need to restart Jupyter AI. The system logs report the change as intended. Resolves Issue Provider text fields values saved from Chat UI are only applied after Jupyter Lab is restarted. #1118 .
  3. Issue profile_name field ignored for Amazon Bedrock Chat Models in jupyter-ai Extension #1007 : used blank profile_name and new region and the saved model works well.
  4. Issue Missing Request Schema for SageMaker Endpoint in jupyter-ai Extension #1006 (SageMaker endpoint request schema error). This still needs to be tried though there may not be JAI users who are calling SageMaker for the models.
  5. Issue api_version in GUI not considered, need to set OPENAI_API_VERSION #807 to be tested but no access to Azure. Hopefully @OliverKleinBST can test this.

@krassowski
Copy link
Member

I think this should go in, but I suspect that completions_fields does not work correctly.

I do not have a way to test it (no access to Amazon models nor Azure which are the ones that are parametrized). Maybe it would be good to expose some model parameters (temperature) as fields so that this could be tested by folks easily?

@krassowski
Copy link
Member

I think this should go in, but I suspect that completions_fields does not work correctly.

To clarify, I think this is not a result of this PR but since #711. Yet, it might be that fixing these together could be easier than separately.

Copy link
Collaborator

@srdas srdas left a comment

Choose a reason for hiding this comment

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

All LGTM.

@dlqqq
Copy link
Member Author

dlqqq commented Dec 2, 2024

@krassowski Thank you for the callout. I agree it would be good to also include a fix for completion fields before the next patch release. However, I think it should be done in a separate PR since it can be done independently.

I can help with these changes. It shouldn't be too much work; the _provider_params() method needs to read from config.completion_fields instead of config.fields when getting params for a completion model. Let me know if you'd like to help, and I'll open an issue and assign it to you. Otherwise I'll open a PR for this before the next patch release.

Proceeding to merge. Thank you @krassowski and @srdas for the testing & feedback!

@krassowski
Copy link
Member

Let me know if you'd like to help, and I'll open an issue and assign it to you. Otherwise I'll open a PR for this before the next patch release.

I'm unlikely to find time this week, if you see how to fix it easily feel free to go ahead. Also, agree a separate PR would be better.

@dlqqq
Copy link
Member Author

dlqqq commented Dec 2, 2024

@krassowski No worries! Take care.

@dlqqq dlqqq merged commit 342bb7b into main Dec 2, 2024
11 checks passed
@dlqqq
Copy link
Member Author

dlqqq commented Dec 2, 2024

@meeseeksdev please backport to v3-dev

meeseeksmachine pushed a commit to meeseeksmachine/jupyter-ai that referenced this pull request Dec 2, 2024
dlqqq added a commit that referenced this pull request Dec 2, 2024
@dlqqq dlqqq deleted the fix-config-save branch December 6, 2024 01:02
@OliverKleinBST
Copy link

Confirm that it solves also the problem reported in #807

dlqqq added a commit that referenced this pull request Dec 26, 2024
* Backport PR #1049: Added new Anthropic Sonnet3.5 v2 models (#1050)

Co-authored-by: Sanjiv Das <srdas@scu.edu>

* Backport PR #1051: Added Developer documentation for streaming responses (#1058)

Co-authored-by: Sanjiv Das <srdas@scu.edu>

* Backport PR #1048: Implement streaming for `/fix` (#1059)

Co-authored-by: Sanjiv Das <srdas@scu.edu>

* Backport PR #1057: [pre-commit.ci] pre-commit autoupdate (#1060)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Backport PR #1064: Added Ollama to the providers table in user docs (#1066)

Co-authored-by: Sanjiv Das <srdas@scu.edu>

* Backport PR #1056: Add examples of using Fields and EnvAuthStrategy to developer documentation (#1073)

Co-authored-by: Alan Meeson <alanmeeson@users.noreply.github.com>

* Backport PR #1069: Merge Anthropic language model providers (#1076)

Co-authored-by: Sanjiv Das <srdas@scu.edu>

* Backport PR #1068: Allow `$` to literally denote quantities of USD in chat (#1079)

Co-authored-by: david qiu <david@qiu.dev>

* Backport PR #1075: Fix magic commands when using non-chat providers w/ history (#1080)

Co-authored-by: Alan Meeson <alanmeeson@users.noreply.github.com>

* Backport PR #1077: Fix `/export` by including streamed agent messages (#1081)

Co-authored-by: Mahmut CAVDAR <4072246+mcavdar@users.noreply.github.com>

* Backport PR #1072: Reduced padding in cell around code icons in code toolbar (#1084)

Co-authored-by: Sanjiv Das <srdas@scu.edu>

* Backport PR #1087: Improve installation documentation and clarify provider dependencies (#1091)

Co-authored-by: Sanjiv Das <srdas@scu.edu>

* Backport PR #1092: Remove retired models and add new `Haiku-3.5` model in Anthropic (#1093)

Co-authored-by: Sanjiv Das <srdas@scu.edu>

* Backport PR #1094: Continue to allow `$` symbols to delimit inline math in human messages (#1095)

Co-authored-by: david qiu <david@qiu.dev>

* Backport PR #1097: Update `faiss-cpu` version range (#1101)

Co-authored-by: david qiu <david@qiu.dev>

* Backport PR #1104: Fix rendering of code blocks in JupyterLab 4.3.0+ (#1105)

Co-authored-by: david qiu <david@qiu.dev>

* Backport PR #1106: Catch error on non plaintext files in `@file` and reply gracefully in chat (#1110)

Co-authored-by: Sanjiv Das <srdas@scu.edu>

* Backport PR #1109: Bump LangChain minimum versions (#1112)

Co-authored-by: david qiu <david@qiu.dev>

* Backport PR #1119: Downgrade spurious 'error' logs (#1124)

Co-authored-by: ctcjab <joshua.bronson@chicagotrading.com>

* Backport PR #1127: Removes outdated OpenAI models and adds new ones (#1130)

Co-authored-by: Sanjiv Das <srdas@scu.edu>

* Backport PR #1131: [pre-commit.ci] pre-commit autoupdate (#1132)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Backport PR #1125: Update model fields immediately on save (#1133)

Co-authored-by: david qiu <david@qiu.dev>

* Backport PR #1139: Fix install step in CI (#1140)

Co-authored-by: david qiu <david@qiu.dev>

* Backport PR #1129: Fix JSON serialization error in Ollama models (#1141)

Co-authored-by: Mr.W <janus.choy@gmail.com>

* Backport PR #1137: Update completion model fields immediately on save (#1142)

Co-authored-by: david qiu <david@qiu.dev>

* [v3-dev] Initial migration to `jupyterlab-chat` (#1043)

* Very first version of the AI working in jupyterlab_collaborative_chat

* Allows both collaborative and regular chat to work with AI

* handle the help message in the chat too

* Autocompletion (#2)

* Fix handler methods' parameters

* Add slash commands (autocompletion) to the chat input

* Stream messages (#3)

* Allow for stream messages

* update jupyter collaborative chat dependency

* AI settings (#4)

* Add a menu option to open the AI settings

* Remove the input option from the setting widget

* pre-commit

* linting

* Homogeneize typing for optional arguments

* Fix import

* Showing that the bot is writing (answering) (#5)

* Show that the bot is writing (answering)

* Update jupyter chat dependency

* Some typing

* Update extension to jupyterlab_chat (0.6.0) (#8)

* Fix linting

* Remove try/except to import jupyterlab_chat (not optional anymore), and fix typing

* linter

* Python unit tests

* Fix typing

* lint

* Fix lint and mypy all together

* Fix web_app settings accessor

* Fix jupyter_collaboration version

Co-authored-by: david qiu <44106031+dlqqq@users.noreply.github.com>

* Remove unecessary try/except

* Dedicate one set of chat handlers per room (#9)

* create new set of chat handlers per room

* make YChat an instance attribute on BaseChatHandler

* revert changes to chat handlers

* pre-commit

* use room_id local var

Co-authored-by: Nicolas Brichet <32258950+brichet@users.noreply.github.com>

---------

Co-authored-by: Nicolas Brichet <32258950+brichet@users.noreply.github.com>

---------

Co-authored-by: david qiu <44106031+dlqqq@users.noreply.github.com>
Co-authored-by: david qiu <david@qiu.dev>

* Backport PR #1134: Improve user messaging and documentation for Cross-Region Inference on Amazon Bedrock (#1143)

Co-authored-by: Sanjiv Das <srdas@scu.edu>

* Backport PR #1136: Add base API URL field for Ollama and OpenAI embedding models (#1149)

Co-authored-by: Sanjiv Das <srdas@scu.edu>

* [v3-dev] Remove `/export`, `/clear`, and `/fix` (#1148)

* remove /export

* remove /clear

* remove /fix

* Fix CI in `v3-dev` branch (#1154)

* fix check release by bumping to impossible version

* fix types

* Update Playwright Snapshots

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* [v3-dev] Dedicate one LangChain history object per chat (#1151)

* dedicate a separate LangChain history object per chat

* pre-commit

* fix mypy

* Backport PR #1160: Trigger update snapshots based on commenter's role (#1161)

Co-authored-by: david qiu <david@qiu.dev>

* Backport PR #1155: Fix code output format in IPython (#1162)

Co-authored-by: Divyansh Choudhary <divyanshchoudhary99@gmail.com>

* Backport PR #1158: Update `/generate` to not split classes & functions across cells (#1164)

Co-authored-by: Sanjiv Das <srdas@scu.edu>

* Remove v2 frontend components (#1156)

* First pass to remove the front end chat

* Remove code-toolbar by using a simplified markdown renderer in settings

* Remove chat-message-menu (should be ported in jupyter-chat)

* Remove chat handler

* Follow up 'Remove chat-message-menu (should be ported in jupyter-chat)' commit

* Clean package.json

* Remove UI tests

* Remove the generative AI menu

* Remove unused components

* run yarn dedupe

---------

Co-authored-by: David L. Qiu <david@qiu.dev>

* Upgrade to `jupyterlab-chat>=0.7.0` (#1166)

* upgrade to jupyterlab-chat 0.7.0

* pre-commit

* upgrade to @jupyter/chat ^0.7.0 in frontend

* Remove v2 backend components (#1168)

* remove v2 llm memory, implement ReplyStream

* remove v2 websockets & REST handlers

* remove unused v2 data models

* fix slash command autocomplete

* fix unit tests

* remove unused _learned context provider

* fix mypy

* pre-commit

* fix optional k arg in YChatHistory

* bump jupyter chat to 0.7.1 to fix Python 3.9 tests

* revert accidentally breaking /learn

---------

Co-authored-by: Lumberbot (aka Jack) <39504233+meeseeksmachine@users.noreply.github.com>
Co-authored-by: Sanjiv Das <srdas@scu.edu>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Alan Meeson <alanmeeson@users.noreply.github.com>
Co-authored-by: Mahmut CAVDAR <4072246+mcavdar@users.noreply.github.com>
Co-authored-by: ctcjab <joshua.bronson@chicagotrading.com>
Co-authored-by: Mr.W <janus.choy@gmail.com>
Co-authored-by: Nicolas Brichet <32258950+brichet@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Divyansh Choudhary <divyanshchoudhary99@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment