Browse Source

Add datetime tool to gptbot

Introduced a new 'datetime' tool to the gptbot, which provides the current date and time in UTC. This enhancement caters to the need for time-related queries within the bot's functionality, expanding its utility for users dealing with time-sensitive information.
Kumi 1 year ago
parent
commit
eba650188b
2 changed files with 17 additions and 0 deletions
  1. 1 0
      src/gptbot/tools/__init__.py
  2. 16 0
      src/gptbot/tools/datetime.py

+ 1 - 0
src/gptbot/tools/__init__.py

@@ -13,6 +13,7 @@ for tool in [
     "imagine",
     "imagedescription",
     "wikipedia",
+    "datetime",
 ]:
     tool_class = getattr(import_module(
         "." + tool, "gptbot.tools"), tool.capitalize())

+ 16 - 0
src/gptbot/tools/datetime.py

@@ -0,0 +1,16 @@
+from .base import BaseTool
+
+from datetime import datetime
+
+class Datetime(BaseTool):
+    DESCRIPTION = "Get the current date and time."
+    PARAMETERS = {
+        "type": "object",
+        "properties": {
+        },
+    }
+
+    async def run(self):
+        """Get the current date and time."""
+        return f"""**Current date and time (UTC)**
+{datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")}"""