|
@@ -12,12 +12,17 @@ from core.plugin.entities.plugin_daemon import PluginDaemonBasicResponse
|
|
plugin_daemon_inner_api_baseurl = dify_config.PLUGIN_API_URL
|
|
plugin_daemon_inner_api_baseurl = dify_config.PLUGIN_API_URL
|
|
plugin_daemon_inner_api_key = dify_config.PLUGIN_API_KEY
|
|
plugin_daemon_inner_api_key = dify_config.PLUGIN_API_KEY
|
|
|
|
|
|
-T = TypeVar("T", bound=(BaseModel | dict))
|
|
|
|
|
|
+T = TypeVar("T", bound=(BaseModel | dict | bool))
|
|
|
|
|
|
|
|
|
|
class BasePluginManager:
|
|
class BasePluginManager:
|
|
def _request(
|
|
def _request(
|
|
- self, method: str, path: str, headers: dict | None = None, data: bytes | None = None, stream: bool = False
|
|
|
|
|
|
+ self,
|
|
|
|
+ method: str,
|
|
|
|
+ path: str,
|
|
|
|
+ headers: dict | None = None,
|
|
|
|
+ data: bytes | dict | None = None,
|
|
|
|
+ stream: bool = False,
|
|
) -> requests.Response:
|
|
) -> requests.Response:
|
|
"""
|
|
"""
|
|
Make a request to the plugin daemon inner API.
|
|
Make a request to the plugin daemon inner API.
|
|
@@ -29,7 +34,7 @@ class BasePluginManager:
|
|
return response
|
|
return response
|
|
|
|
|
|
def _stream_request(
|
|
def _stream_request(
|
|
- self, method: str, path: str, headers: dict | None = None, data: bytes | None = None
|
|
|
|
|
|
+ self, method: str, path: str, headers: dict | None = None, data: bytes | dict | None = None
|
|
) -> Generator[bytes, None, None]:
|
|
) -> Generator[bytes, None, None]:
|
|
"""
|
|
"""
|
|
Make a stream request to the plugin daemon inner API
|
|
Make a stream request to the plugin daemon inner API
|
|
@@ -43,7 +48,7 @@ class BasePluginManager:
|
|
path: str,
|
|
path: str,
|
|
type: type[T],
|
|
type: type[T],
|
|
headers: dict | None = None,
|
|
headers: dict | None = None,
|
|
- data: bytes | None = None,
|
|
|
|
|
|
+ data: bytes | dict | None = None,
|
|
) -> Generator[T, None, None]:
|
|
) -> Generator[T, None, None]:
|
|
"""
|
|
"""
|
|
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.
|
|
@@ -61,7 +66,7 @@ class BasePluginManager:
|
|
return type(**response.json())
|
|
return type(**response.json())
|
|
|
|
|
|
def _request_with_plugin_daemon_response(
|
|
def _request_with_plugin_daemon_response(
|
|
- self, method: str, path: str, type: type[T], headers: dict | None = None, data: bytes | None = None
|
|
|
|
|
|
+ self, method: str, path: str, type: type[T], headers: dict | None = None, data: bytes | dict | None = None
|
|
) -> T:
|
|
) -> T:
|
|
"""
|
|
"""
|
|
Make a request to the plugin daemon inner API and return the response as a model.
|
|
Make a request to the plugin daemon inner API and return the response as a model.
|
|
@@ -72,11 +77,11 @@ class BasePluginManager:
|
|
raise ValueError(f"got error from plugin daemon: {rep.message}, code: {rep.code}")
|
|
raise ValueError(f"got error from plugin daemon: {rep.message}, code: {rep.code}")
|
|
if rep.data is None:
|
|
if rep.data is None:
|
|
raise ValueError("got empty data from plugin daemon")
|
|
raise ValueError("got empty data from plugin daemon")
|
|
-
|
|
|
|
|
|
+
|
|
return rep.data
|
|
return rep.data
|
|
-
|
|
|
|
|
|
+
|
|
def _request_with_plugin_daemon_response_stream(
|
|
def _request_with_plugin_daemon_response_stream(
|
|
- self, method: str, path: str, type: type[T], headers: dict | None = None, data: bytes | None = None
|
|
|
|
|
|
+ self, method: str, path: str, type: type[T], headers: dict | None = None, data: bytes | dict | None = None
|
|
) -> Generator[T, None, None]:
|
|
) -> Generator[T, None, None]:
|
|
"""
|
|
"""
|
|
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.
|
|
@@ -85,7 +90,7 @@ class BasePluginManager:
|
|
line_data = json.loads(line)
|
|
line_data = json.loads(line)
|
|
rep = PluginDaemonBasicResponse[type](**line_data)
|
|
rep = PluginDaemonBasicResponse[type](**line_data)
|
|
if rep.code != 0:
|
|
if rep.code != 0:
|
|
- raise Exception(f"got error from plugin daemon: {rep.message}, code: {rep.code}")
|
|
|
|
|
|
+ raise ValueError(f"got error from plugin daemon: {rep.message}, code: {rep.code}")
|
|
if rep.data is None:
|
|
if rep.data is None:
|
|
- raise Exception("got empty data from plugin daemon")
|
|
|
|
- yield rep.data
|
|
|
|
|
|
+ raise ValueError("got empty data from plugin daemon")
|
|
|
|
+ yield rep.data
|