3
3
4
4
from jupyter_ai_magics import Persona
5
5
from jupyter_ai_magics .providers import AuthStrategy , Field
6
- from pydantic import BaseModel , validator
6
+ from pydantic import BaseModel , field_validator
7
7
8
8
DEFAULT_CHUNK_SIZE = 2000
9
9
DEFAULT_CHUNK_OVERLAP = 100
@@ -129,7 +129,8 @@ class AgentStreamChunkMessage(BaseModel):
129
129
on `BaseAgentMessage.metadata` for information.
130
130
"""
131
131
132
- @validator ("metadata" )
132
+ @field_validator ("metadata" , mode = "before" )
133
+ @classmethod
133
134
def validate_metadata (cls , v ):
134
135
"""Ensure metadata values are JSON serializable"""
135
136
try :
@@ -252,11 +253,6 @@ class DescribeConfigResponse(BaseModel):
252
253
completions_fields : Dict [str , Dict [str , Any ]]
253
254
254
255
255
- def forbid_none (cls , v ):
256
- assert v is not None , "size may not be None"
257
- return v
258
-
259
-
260
256
class UpdateConfigRequest (BaseModel ):
261
257
model_provider_id : Optional [str ] = None
262
258
embeddings_provider_id : Optional [str ] = None
@@ -269,11 +265,14 @@ class UpdateConfigRequest(BaseModel):
269
265
completions_model_provider_id : Optional [str ] = None
270
266
completions_fields : Optional [Dict [str , Dict [str , Any ]]] = None
271
267
272
- _validate_send_wse = validator ("send_with_shift_enter" , allow_reuse = True )(
273
- forbid_none
274
- )
275
- _validate_api_keys = validator ("api_keys" , allow_reuse = True )(forbid_none )
276
- _validate_fields = validator ("fields" , allow_reuse = True )(forbid_none )
268
+ @field_validator ("send_with_shift_enter" , "api_keys" , "fields" , mode = "before" )
269
+ @classmethod
270
+ def ensure_not_none_if_passed (cls , field_val : Any ) -> Any :
271
+ """
272
+ Field validator ensuring that certain fields are never `None` if set.
273
+ """
274
+ assert field_val is not None , "size may not be None"
275
+ return field_val
277
276
278
277
279
278
class GlobalConfig (BaseModel ):
0 commit comments