MCPcopy Create free account
hub / github.com/CJackHwang/AIstudioProxyAPI / process_response

Method process_response

stream/interceptors.py:114–143  ·  view source on GitHub ↗

Process the response data before sending to the client using persistent buffering

(
        self,
        response_data: Union[int, bytes],
        host: str,
        path: str,
        headers: Dict[Any, Any],
    )

Source from the content-addressed store, hash-verified

112 return request_data
113
114 async def process_response(
115 self,
116 response_data: Union[int, bytes],
117 host: str,
118 path: str,
119 headers: Dict[Any, Any],
120 ) -> Dict[str, Any]:
121 """
122 Process the response data before sending to the client using persistent buffering
123 """
124 try:
125 # Handle chunked encoding
126 decoded_data, is_done = self._decode_chunked(bytes(response_data))
127 # Handle gzip encoding
128 decoded_data = self._decompress_zlib_stream(decoded_data)
129
130 # Convert to string and accumulate in persistent buffer
131 try:
132 decoded_str = decoded_data.decode("utf-8")
133 self.response_buffer += decoded_str
134 except UnicodeDecodeError:
135 # Not UTF-8 data, return empty result
136 return {"reason": "", "body": "", "function": [], "done": is_done}
137
138 # Try to parse complete JSON objects from the buffer
139 result = self.parse_response_from_buffer(is_done)
140 return result
141 except Exception as e:
142 self.logger.debug(f"Error processing response: {e}")
143 return {"reason": "", "body": "", "function": [], "done": False}
144
145 def parse_response_from_buffer(self, is_done=False):
146 """

Calls 4

_decode_chunkedMethod · 0.95
debugMethod · 0.80