Description
Problem
In Jupyter AI v1 & v2, our team was heavily focused on moving quickly & adding new features that users wanted. This was great, but some of these changes required "hacky" solutions to our model provider classes. These experiences have taught us that we need to explore defining a new API for models & model providers in v3.
This new epic documents multiple issues that are difficult to address separately, since they each require breaking API changes. The main issues are listed below in this description. Subissues on this epic represent other issues reported by users which would be fixed in v3, were this epic to be resolved.
Specifically, the issues with the v2 API are:
- Providers were intended to abstract a model service, but there may be >1 provider per model service. In other words, there is a confusing mismatch between what a provider is & what a provider should be.
Show details (click to expand)
-
Example: OpenAI models are actually served through 2 different providers in Jupyter AI:
openai
andopenai-chat
. This is fine for chat, but causes confusion for magic command users, since a user has to type out the full model ID in the%ai
magic command. -
A provider should be defined as a class abstraction that represents a model service, a service served either locally (e.g. via Ollama) or remotely (e.g. via Amazon Bedrock). A provider is said to provide one or more models, hence its name.
-
However, in v2, a provider is a LangChain class. Specifically, each provider is defined as a class that inherits from 2 classes: the
BaseProvider
(fromjupyter_ai_magics
) and either aLLM
orChatModel
subclass from LangChain. -
We did this since it seemed simple at the time. This was before LangChain separated
LLM
andChatModel
classes, which forced duplication of some providers. -
If 2 LangChain classes are offered for the same service (e.g.
OpenAI
andChatOpenAI
), then we are forced to vendor those models through 2 different providers (e.g.OpenAIProvider
andChatOpenAIProvider
).
-
The definition of a provider forces multiple inheritance. This introduces ways for non-breaking changes in LangChain to break Jupyter AI, and has caused issues in the past.
-
Users have no way of updating a model provider's list of models, if it is defined. By contrast, "registry providers" (e.g.
ollama
) allow a user to type in a model ID, but do not allow users to select a previous model used with a registry provider. We should unify these 2 capabilities in a new experience: let users pick & choose from a list of models, but also let users add new ones in case ours don't work. -
A provider provides every chat model as a completion model by default. Since we seek to improve code completions by preferring FITM (fill-in-the-middle) models, we should make this configurable to allow changing our defaults without introducing a breaking change.
-
A provider may define the
unsupported_slash_commands
andpersona
fields. These were added as quick solutions for v2 users, but these cannot continue to exist in v3. Persona will be a new abstraction, and we will likely want to replaceunsupported_slash_commands
with configurable "model rules" in the settings UI.
- Personas in v3: [v3-beta] Personas #1313
- TODO: open a new issue about model rules and explain what they are.
-
Providers are hidden from the AI Settings menu when their dependencies are not installed. We should be able to at least show these models anyways & remind the user that they must install that dependency to access that model.
-
All providers are defined in the
jupyter_ai_magics
package. While leaving it there is fine for users, it is slightly confusing for contributors, since it isn't obvious why models are defined injupyter_ai_magics
and notjupyter_ai
. We should explore providing a package which provides a Python API for managing models.
Proposed Solution
WIP.
- Create a new
jupyter_ai_models
package that provides APIs that allow one to:- Fetch the list of models (even if not all model dependencies are installed).
- Fetch the list of model providers.
- Add a custom model to a provider, along with user-entered fields.
- Delete a previously-added custom model.
- Update a previously-added custom model with new fields.
- Add model rules to customize certain models, e.g. disabling slash commands on models matching
amazon-bedrock:*
.
- Identify a way for one provider to specify multiple LangChain classes as clients to the model service. For example, there should be exactly one OpenAI provider, which calls
OpenAI
orChatOpenAI
from LangChain, based on the model ID.
Additional context
This issue is still a WIP.