datetime tool

This commit is contained in:
Harrison Chase 2023-02-21 13:22:23 -08:00
parent 4e43b0efe9
commit 083b5b7d66
2 changed files with 30 additions and 0 deletions

View File

@ -13,6 +13,7 @@ from langchain.python import PythonREPL
from langchain.requests import RequestsWrapper
from langchain.tools.base import BaseTool
from langchain.tools.bing_search.tool import BingSearchRun
from langchain.tools.datetime import DateTimeTool
from langchain.tools.google_search.tool import GoogleSearchResults, GoogleSearchRun
from langchain.tools.wolfram_alpha.tool import WolframAlphaQueryRun
from langchain.utilities.bash import BashProcess
@ -48,10 +49,15 @@ def _get_terminal() -> BaseTool:
)
def _get_datetime() -> BaseTool:
return DateTimeTool()
_BASE_TOOLS = {
"python_repl": _get_python_repl,
"requests": _get_requests,
"terminal": _get_terminal,
"datetime": _get_datetime,
}

View File

@ -0,0 +1,24 @@
"""Tool to get the current date and time."""
from datetime import datetime
from langchain.tools.base import BaseTool
class DateTimeTool(BaseTool):
"""Tool to get the current date and time."""
name = "DateTime"
description = (
"A method to get the CURRENT date and time. "
"The input to this should be an empty string."
)
def _run(self, query: str) -> str:
"""Use the DateTime tool."""
now = datetime.now()
dt_string = now.strftime("%A, %m/%d/%Y %H:%M:%S")
return f"The current date and time is: {dt_string}"
async def _arun(self, query: str) -> str:
"""Use the DateTime tool asynchronously."""
raise NotImplementedError("DateTimeTool does not support async")