feat(workflow node): built-in tools output modifications to adapt to workflow nodes
This commit is contained in:
@@ -110,7 +110,7 @@ class BaiduSearchTool(BuiltinTool):
|
|||||||
|
|
||||||
execution_time = time.time() - start_time
|
execution_time = time.time() - start_time
|
||||||
return ToolResult.success_result(
|
return ToolResult.success_result(
|
||||||
data=result,
|
data=result["results"],
|
||||||
execution_time=execution_time
|
execution_time=execution_time
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ class DateTimeTool(BuiltinTool):
|
|||||||
|
|
||||||
execution_time = time.time() - start_time
|
execution_time = time.time() - start_time
|
||||||
return ToolResult.success_result(
|
return ToolResult.success_result(
|
||||||
data=result,
|
data=result["result_data"],
|
||||||
execution_time=execution_time
|
execution_time=execution_time
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -123,12 +123,14 @@ class DateTimeTool(BuiltinTool):
|
|||||||
utc_now = datetime.now(timezone.utc)
|
utc_now = datetime.now(timezone.utc)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"datetime": now.strftime(output_format),
|
|
||||||
"timestamp": int(now.timestamp()),
|
|
||||||
"timezone": timezone_str,
|
"timezone": timezone_str,
|
||||||
"iso_format": now.isoformat(),
|
"iso_format": now.isoformat(),
|
||||||
"timestamp_ms": int(now.timestamp() * 1000),
|
"result_data": {
|
||||||
"utc_datetime": utc_now.strftime(output_format)
|
"datetime": now.strftime(output_format),
|
||||||
|
"timestamp": int(now.timestamp()),
|
||||||
|
"timestamp_ms": int(now.timestamp() * 1000),
|
||||||
|
"utc_datetime": utc_now.strftime(output_format),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -148,7 +150,8 @@ class DateTimeTool(BuiltinTool):
|
|||||||
"original": input_value,
|
"original": input_value,
|
||||||
"formatted": dt.strftime(output_format),
|
"formatted": dt.strftime(output_format),
|
||||||
"timestamp": int(dt.timestamp()),
|
"timestamp": int(dt.timestamp()),
|
||||||
"iso_format": dt.isoformat()
|
"iso_format": dt.isoformat(),
|
||||||
|
"result_data": dt.strftime(output_format)
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -189,7 +192,8 @@ class DateTimeTool(BuiltinTool):
|
|||||||
"original_timezone": from_timezone,
|
"original_timezone": from_timezone,
|
||||||
"converted": converted_dt.strftime(output_format),
|
"converted": converted_dt.strftime(output_format),
|
||||||
"converted_timezone": to_timezone,
|
"converted_timezone": to_timezone,
|
||||||
"timestamp": int(converted_dt.timestamp())
|
"timestamp": int(converted_dt.timestamp()),
|
||||||
|
"result_data": converted_dt.strftime(output_format)
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -219,7 +223,8 @@ class DateTimeTool(BuiltinTool):
|
|||||||
"timestamp": timestamp,
|
"timestamp": timestamp,
|
||||||
"datetime": dt.strftime(output_format),
|
"datetime": dt.strftime(output_format),
|
||||||
"timezone": timezone_str,
|
"timezone": timezone_str,
|
||||||
"iso_format": dt.isoformat()
|
"iso_format": dt.isoformat(),
|
||||||
|
"result_data": dt.strftime(output_format)
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -249,7 +254,8 @@ class DateTimeTool(BuiltinTool):
|
|||||||
"datetime": input_value,
|
"datetime": input_value,
|
||||||
"timezone": timezone_str,
|
"timezone": timezone_str,
|
||||||
"timestamp": int(dt.timestamp()),
|
"timestamp": int(dt.timestamp()),
|
||||||
"iso_format": dt.isoformat()
|
"iso_format": dt.isoformat(),
|
||||||
|
"result_data": int(dt.timestamp())
|
||||||
}
|
}
|
||||||
|
|
||||||
def _calculate_datetime(self, kwargs) -> dict:
|
def _calculate_datetime(self, kwargs) -> dict:
|
||||||
@@ -287,7 +293,8 @@ class DateTimeTool(BuiltinTool):
|
|||||||
"calculation": calculation,
|
"calculation": calculation,
|
||||||
"result": calculated_dt.strftime(output_format),
|
"result": calculated_dt.strftime(output_format),
|
||||||
"timezone": timezone_str,
|
"timezone": timezone_str,
|
||||||
"timestamp": int(calculated_dt.timestamp())
|
"timestamp": int(calculated_dt.timestamp()),
|
||||||
|
"result_data": calculated_dt.strftime(output_format)
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class JsonTool(BuiltinTool):
|
|||||||
ToolParameter(
|
ToolParameter(
|
||||||
name="json_path",
|
name="json_path",
|
||||||
type=ParameterType.STRING,
|
type=ParameterType.STRING,
|
||||||
description="JSON路径表达式(用于extract、insert、replace、delete、parse操作,如:$.user.name或users[0].name)",
|
description="JSON路径表达式(用于insert、replace、delete、parse操作,如:$.user.name或users[0].name)",
|
||||||
required=False
|
required=False
|
||||||
),
|
),
|
||||||
ToolParameter(
|
ToolParameter(
|
||||||
@@ -136,7 +136,7 @@ class JsonTool(BuiltinTool):
|
|||||||
|
|
||||||
execution_time = time.time() - start_time
|
execution_time = time.time() - start_time
|
||||||
return ToolResult.success_result(
|
return ToolResult.success_result(
|
||||||
data=result,
|
data=result["result_data"],
|
||||||
execution_time=execution_time
|
execution_time=execution_time
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -671,7 +671,8 @@ class JsonTool(BuiltinTool):
|
|||||||
"success": True,
|
"success": True,
|
||||||
"value": current,
|
"value": current,
|
||||||
"value_type": type(current).__name__,
|
"value_type": type(current).__name__,
|
||||||
"value_json": json.dumps(current, indent=2, ensure_ascii=False) if isinstance(current, (dict, list)) else str(current)
|
"value_json": json.dumps(current, indent=2, ensure_ascii=False) if isinstance(current, (dict, list)) else str(current),
|
||||||
|
"result_data": json.dumps(current, indent=2, ensure_ascii=False) if isinstance(current, (dict, list)) else str(current)
|
||||||
}
|
}
|
||||||
|
|
||||||
except (KeyError, IndexError, TypeError) as e:
|
except (KeyError, IndexError, TypeError) as e:
|
||||||
@@ -680,7 +681,8 @@ class JsonTool(BuiltinTool):
|
|||||||
"json_path": json_path,
|
"json_path": json_path,
|
||||||
"success": False,
|
"success": False,
|
||||||
"error": str(e),
|
"error": str(e),
|
||||||
"value": None
|
"value": None,
|
||||||
|
"result_data": None
|
||||||
}
|
}
|
||||||
|
|
||||||
def _analyze_json_structure(self, data: Any, depth: int = 0) -> Dict[str, Any]:
|
def _analyze_json_structure(self, data: Any, depth: int = 0) -> Dict[str, Any]:
|
||||||
|
|||||||
Reference in New Issue
Block a user