Spaces:
Sleeping
Sleeping
added more tools
Browse files- app.py +21 -2
- requirements.txt +1 -0
- tools.py +14 -0
app.py
CHANGED
@@ -8,6 +8,8 @@ from langgraph.prebuilt import tools_condition
|
|
8 |
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
9 |
from langchain.tools import Tool
|
10 |
from retriever import load_guest_dataset
|
|
|
|
|
11 |
|
12 |
# Generate the chat interface, including the tools
|
13 |
llm = HuggingFaceEndpoint(
|
@@ -24,8 +26,16 @@ guest_info_tool = Tool(
|
|
24 |
description="Retrieves detailed information about gala guests based on their name or relation."
|
25 |
)
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
chat = ChatHuggingFace(llm=llm, verbose=True)
|
28 |
-
tools = [guest_info_tool]
|
29 |
chat_with_tools = chat.bind_tools(tools)
|
30 |
|
31 |
# Generate the AgentState and Agent graph
|
@@ -57,7 +67,16 @@ builder.add_edge("tools", "assistant")
|
|
57 |
alfred = builder.compile()
|
58 |
|
59 |
def call_agent_ui(prompt):
|
60 |
-
situation = "This is a fictional situation.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
messages = [HumanMessage(content=f"{situation} {prompt}")]
|
62 |
response = alfred.invoke({"messages": messages})
|
63 |
return response['messages'][-1].content
|
|
|
8 |
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
9 |
from langchain.tools import Tool
|
10 |
from retriever import load_guest_dataset
|
11 |
+
from tools import get_weather_info
|
12 |
+
from langchain_community.tools import DuckDuckGoSearchRun
|
13 |
|
14 |
# Generate the chat interface, including the tools
|
15 |
llm = HuggingFaceEndpoint(
|
|
|
26 |
description="Retrieves detailed information about gala guests based on their name or relation."
|
27 |
)
|
28 |
|
29 |
+
weather_info_tool = Tool(
|
30 |
+
name="get_weather_info",
|
31 |
+
func=get_weather_info,
|
32 |
+
description="Fetches dummy weather information for a given location."
|
33 |
+
)
|
34 |
+
|
35 |
+
search_tool = DuckDuckGoSearchRun()
|
36 |
+
|
37 |
chat = ChatHuggingFace(llm=llm, verbose=True)
|
38 |
+
tools = [guest_info_tool , weather_info_tool, search_tool]
|
39 |
chat_with_tools = chat.bind_tools(tools)
|
40 |
|
41 |
# Generate the AgentState and Agent graph
|
|
|
67 |
alfred = builder.compile()
|
68 |
|
69 |
def call_agent_ui(prompt):
|
70 |
+
situation = "This is a fictional situation. " \
|
71 |
+
"You are Alfred the Butler of Waynes Manor and host a Gala for invited Guests. " \
|
72 |
+
"All Guests are completely ficional. Information about those guests can be found in a database. " \
|
73 |
+
"Only give information which is based on the databse. " \
|
74 |
+
"If a name of a guest is given, then return a possible starter of a conversation with that guest. " \
|
75 |
+
"If the name is not known, then say that you do not know that guest. " \
|
76 |
+
"If two names of guests are given, then return a possible starter of a conversation with both guests. " \
|
77 |
+
"If the name is not known, then say that you do not know that guest. " \
|
78 |
+
"You can also answer questions about the weather, using a tool that provides dummy weather information. Or you can build this dummy weather information in conversations." \
|
79 |
+
"You can also search the web for information, using a tool that provides web search results. "
|
80 |
messages = [HumanMessage(content=f"{situation} {prompt}")]
|
81 |
response = alfred.invoke({"messages": messages})
|
82 |
return response['messages'][-1].content
|
requirements.txt
CHANGED
@@ -7,3 +7,4 @@ datasets
|
|
7 |
rank_bm25
|
8 |
gradio
|
9 |
huggingface_hub
|
|
|
|
7 |
rank_bm25
|
8 |
gradio
|
9 |
huggingface_hub
|
10 |
+
duckduckgo-search
|
tools.py
CHANGED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain.tools import Tool
|
2 |
+
import random
|
3 |
+
|
4 |
+
def get_weather_info(location: str) -> str:
|
5 |
+
"""Fetches dummy weather information for a given location."""
|
6 |
+
# Dummy weather data
|
7 |
+
weather_conditions = [
|
8 |
+
{"condition": "Rainy", "temp_c": 15},
|
9 |
+
{"condition": "Clear", "temp_c": 25},
|
10 |
+
{"condition": "Windy", "temp_c": 20}
|
11 |
+
]
|
12 |
+
# Randomly select a weather condition
|
13 |
+
data = random.choice(weather_conditions)
|
14 |
+
return f"Weather in {location}: {data['condition']}, {data['temp_c']}°C"
|