Skip to content

Commit ca736ef

Browse files
authored
feat(invocation): add FetchAppInvocation and update type hints for improved clarity (#100)
* feat(invocation): add FetchAppInvocation and update type hints for improved clarity - Introduced FetchAppInvocation class to handle fetching app data. - Updated type hints in ToolInvokeMessage and related classes to use Mapping for better type safety. - Added FetchApp enum value to InvokeType for consistency in invocation types. * apply ruff
1 parent 0690573 commit ca736ef

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

python/dify_plugin/core/entities/invocation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class InvokeType(Enum):
1515
Storage = "storage"
1616
UploadFile = "upload_file"
1717
SYSTEM_SUMMARY = "system_summary"
18+
FetchApp = "fetch_app"
1819

1920
@classmethod
2021
def value_of(cls, value: str) -> "InvokeType":

python/dify_plugin/core/runtime.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
import uuid
33
from abc import ABC
4-
from collections.abc import Generator
4+
from collections.abc import Generator, Mapping
55
from concurrent.futures import ThreadPoolExecutor
66
from enum import Enum
77
from typing import Generic, Optional, TypeVar, Union
@@ -46,13 +46,18 @@ def __init__(self, session: "Session") -> None:
4646

4747
class AppInvocations:
4848
def __init__(self, session: "Session"):
49+
from dify_plugin.invocations.app import FetchAppInvocation
4950
from dify_plugin.invocations.app.chat import ChatAppInvocation
5051
from dify_plugin.invocations.app.completion import CompletionAppInvocation
5152
from dify_plugin.invocations.app.workflow import WorkflowAppInvocation
5253

5354
self.chat = ChatAppInvocation(session)
5455
self.completion = CompletionAppInvocation(session)
5556
self.workflow = WorkflowAppInvocation(session)
57+
self.fetch_app_invocation = FetchAppInvocation(session)
58+
59+
def fetch_app(self, app_id: str) -> Mapping:
60+
return self.fetch_app_invocation.get(app_id)
5661

5762

5863
class WorkflowNodeInvocations:

python/dify_plugin/entities/tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def to_dict(self):
8181
return {"text": self.text}
8282

8383
class JsonMessage(BaseModel):
84-
json_object: dict
84+
json_object: Mapping
8585

8686
def to_dict(self):
8787
return {"json_object": self.json_object}

python/dify_plugin/interfaces/tool/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def create_text_message(self, text: str) -> T:
2525
message=ToolInvokeMessage.TextMessage(text=text),
2626
)
2727

28-
def create_json_message(self, json: dict) -> T:
28+
def create_json_message(self, json: Mapping) -> T:
2929
return self.response_type(
3030
type=ToolInvokeMessage.MessageType.JSON,
3131
message=ToolInvokeMessage.JsonMessage(json_object=json),
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from collections.abc import Mapping
2+
3+
from dify_plugin.core.entities.invocation import InvokeType
4+
from dify_plugin.core.runtime import BackwardsInvocation
5+
6+
7+
class FetchAppInvocation(BackwardsInvocation[dict]):
8+
def get(
9+
self,
10+
app_id: str,
11+
) -> Mapping:
12+
"""
13+
Invoke chat app
14+
"""
15+
response = self._backwards_invoke(
16+
InvokeType.FetchApp,
17+
dict,
18+
{
19+
"app_id": app_id,
20+
},
21+
)
22+
23+
for data in response:
24+
return data
25+
26+
raise Exception("No response")

0 commit comments

Comments
 (0)