Skip to content

Commit 497016d

Browse files
authored
Remove config schema and legacy v2 persona references (#1420)
* move config models to config/config_models.py * replace config schema validation with pydantic * override config w/ traitlets defaults on init, fix all tests * remove old v2 persona files * fix jupyternaut route
1 parent 10b83cb commit 497016d

File tree

11 files changed

+195
-409
lines changed

11 files changed

+195
-409
lines changed

packages/jupyter-ai-magics/jupyter_ai_magics/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
)
1414
from .exception import store_exception
1515
from .magics import AiMagics
16-
from .models.persona import JupyternautPersona, Persona
1716
from .providers import (
1817
AI21Provider,
1918
BaseProvider,
@@ -24,7 +23,6 @@
2423
)
2524
else:
2625
_exports_by_module = {
27-
# expose embedding model providers on the package root
2826
"embedding_providers": [
2927
"BaseEmbeddingsProvider",
3028
"GPT4AllEmbeddingsProvider",
@@ -33,9 +31,6 @@
3331
],
3432
"exception": ["store_exception"],
3533
"magics": ["AiMagics"],
36-
# expose JupyternautPersona on the package root
37-
# required by `jupyter-ai`.
38-
"models.persona": ["JupyternautPersona", "Persona"],
3934
# expose model providers on the package root
4035
"providers": [
4136
"AI21Provider",
@@ -80,8 +75,6 @@ def unload_ipython_extension(ipython):
8075
"QianfanEmbeddingsEndpointProvider",
8176
"store_exception",
8277
"AiMagics",
83-
"JupyternautPersona",
84-
"Persona",
8578
"AI21Provider",
8679
"BaseProvider",
8780
"GPT4AllProvider",

packages/jupyter-ai-magics/jupyter_ai_magics/base_provider.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
InlineCompletionRequest,
3333
InlineCompletionStreamChunk,
3434
)
35-
from .models.persona import Persona
3635

3736
CHAT_SYSTEM_PROMPT = """
3837
You are Jupyternaut, a conversational assistant living in JupyterLab to help users.
@@ -218,18 +217,6 @@ class BaseProvider(BaseModel):
218217
set to `True`, Jupyter AI will not pass the chat history to this provider
219218
when invoked."""
220219

221-
persona: ClassVar[Optional[Persona]] = None
222-
"""
223-
The **persona** of this provider, a struct that defines the name and avatar
224-
shown on agent replies in the chat UI. When set to `None`, `jupyter-ai` will
225-
choose a default persona when rendering agent messages by this provider.
226-
227-
Because this field is set to `None` by default, `jupyter-ai` will render a
228-
default persona for all providers that are included natively with the
229-
`jupyter-ai` package. This field is reserved for Jupyter AI modules that
230-
serve a custom provider and want to distinguish it in the chat UI.
231-
"""
232-
233220
unsupported_slash_commands: ClassVar[set] = set()
234221
"""
235222
A set of slash commands unsupported by this provider. Unsupported slash

packages/jupyter-ai-magics/jupyter_ai_magics/models/persona.py

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .config_models import JaiConfig, UpdateConfigRequest, DescribeConfigResponse
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
from pydantic import BaseModel, field_validator
2+
from typing import Any, Optional
3+
4+
class JaiConfig(BaseModel):
5+
"""
6+
Pydantic model that serializes and validates the Jupyter AI config.
7+
"""
8+
9+
model_provider_id: Optional[str] = None
10+
"""
11+
Model ID of the chat model.
12+
"""
13+
14+
embeddings_provider_id: Optional[str] = None
15+
"""
16+
Model ID of the embedding model.
17+
"""
18+
19+
completions_model_provider_id: Optional[str] = None
20+
"""
21+
Model ID of the completions model.
22+
"""
23+
24+
api_keys: dict[str, str] = {}
25+
"""
26+
Dictionary of API keys. The name of each key should correspond to the
27+
environment variable expected by the underlying client library, e.g.
28+
"OPENAI_API_KEY".
29+
"""
30+
31+
send_with_shift_enter: bool = False
32+
"""
33+
Whether the "Enter" key should create a new line instead of sending the
34+
message.
35+
"""
36+
37+
fields: dict[str, dict[str, Any]] = {}
38+
"""
39+
Dictionary that defines custom fields for each chat model.
40+
Key: chat model ID.
41+
Value: Dictionary of keyword arguments.
42+
"""
43+
44+
embeddings_fields: dict[str, dict[str, Any]] = {}
45+
completions_fields: dict[str, dict[str, Any]] = {}
46+
47+
48+
class DescribeConfigResponse(BaseModel):
49+
model_provider_id: Optional[str] = None
50+
embeddings_provider_id: Optional[str] = None
51+
send_with_shift_enter: bool
52+
fields: dict[str, dict[str, Any]]
53+
54+
api_keys: list[str]
55+
"""
56+
List of the names of the API keys. This deliberately does not include the
57+
value of each API key in the interest of security.
58+
"""
59+
60+
last_read: int
61+
"""
62+
Timestamp indicating when the configuration file was last read. Should be
63+
passed to the subsequent UpdateConfig request if an update is made.
64+
"""
65+
66+
completions_model_provider_id: Optional[str] = None
67+
completions_fields: dict[str, dict[str, Any]]
68+
embeddings_fields: dict[str, dict[str, Any]]
69+
70+
71+
class UpdateConfigRequest(BaseModel):
72+
model_provider_id: Optional[str] = None
73+
embeddings_provider_id: Optional[str] = None
74+
completions_model_provider_id: Optional[str] = None
75+
send_with_shift_enter: Optional[bool] = None
76+
api_keys: Optional[dict[str, str]] = None
77+
# if passed, this will raise an Error if the config was written to after the
78+
# time specified by `last_read` to prevent write-write conflicts.
79+
last_read: Optional[int] = None
80+
fields: Optional[dict[str, dict[str, Any]]] = None
81+
completions_fields: Optional[dict[str, dict[str, Any]]] = None
82+
embeddings_fields: Optional[dict[str, dict[str, Any]]] = None
83+
84+
@field_validator("send_with_shift_enter", "api_keys", "fields", mode="before")
85+
@classmethod
86+
def ensure_not_none_if_passed(cls, field_val: Any) -> Any:
87+
"""
88+
Field validator ensuring that certain fields are never `None` if set.
89+
"""
90+
assert field_val is not None, "size may not be None"
91+
return field_val

packages/jupyter-ai/jupyter_ai/config/config_schema.json

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)