(text: str, text_format: type[TextFormatT] | Omit)
| 140 | |
| 141 | |
| 142 | def parse_text(text: str, text_format: type[TextFormatT] | Omit) -> TextFormatT | None: |
| 143 | if not is_given(text_format): |
| 144 | return None |
| 145 | |
| 146 | if is_basemodel_type(text_format): |
| 147 | return cast(TextFormatT, model_parse_json(text_format, text)) |
| 148 | |
| 149 | if is_dataclass_like_type(text_format): |
| 150 | if PYDANTIC_V1: |
| 151 | raise TypeError(f"Non BaseModel types are only supported with Pydantic v2 - {text_format}") |
| 152 | |
| 153 | return pydantic.TypeAdapter(text_format).validate_json(text) |
| 154 | |
| 155 | raise TypeError(f"Unable to automatically parse response format type {text_format}") |
| 156 | |
| 157 | |
| 158 | def get_input_tool_by_name(*, input_tools: Iterable[ToolParam], name: str) -> FunctionToolParam | None: |
no test coverage detected