mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-11 11:56:53 +08:00
chore: apply ruff's pyupgrade linter rules to modernize Python code with targeted version (#2419)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from enum import Enum
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
from typing import Any, Optional, Union
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
@@ -19,7 +19,7 @@ from core.tools.tool_file_manager import ToolFileManager
|
||||
|
||||
class Tool(BaseModel, ABC):
|
||||
identity: ToolIdentity = None
|
||||
parameters: Optional[List[ToolParameter]] = None
|
||||
parameters: Optional[list[ToolParameter]] = None
|
||||
description: ToolDescription = None
|
||||
is_team_authorization: bool = False
|
||||
agent_callback: Optional[DifyAgentCallbackHandler] = None
|
||||
@@ -36,8 +36,8 @@ class Tool(BaseModel, ABC):
|
||||
|
||||
tenant_id: str = None
|
||||
tool_id: str = None
|
||||
credentials: Dict[str, Any] = None
|
||||
runtime_parameters: Dict[str, Any] = None
|
||||
credentials: dict[str, Any] = None
|
||||
runtime_parameters: dict[str, Any] = None
|
||||
|
||||
runtime: Runtime = None
|
||||
variables: ToolRuntimeVariablePool = None
|
||||
@@ -53,7 +53,7 @@ class Tool(BaseModel, ABC):
|
||||
class VARIABLE_KEY(Enum):
|
||||
IMAGE = 'image'
|
||||
|
||||
def fork_tool_runtime(self, meta: Dict[str, Any], agent_callback: DifyAgentCallbackHandler = None) -> 'Tool':
|
||||
def fork_tool_runtime(self, meta: dict[str, Any], agent_callback: DifyAgentCallbackHandler = None) -> 'Tool':
|
||||
"""
|
||||
fork a new tool with meta data
|
||||
|
||||
@@ -146,7 +146,7 @@ class Tool(BaseModel, ABC):
|
||||
|
||||
return file_binary[0]
|
||||
|
||||
def list_variables(self) -> List[ToolRuntimeVariable]:
|
||||
def list_variables(self) -> list[ToolRuntimeVariable]:
|
||||
"""
|
||||
list all variables
|
||||
|
||||
@@ -157,7 +157,7 @@ class Tool(BaseModel, ABC):
|
||||
|
||||
return self.variables.pool
|
||||
|
||||
def list_default_image_variables(self) -> List[ToolRuntimeVariable]:
|
||||
def list_default_image_variables(self) -> list[ToolRuntimeVariable]:
|
||||
"""
|
||||
list all image variables
|
||||
|
||||
@@ -174,7 +174,7 @@ class Tool(BaseModel, ABC):
|
||||
|
||||
return result
|
||||
|
||||
def invoke(self, user_id: str, tool_parameters: Dict[str, Any]) -> List[ToolInvokeMessage]:
|
||||
def invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> list[ToolInvokeMessage]:
|
||||
# update tool_parameters
|
||||
if self.runtime.runtime_parameters:
|
||||
tool_parameters.update(self.runtime.runtime_parameters)
|
||||
@@ -209,7 +209,7 @@ class Tool(BaseModel, ABC):
|
||||
|
||||
return result
|
||||
|
||||
def _convert_tool_response_to_str(self, tool_response: List[ToolInvokeMessage]) -> str:
|
||||
def _convert_tool_response_to_str(self, tool_response: list[ToolInvokeMessage]) -> str:
|
||||
"""
|
||||
Handle tool response
|
||||
"""
|
||||
@@ -233,10 +233,10 @@ class Tool(BaseModel, ABC):
|
||||
return result
|
||||
|
||||
@abstractmethod
|
||||
def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
||||
pass
|
||||
|
||||
def validate_credentials(self, credentials: Dict[str, Any], parameters: Dict[str, Any]) -> None:
|
||||
def validate_credentials(self, credentials: dict[str, Any], parameters: dict[str, Any]) -> None:
|
||||
"""
|
||||
validate the credentials
|
||||
|
||||
@@ -245,7 +245,7 @@ class Tool(BaseModel, ABC):
|
||||
"""
|
||||
pass
|
||||
|
||||
def get_runtime_parameters(self) -> List[ToolParameter]:
|
||||
def get_runtime_parameters(self) -> list[ToolParameter]:
|
||||
"""
|
||||
get the runtime parameters
|
||||
|
||||
|
||||
Reference in New Issue
Block a user