Convert tool input to pydantic model.
(
self,
tool_input: Union[str, Dict],
)
| 289 | # --- Tool --- |
| 290 | |
| 291 | def _parse_input( |
| 292 | self, |
| 293 | tool_input: Union[str, Dict], |
| 294 | ) -> Union[str, Dict[str, Any]]: |
| 295 | """Convert tool input to pydantic model.""" |
| 296 | input_args = self.args_schema |
| 297 | if isinstance(tool_input, str): |
| 298 | if input_args is not None: |
| 299 | key_ = next(iter(input_args.__fields__.keys())) |
| 300 | input_args.validate({key_: tool_input}) |
| 301 | return tool_input |
| 302 | else: |
| 303 | if input_args is not None: |
| 304 | result = input_args.parse_obj(tool_input) |
| 305 | return { |
| 306 | k: getattr(result, k) |
| 307 | for k, v in result.dict().items() |
| 308 | if k in tool_input |
| 309 | } |
| 310 | return tool_input |
| 311 | |
| 312 | @root_validator(pre=True) |
| 313 | def raise_deprecation(cls, values: Dict) -> Dict: |