mirror of
https://github.com/langgenius/dify.git
synced 2026-04-15 09:57:03 +08:00
refactor: replace bare dict with typed annotations in core tools module (#35098)
This commit is contained in:
parent
c8b372dba0
commit
fc389a54c5
@ -1,4 +1,5 @@
|
||||
from collections.abc import Mapping
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
@ -26,6 +27,6 @@ class ApiToolBundle(BaseModel):
|
||||
# icon
|
||||
icon: str | None = None
|
||||
# openapi operation
|
||||
openapi: dict
|
||||
openapi: dict[str, Any]
|
||||
# output schema
|
||||
output_schema: Mapping[str, object] = Field(default_factory=dict)
|
||||
|
||||
@ -47,7 +47,7 @@ class ToolEngine:
|
||||
@staticmethod
|
||||
def agent_invoke(
|
||||
tool: Tool,
|
||||
tool_parameters: Union[str, dict],
|
||||
tool_parameters: Union[str, dict[str, Any]],
|
||||
user_id: str,
|
||||
tenant_id: str,
|
||||
message: Message,
|
||||
@ -85,7 +85,7 @@ class ToolEngine:
|
||||
invocation_meta_dict: dict[str, ToolInvokeMeta] = {}
|
||||
|
||||
def message_callback(
|
||||
invocation_meta_dict: dict[str, Any],
|
||||
invocation_meta_dict: dict[str, ToolInvokeMeta],
|
||||
messages: Generator[ToolInvokeMessage | ToolInvokeMeta, None, None],
|
||||
):
|
||||
for message in messages:
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from typing import cast
|
||||
from typing import Any, cast
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from sqlalchemy import select
|
||||
@ -39,7 +39,7 @@ class DatasetRetrieverTool(DatasetRetrieverBaseTool):
|
||||
dataset_id: str
|
||||
user_id: str | None = None
|
||||
retrieve_config: DatasetRetrieveConfigEntity
|
||||
inputs: dict
|
||||
inputs: dict[str, Any]
|
||||
|
||||
@classmethod
|
||||
def from_dataset(cls, dataset: Dataset, **kwargs):
|
||||
|
||||
@ -277,7 +277,7 @@ class WorkflowTool(Tool):
|
||||
session.expunge(app)
|
||||
return app
|
||||
|
||||
def _transform_args(self, tool_parameters: dict[str, Any]) -> tuple[dict[str, Any], list[dict[str, Any]]]:
|
||||
def _transform_args(self, tool_parameters: dict[str, Any]) -> tuple[dict[str, Any], list[dict[str, str | None]]]:
|
||||
"""
|
||||
transform the tool parameters
|
||||
|
||||
@ -355,7 +355,7 @@ class WorkflowTool(Tool):
|
||||
|
||||
return result, files
|
||||
|
||||
def _update_file_mapping(self, file_dict: dict[str, Any]):
|
||||
def _update_file_mapping(self, file_dict: dict[str, Any]) -> dict[str, Any]:
|
||||
file_id = resolve_file_record_id(file_dict.get("reference") or file_dict.get("related_id"))
|
||||
transfer_method = FileTransferMethod.value_of(file_dict.get("transfer_method"))
|
||||
match transfer_method:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user