-
-
Notifications
You must be signed in to change notification settings - Fork 438
Adding magics
functionality to the litellm
implementation
#1437
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@srdas This looks great, thank you! Just a few comments. Haven't tested it yet, have to join standup now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@srdas This is a great start, thank you! Just one extra comment below.
In addition, I've opened some follow-up issues (titled [magics] ...
) for you to explore. They can be addressed in separate PRs.
This is already a fantastic start, and I'm excited to merge this once the last comment is addressed.
self.transcript.append({"role": "user", "content": prompt}) | ||
self.transcript.append({"role": "assistant", "content": output}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you bound this list to be of length self.max_history * 2
? Right now, the ai()
method is manually truncating self.transcript
every time it appends it to the chat history. It would be more reliable to add some logic to bound the length of self.transcript
in the _append_exchange()
method itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is now done. Tested everything to make sure it is working. Here is a notebook if you want to test all the magics features (unzip to use).
magics_litellm.ipynb.zip
…rlab#1437) * Adding `magics` functionality to the `litellm` implementation * updates for initializing aliases and resolving types, mypy * Update magics.py * init alias * Update test_magics.py * Update magics.py * Changed `error` to `fix` in magics * Update index.md * Update test_magics.py * Update magics.py * streamlining magics * removed update command * initial_chat_model * magics pre-commit * Update magics.py
Is there any example about how to use litellm with %%ai magic? |
@cszhbo The refactoring of Jupyter AI to use
To your question about usage examples: This video shows the new workflow with chat and magics. The vast range of models offered by Screen.Recording.2025-08-21.at.7.45.49.AM.movHope this helps! |
It is very helpful. Appreciate your detailed demonstration. |
* [litellm] Initial migration to LiteLLM (#1425) * add new /api/ai/models endpoint * add litellm dependency * add new model ID input component * fix custom model ID input * update ConfigManager to accept litellm model IDs * update Jupyternaut to use litellm * remove LangChain partner packages from dependencies * remove LangChain provider entry points * pre-commit * rename /api/ai/models => /api/ai/models/chat * simplify model settings UI * [litellm] Remove LangChain from source code (#1435) * remove LangChain from jupyter_ai_magics * remove unused useServerInfo() hook in frontend * remove LangChain references from jupyter_ai * remove langchain from test & cookiecutter packages * move all completions code to jupyter_ai.completions * remove LangChain provider code from ConfigManager * minor fixes to allow JAI to start * Implementing model parameters input * Implement new Secrets UI and REST API (#1439) * add EnvSecretsManager and secrets REST API * make ListSecrets endpoint more generic * fix UpdateSecretsRequest type * fix bug where last secret cannot be deleted * remove error log used in dev * add new <SecretsSection /> component * tweak UI appearance * make settings page scrollable, fix #1409 * show no static secrets by default * show something when no secrets are present * adjust language * fix success & error alerts on updating secrets * fix lint * fix bug when .gitignore and .env do not exist * bump to 2s poll interval in EnvSecretsManager * disable model parameters input for now, fix merge conflicts * Adding `magics` functionality to the `litellm` implementation (#1437) * Adding `magics` functionality to the `litellm` implementation * updates for initializing aliases and resolving types, mypy * Update magics.py * init alias * Update test_magics.py * Update magics.py * Changed `error` to `fix` in magics * Update index.md * Update test_magics.py * Update magics.py * streamlining magics * removed update command * initial_chat_model * magics pre-commit * Update magics.py * missing model id in magics (#1457) Thanks David for approving this. * Added sublists for providers using %ai (#1458) * Fix `litellm` branch CI, add `EnvSecretsManager` tests (#1459) * update prettier ignore file * fix prettier errors & warnings * fix mypy errors in jupyter_ai * skip ConfigManager and inline completion tests until fixed in v3 * add tests for secrets manager * fix mypy error * run minimum dependency tests on Python 3.10 * comment out precommit job to be added in future * updated test_magics.py --------- Co-authored-by: Sanjiv Das <[email protected]> * [litellm] Display model IDs to match search string (#1445) * Enable the use of API Keys in magics from the `.env` file (#1465) * magics to use dotenv * Update magics.py * Update magics.py * Add model parameters input (#1456) * start of backend implementation * fixes api code * implemented type mapping * integrating api with ui * Working prototype of the model parameter input component with correct model parameters and dropdown feature! * added api to save parameters to config and removed old model-fields * code debugging, changing UI, and adding success error message * latest changes * fix type safety issues in model-parameters-input * fix frontend lint checks, update comment * fix mypy errors, add comments * small type fix * Updated coercion typing, improved code functionality, removed unnecessary code * pass chat model arguments to Jupyternaut * delete/update existing parameter * hide params controlling tool usage from frontend --------- Co-authored-by: David L. Qiu <[email protected]> * Clean up AI settings page (#1468) * Clean up AI settings page * remove debug line added by accident * Move LiteLLM model list to `jupyter_ai_magics` (#1469) * move model list to jupyter_ai_magics * fix mypy --------- Co-authored-by: Jonah Jung <[email protected]> Co-authored-by: Sanjiv Das <[email protected]> Co-authored-by: Jonah Jung <[email protected]>
Refactored various functionality for the
%ai
and%%ai
magics to use the newlitellm
backbone added in PR #1426 . Fixes Issue #1432run_ai_cell
to invokelitellm
instead oflangchain
.register
command toalias
which is more natural when registering an alias for amodel_id
.delete
command todealias
which is more natural.update
command as it is working well and is convenient.help
is working and shows the updated commands.list
command to show model IDs and aliases.reset
command is working.default_language_model
toinitial_language_model
.aliases
toinitial_aliases
.error
command tofix
, updated it's handling..env
approach.See the demo below showing all of it working:
Screen.Recording.2025-07-30.at.2.30.01.PM.mov
Nice to have (among other items):
format
options to be much more stable using agentic capabilities with better prompts.widgets
as another output format option.TODO
commented items inmagics.py
for consideration.