Spaces:
Running
Running
File size: 1,264 Bytes
7a96bd0 a15cde7 162482a c0dde41 7a96bd0 ffdad84 7a96bd0 50eb83e 7a96bd0 09909f3 50eb83e 05f62c8 7a96bd0 ffdad84 7a96bd0 b7b5135 7a96bd0 |
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 32 33 34 35 36 37 |
import os
from datetime import date
from langchain.agents import AgentType, initialize_agent, load_tools, tool
from langchain.chat_models import ChatOpenAI
os.environ["LANGCHAIN_API_KEY"] = os.environ["LANGCHAIN_API_KEY"]
os.environ["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com"
os.environ["LANGCHAIN_PROJECT"] = "default"
os.environ["LANGCHAIN_TRACING_V2"] = "true"
@tool
def today_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 agent_langchain(config, prompt):
llm = ChatOpenAI(
model_name = config["model"],
temperature = config["temperature"])
OPENWEATHERMAP_API_KEY = os.environ["OPENWEATHERMAP_API_KEY"]
tools = load_tools(["openweathermap-api"])
agent = initialize_agent(
tools + # built-in tools
[today_tool], # custom tools
llm,
agent = AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
handle_parsing_errors = True,
verbose = True
)
return agent(prompt) |