mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-19 09:30:15 +00:00
datetime tool
This commit is contained in:
parent
4e43b0efe9
commit
083b5b7d66
@ -13,6 +13,7 @@ from langchain.python import PythonREPL
|
|||||||
from langchain.requests import RequestsWrapper
|
from langchain.requests import RequestsWrapper
|
||||||
from langchain.tools.base import BaseTool
|
from langchain.tools.base import BaseTool
|
||||||
from langchain.tools.bing_search.tool import BingSearchRun
|
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.google_search.tool import GoogleSearchResults, GoogleSearchRun
|
||||||
from langchain.tools.wolfram_alpha.tool import WolframAlphaQueryRun
|
from langchain.tools.wolfram_alpha.tool import WolframAlphaQueryRun
|
||||||
from langchain.utilities.bash import BashProcess
|
from langchain.utilities.bash import BashProcess
|
||||||
@ -48,10 +49,15 @@ def _get_terminal() -> BaseTool:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_datetime() -> BaseTool:
|
||||||
|
return DateTimeTool()
|
||||||
|
|
||||||
|
|
||||||
_BASE_TOOLS = {
|
_BASE_TOOLS = {
|
||||||
"python_repl": _get_python_repl,
|
"python_repl": _get_python_repl,
|
||||||
"requests": _get_requests,
|
"requests": _get_requests,
|
||||||
"terminal": _get_terminal,
|
"terminal": _get_terminal,
|
||||||
|
"datetime": _get_datetime,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
24
langchain/tools/datetime.py
Normal file
24
langchain/tools/datetime.py
Normal 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")
|
Loading…
Reference in New Issue
Block a user