Spaces:
Running
Running
File size: 1,010 Bytes
c2515e1 cab5cd2 5d64b03 46e9da4 1de188f a09203a cab5cd2 a09203a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import os
from datetime import date
from langchain.agents import AgentType, initialize_agent, load_tools, tool
from langchain.chat_models import ChatOpenAI
OPENWEATHERMAP_API_KEY = os.environ["OPENWEATHERMAP_API_KEY"]
@tool
def date_tool(text: str) -> str:
"""Returns today's date. Use this for any questions related to knowing today's date.
The input should always be an empty string, and this function will always return today's date.
Any date mathematics should occur outside this function."""
return str(date.today())
def invoke_agent(model, temperature, prompt):
llm = ChatOpenAI(
model_name = model,
temperature = temperature)
tools = load_tools(["openweathermap-api"])
agent = initialize_agent(
tools + # built-in tools
[date_tool], # custom tools
llm,
agent = AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
handle_parsing_errors = True,
verbose = True)
return agent(prompt) |