mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-03-19 21:38:18 +08:00
fix: optimize suggestion words and retries
This commit is contained in:
@@ -4,7 +4,6 @@ from agent.tools.tool_manager import ToolManager
|
||||
|
||||
# Import basic tools (no external dependencies)
|
||||
from agent.tools.calculator.calculator import Calculator
|
||||
from agent.tools.current_time.current_time import CurrentTime
|
||||
|
||||
# Import file operation tools
|
||||
from agent.tools.read.read import Read
|
||||
@@ -82,7 +81,6 @@ __all__ = [
|
||||
'BaseTool',
|
||||
'ToolManager',
|
||||
'Calculator',
|
||||
'CurrentTime',
|
||||
'Read',
|
||||
'Write',
|
||||
'Edit',
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
import datetime
|
||||
import time
|
||||
|
||||
from agent.tools.base_tool import BaseTool, ToolResult
|
||||
|
||||
|
||||
class CurrentTime(BaseTool):
|
||||
name: str = "time"
|
||||
description: str = "A tool to get current date and time information."
|
||||
params: dict = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"format": {
|
||||
"type": "string",
|
||||
"description": "Optional format for the time (e.g., 'iso', 'unix', 'human'). Default is 'human'."
|
||||
},
|
||||
"timezone": {
|
||||
"type": "string",
|
||||
"description": "Optional timezone specification (e.g., 'UTC', 'local'). Default is 'local'."
|
||||
}
|
||||
},
|
||||
"required": []
|
||||
}
|
||||
config: dict = {}
|
||||
|
||||
def execute(self, args: dict) -> ToolResult:
|
||||
try:
|
||||
# Get the format and timezone parameters, with defaults
|
||||
time_format = args.get("format", "human").lower()
|
||||
timezone = args.get("timezone", "local").lower()
|
||||
|
||||
# Get current time
|
||||
current_time = datetime.datetime.now()
|
||||
|
||||
# Handle timezone if specified
|
||||
if timezone == "utc":
|
||||
current_time = datetime.datetime.utcnow()
|
||||
|
||||
# Format the time according to the specified format
|
||||
if time_format == "iso":
|
||||
# ISO 8601 format
|
||||
formatted_time = current_time.isoformat()
|
||||
elif time_format == "unix":
|
||||
# Unix timestamp (seconds since epoch)
|
||||
formatted_time = time.time()
|
||||
else:
|
||||
# Human-readable format
|
||||
formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
# Prepare additional time components for the response
|
||||
year = current_time.year
|
||||
month = current_time.month
|
||||
day = current_time.day
|
||||
hour = current_time.hour
|
||||
minute = current_time.minute
|
||||
second = current_time.second
|
||||
weekday = current_time.strftime("%A") # Full weekday name
|
||||
|
||||
result = {
|
||||
"current_time": formatted_time,
|
||||
"components": {
|
||||
"year": year,
|
||||
"month": month,
|
||||
"day": day,
|
||||
"hour": hour,
|
||||
"minute": minute,
|
||||
"second": second,
|
||||
"weekday": weekday
|
||||
},
|
||||
"format": time_format,
|
||||
"timezone": timezone
|
||||
}
|
||||
return ToolResult.success(result=result)
|
||||
except Exception as e:
|
||||
return ToolResult.fail(result=str(e))
|
||||
Reference in New Issue
Block a user