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

Function parse_response

src/openai/lib/_parsing/_responses.py:53–139  ·  view source on GitHub ↗
(
    *,
    text_format: type[TextFormatT] | Omit,
    input_tools: Iterable[ToolParam] | Omit | None,
    response: Response | ParsedResponse[object],
)

Source from the content-addressed store, hash-verified

51
52
53def parse_response(
54 *,
55 text_format: type[TextFormatT] | Omit,
56 input_tools: Iterable[ToolParam] | Omit | None,
57 response: Response | ParsedResponse[object],
58) -> ParsedResponse[TextFormatT]:
59 output_list: List[ParsedResponseOutputItem[TextFormatT]] = []
60
61 for output in response.output:
62 if output.type == "message":
63 content_list: List[ParsedContent[TextFormatT]] = []
64 for item in output.content:
65 if item.type != "output_text":
66 content_list.append(item)
67 continue
68
69 content_list.append(
70 construct_type_unchecked(
71 type_=ParsedResponseOutputText[TextFormatT],
72 value={
73 **item.to_dict(),
74 "parsed": parse_text(item.text, text_format=text_format),
75 },
76 )
77 )
78
79 output_list.append(
80 construct_type_unchecked(
81 type_=ParsedResponseOutputMessage[TextFormatT],
82 value={
83 **output.to_dict(),
84 "content": content_list,
85 },
86 )
87 )
88 elif output.type == "function_call":
89 output_list.append(
90 construct_type_unchecked(
91 type_=ParsedResponseFunctionToolCall,
92 value={
93 **output.to_dict(),
94 "parsed_arguments": parse_function_tool_arguments(
95 input_tools=input_tools, function_call=output
96 ),
97 },
98 )
99 )
100 elif (
101 output.type == "computer_call"
102 or output.type == "file_search_call"
103 or output.type == "web_search_call"
104 or output.type == "tool_search_call"
105 or output.type == "tool_search_output"
106 or output.type == "additional_tools"
107 or output.type == "reasoning"
108 or output.type == "compaction"
109 or output.type == "mcp_call"
110 or output.type == "mcp_approval_request"

Callers 3

parserMethod · 0.85
parserMethod · 0.85
accumulate_eventMethod · 0.85

Calls 5

construct_type_uncheckedFunction · 0.85
parse_textFunction · 0.85
to_dictMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected