- Enhanced `ARCHITECTURE.md` with details on LLM models for work (Llama 3.1 70B Q4) and family agents (Phi-3 Mini 3.8B Q4). - Introduced new documents: - `ASR_EVALUATION.md` for ASR engine evaluation and selection. - `HARDWARE.md` outlining hardware requirements and purchase plans. - `IMPLEMENTATION_GUIDE.md` for Milestone 2 implementation steps. - `LLM_CAPACITY.md` assessing VRAM and context window limits. - `LLM_MODEL_SURVEY.md` surveying open-weight LLM models. - `LLM_USAGE_AND_COSTS.md` detailing LLM usage and operational costs. - `MCP_ARCHITECTURE.md` describing the Model Context Protocol architecture. - `MCP_IMPLEMENTATION_SUMMARY.md` summarizing MCP implementation status. These updates provide comprehensive guidance for the next phases of development and ensure clarity in project documentation.
246 lines
8.2 KiB
Python
246 lines
8.2 KiB
Python
"""
|
|
Time and Date Tools - Get current time, date, and timezone information.
|
|
"""
|
|
|
|
from datetime import datetime
|
|
import pytz
|
|
from typing import Any, Dict, List
|
|
from tools.base import BaseTool
|
|
|
|
|
|
class GetCurrentTimeTool(BaseTool):
|
|
"""Get current local time with timezone."""
|
|
|
|
@property
|
|
def name(self) -> str:
|
|
return "get_current_time"
|
|
|
|
@property
|
|
def description(self) -> str:
|
|
return "Get the current local time with timezone information."
|
|
|
|
def get_schema(self) -> Dict[str, Any]:
|
|
"""Get tool schema."""
|
|
return {
|
|
"name": self.name,
|
|
"description": self.description,
|
|
"inputSchema": {
|
|
"type": "object",
|
|
"properties": {
|
|
"timezone": {
|
|
"type": "string",
|
|
"description": "Optional timezone (e.g., 'America/Los_Angeles'). Defaults to local timezone.",
|
|
"default": None
|
|
}
|
|
},
|
|
"required": []
|
|
}
|
|
}
|
|
|
|
def execute(self, arguments: Dict[str, Any]) -> str:
|
|
"""Execute get_current_time tool."""
|
|
timezone_str = arguments.get("timezone")
|
|
|
|
if timezone_str:
|
|
try:
|
|
tz = pytz.timezone(timezone_str)
|
|
now = datetime.now(tz)
|
|
except pytz.exceptions.UnknownTimeZoneError:
|
|
return f"Error: Unknown timezone '{timezone_str}'"
|
|
else:
|
|
now = datetime.now()
|
|
tz = now.astimezone().tzinfo
|
|
|
|
time_str = now.strftime("%I:%M:%S %p")
|
|
date_str = now.strftime("%A, %B %d, %Y")
|
|
timezone_name = str(tz) if tz else "local"
|
|
|
|
return f"Current time: {time_str} ({timezone_name})\nDate: {date_str}"
|
|
|
|
|
|
class GetDateTool(BaseTool):
|
|
"""Get current date information."""
|
|
|
|
@property
|
|
def name(self) -> str:
|
|
return "get_date"
|
|
|
|
@property
|
|
def description(self) -> str:
|
|
return "Get the current date information."
|
|
|
|
def get_schema(self) -> Dict[str, Any]:
|
|
"""Get tool schema."""
|
|
return {
|
|
"name": self.name,
|
|
"description": self.description,
|
|
"inputSchema": {
|
|
"type": "object",
|
|
"properties": {},
|
|
"required": []
|
|
}
|
|
}
|
|
|
|
def execute(self, arguments: Dict[str, Any]) -> str:
|
|
"""Execute get_date tool."""
|
|
now = datetime.now()
|
|
date_str = now.strftime("%A, %B %d, %Y")
|
|
day_of_year = now.timetuple().tm_yday
|
|
|
|
return f"Today's date: {date_str}\nDay of year: {day_of_year}"
|
|
|
|
|
|
class GetTimezoneInfoTool(BaseTool):
|
|
"""Get timezone information including DST."""
|
|
|
|
@property
|
|
def name(self) -> str:
|
|
return "get_timezone_info"
|
|
|
|
@property
|
|
def description(self) -> str:
|
|
return "Get timezone information including daylight saving time status and UTC offset."
|
|
|
|
def get_schema(self) -> Dict[str, Any]:
|
|
"""Get tool schema."""
|
|
return {
|
|
"name": self.name,
|
|
"description": self.description,
|
|
"inputSchema": {
|
|
"type": "object",
|
|
"properties": {
|
|
"timezone": {
|
|
"type": "string",
|
|
"description": "Timezone (e.g., 'America/Los_Angeles'). Defaults to local timezone.",
|
|
"default": None
|
|
}
|
|
},
|
|
"required": []
|
|
}
|
|
}
|
|
|
|
def execute(self, arguments: Dict[str, Any]) -> str:
|
|
"""Execute get_timezone_info tool."""
|
|
timezone_str = arguments.get("timezone")
|
|
|
|
if timezone_str:
|
|
try:
|
|
tz = pytz.timezone(timezone_str)
|
|
except pytz.exceptions.UnknownTimeZoneError:
|
|
return f"Error: Unknown timezone '{timezone_str}'"
|
|
else:
|
|
now = datetime.now()
|
|
tz = now.astimezone().tzinfo
|
|
if tz is None:
|
|
return "Error: Could not determine local timezone"
|
|
|
|
now = datetime.now(tz) if isinstance(tz, pytz.BaseTzInfo) else datetime.now()
|
|
if isinstance(tz, pytz.BaseTzInfo):
|
|
offset = now.strftime("%z")
|
|
offset_hours = int(offset) // 100 if offset else 0
|
|
is_dst = bool(now.dst())
|
|
dst_status = "Yes (DST active)" if is_dst else "No (standard time)"
|
|
else:
|
|
offset = now.strftime("%z")
|
|
offset_hours = int(offset) // 100 if offset else 0
|
|
is_dst = "Unknown"
|
|
dst_status = "Unknown"
|
|
|
|
timezone_name = str(tz)
|
|
utc_offset = f"UTC{offset_hours:+d}" if offset_hours != 0 else "UTC"
|
|
|
|
return f"Timezone: {timezone_name}\nUTC Offset: {utc_offset}\nDaylight Saving Time: {dst_status}"
|
|
|
|
|
|
class ConvertTimezoneTool(BaseTool):
|
|
"""Convert time between timezones."""
|
|
|
|
@property
|
|
def name(self) -> str:
|
|
return "convert_timezone"
|
|
|
|
@property
|
|
def description(self) -> str:
|
|
return "Convert a time from one timezone to another."
|
|
|
|
def get_schema(self) -> Dict[str, Any]:
|
|
"""Get tool schema."""
|
|
return {
|
|
"name": self.name,
|
|
"description": self.description,
|
|
"inputSchema": {
|
|
"type": "object",
|
|
"properties": {
|
|
"time": {
|
|
"type": "string",
|
|
"description": "Time to convert (e.g., '14:30' or '2:30 PM'). Defaults to current time."
|
|
},
|
|
"from_timezone": {
|
|
"type": "string",
|
|
"description": "Source timezone (e.g., 'America/New_York'). Defaults to local timezone."
|
|
},
|
|
"to_timezone": {
|
|
"type": "string",
|
|
"description": "Target timezone (e.g., 'Europe/London')",
|
|
"required": True
|
|
}
|
|
},
|
|
"required": ["to_timezone"]
|
|
}
|
|
}
|
|
|
|
def execute(self, arguments: Dict[str, Any]) -> str:
|
|
"""Execute convert_timezone tool."""
|
|
to_tz_str = arguments.get("to_timezone")
|
|
from_tz_str = arguments.get("from_timezone")
|
|
time_str = arguments.get("time")
|
|
|
|
try:
|
|
to_tz = pytz.timezone(to_tz_str)
|
|
except pytz.exceptions.UnknownTimeZoneError:
|
|
return f"Error: Unknown target timezone '{to_tz_str}'"
|
|
|
|
if time_str:
|
|
# Parse time string (simplified - could be enhanced)
|
|
try:
|
|
if from_tz_str:
|
|
from_tz = pytz.timezone(from_tz_str)
|
|
else:
|
|
from_tz = pytz.timezone('UTC') # Default to UTC if no source timezone
|
|
|
|
# Simple time parsing (could be enhanced)
|
|
now = datetime.now()
|
|
time_parts = time_str.split(':')
|
|
if len(time_parts) >= 2:
|
|
hour = int(time_parts[0])
|
|
minute = int(time_parts[1].split()[0])
|
|
dt = now.replace(hour=hour, minute=minute, second=0, microsecond=0)
|
|
else:
|
|
dt = now
|
|
|
|
dt = from_tz.localize(dt)
|
|
except Exception as e:
|
|
return f"Error parsing time: {e}"
|
|
else:
|
|
# Use current time
|
|
if from_tz_str:
|
|
try:
|
|
from_tz = pytz.timezone(from_tz_str)
|
|
except pytz.exceptions.UnknownTimeZoneError:
|
|
return f"Error: Unknown source timezone '{from_tz_str}'"
|
|
dt = datetime.now(from_tz)
|
|
else:
|
|
dt = datetime.now()
|
|
# Try to get local timezone
|
|
local_tz = dt.astimezone().tzinfo
|
|
if local_tz:
|
|
dt = dt.replace(tzinfo=local_tz)
|
|
else:
|
|
dt = pytz.UTC.localize(dt)
|
|
|
|
# Convert to target timezone
|
|
converted = dt.astimezone(to_tz)
|
|
result = converted.strftime("%I:%M:%S %p %Z on %A, %B %d, %Y")
|
|
|
|
return f"Converted time: {result} ({to_tz_str})"
|