File tree 2 files changed +20
-12
lines changed
vertexai/reasoning_engines
2 files changed +20
-12
lines changed Original file line number Diff line number Diff line change @@ -840,9 +840,9 @@ def _method(self, **kwargs) -> Iterable[Any]:
840
840
),
841
841
)
842
842
for chunk in response :
843
- parsed_json = _utils .to_parsed_json (chunk )
844
- if parsed_json is not None :
845
- yield parsed_json
843
+ for parsed_json in _utils .to_parsed_json (chunk ):
844
+ if parsed_json is not None :
845
+ yield parsed_json
846
846
847
847
_method .__name__ = method_name
848
848
_method .__doc__ = doc
Original file line number Diff line number Diff line change @@ -104,22 +104,30 @@ def to_parsed_json(body: httpbody_pb2.HttpBody) -> Any:
104
104
data = getattr (body , "data" , None )
105
105
106
106
if content_type is None or data is None or "application/json" not in content_type :
107
- return body
107
+ yield body
108
+ return
108
109
109
110
try :
110
111
utf8_data = data .decode ("utf-8" )
111
112
except Exception as e :
112
113
_LOGGER .warning (f"Failed to decode data: { data } . Exception: { e } " )
113
- return body
114
+ yield body
115
+ return
114
116
115
117
if not utf8_data :
116
- return None
117
-
118
- try :
119
- return json .loads (utf8_data )
120
- except Exception as e :
121
- _LOGGER .warning (f"Failed to parse JSON: { utf8_data } . Exception: { e } " )
122
- return body # Return the raw body on error
118
+ yield None
119
+ return
120
+
121
+ # Handle the case of multiple dictionaries delimited by newlines.
122
+ for line in utf8_data .split ("\n " ):
123
+ if line :
124
+ try :
125
+ line = json .loads (line )
126
+ except Exception as e :
127
+ _LOGGER .warning (
128
+ f"failed to parse json: { line } . Exception: { e } "
129
+ )
130
+ yield line
123
131
124
132
125
133
def generate_schema (
You can’t perform that action at this time.
0 commit comments