fix(nodes): make fields on ModelConfigBase required

The setup of `ModelConfigBase` means autogenerated types have critical fields flagged as nullable (like `key` and `base`). Need to manually flag them as required.
This commit is contained in:
psychedelicious 2024-02-22 17:21:37 +11:00
parent 0d9fbe5e04
commit 239ecfaf79

View File

@ -138,9 +138,16 @@ class ModelConfigBase(BaseModel):
source: Optional[str] = Field(description="model original source (path, URL or repo_id)", default=None) source: Optional[str] = Field(description="model original source (path, URL or repo_id)", default=None)
last_modified: Optional[float] = Field(description="timestamp for modification time", default_factory=time.time) last_modified: Optional[float] = Field(description="timestamp for modification time", default_factory=time.time)
@staticmethod
def json_schema_extra(schema: dict[str, Any], model_class: Type[BaseModel]) -> None:
schema["required"].extend(
["key", "base", "type", "format", "original_hash", "current_hash", "source", "last_modified"]
)
model_config = ConfigDict( model_config = ConfigDict(
use_enum_values=False, use_enum_values=False,
validate_assignment=True, validate_assignment=True,
json_schema_extra=json_schema_extra,
) )
def update(self, attributes: Dict[str, Any]) -> None: def update(self, attributes: Dict[str, Any]) -> None: