You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Refactor: Add plan_functions to new PlanModel #1729
Now we have a unified Plan model in the context, we can store the plan
functions in there also.
This allows us to put the build_paramaters into this model and utilise
a __call__ to streamline some of the calling
The final Plan would look like this:
class Plan(BlueapiBaseModel):
"""
A plan that can be run
"""
name: str = Field(description="Referenceable name of the plan")
description: str | None = Field(
description="Description/docstring of the plan", default=None
)
model: type[BaseModel] = Field(
description="Validation model of the parameters for the plan"
)
func: PlanGenerator = Field(description="The plan function to be run")
def to_dict(self) -> dict[str, Any]:
return {
"name": self.name,
"parameter_schema": self.model.model_json_schema(),
"description": self.description,
}
def build_parameters(self, json_params: Mapping[str, Any]) -> dict[str, Any]:
param_model = self.model.model_validate(json_params)
prepared_params = {
field: getattr(param_model, field)
for field in param_model.__pydantic_fields__
}
return prepared_params
def __call__(self, json_params: Mapping[str, Any]) -> MsgGenerator:
p = self.build_parameters(json_params)
return self.func(**p)
Would also close this old issue I just found on the same thing: #180
Acceptance Criteria
The plan paramater building method is co-located with the rest of the Plan logic
All previous paramater building and error handling is preserved
Activity