MCPcopy
hub / github.com/openai/openai-python / parse_text

Function parse_text

src/openai/lib/_parsing/_responses.py:142–155  ·  view source on GitHub ↗
(text: str, text_format: type[TextFormatT] | Omit)

Source from the content-addressed store, hash-verified

140
141
142def 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
158def get_input_tool_by_name(*, input_tools: Iterable[ToolParam], name: str) -> FunctionToolParam | None:

Callers 2

parse_responseFunction · 0.85
handle_eventMethod · 0.85

Calls 4

is_givenFunction · 0.85
model_parse_jsonFunction · 0.85
is_dataclass_like_typeFunction · 0.85
is_basemodel_typeFunction · 0.50

Tested by

no test coverage detected