mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 02:29:03 +08:00
enhance(plugin): replace json.loads with Pydantic model_validate_json (#17867)
This commit is contained in:
parent
78da4ca024
commit
b2f5ca356a
@ -168,15 +168,14 @@ class BasePluginManager:
|
|||||||
Make a stream request to the plugin daemon inner API and yield the response as a model.
|
Make a stream request to the plugin daemon inner API and yield the response as a model.
|
||||||
"""
|
"""
|
||||||
for line in self._stream_request(method, path, params, headers, data, files):
|
for line in self._stream_request(method, path, params, headers, data, files):
|
||||||
line_data = None
|
|
||||||
try:
|
try:
|
||||||
line_data = json.loads(line)
|
rep = PluginDaemonBasicResponse[type].model_validate_json(line) # type: ignore
|
||||||
rep = PluginDaemonBasicResponse[type](**line_data) # type: ignore
|
|
||||||
except Exception:
|
except Exception:
|
||||||
# TODO modify this when line_data has code and message
|
# TODO modify this when line_data has code and message
|
||||||
if line_data and "error" in line_data:
|
try:
|
||||||
|
line_data = json.loads(line)
|
||||||
raise ValueError(line_data["error"])
|
raise ValueError(line_data["error"])
|
||||||
else:
|
except Exception:
|
||||||
raise ValueError(line)
|
raise ValueError(line)
|
||||||
|
|
||||||
if rep.code != 0:
|
if rep.code != 0:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user