-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathio.py
More file actions
73 lines (64 loc) · 1.96 KB
/
Copy pathio.py
File metadata and controls
73 lines (64 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from enum import Enum
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from dify_plugin.core.server.__base.request_reader import RequestReader
from dify_plugin.core.server.__base.response_writer import ResponseWriter
class PluginInStreamEvent(Enum):
Request = "request"
BackwardInvocationResponse = "backwards_response"
@classmethod
def value_of(cls, v: str):
for e in cls:
if e.value == v:
return e
raise ValueError(f"Invalid value for PluginInStream.Event: {v}")
class PluginInStreamBase:
def __init__(
self,
session_id: str,
event: PluginInStreamEvent,
data: dict,
conversation_id: str | None = None,
message_id: str | None = None,
app_id: str | None = None,
endpoint_id: str | None = None,
context: dict | None = None,
passthrough: str | None = None,
) -> None:
self.session_id = session_id
self.event = event
self.data = data
self.conversation_id = conversation_id
self.message_id = message_id
self.app_id = app_id
self.endpoint_id = endpoint_id
self.context = context
self.passthrough = passthrough
class PluginInStream(PluginInStreamBase):
def __init__(
self,
session_id: str,
event: PluginInStreamEvent,
data: dict,
reader: "RequestReader",
writer: "ResponseWriter",
conversation_id: str | None = None,
message_id: str | None = None,
app_id: str | None = None,
endpoint_id: str | None = None,
context: dict | None = None,
passthrough: str | None = None,
):
self.reader = reader
self.writer = writer
super().__init__(
session_id,
event,
data,
conversation_id,
message_id,
app_id,
endpoint_id,
context,
passthrough,
)