Spaces:
Build error
Build error
T-K-O-H commited on
Commit ·
8130aa2
1
Parent(s): abd0d1f
Rename search_web to weather_tool and make it weather-specific
Browse files
app.py
CHANGED
|
@@ -48,17 +48,27 @@ app = FastAPI()
|
|
| 48 |
|
| 49 |
# Define tools
|
| 50 |
@tool
|
| 51 |
-
def
|
| 52 |
-
"""
|
| 53 |
-
logger.info(f"
|
| 54 |
try:
|
| 55 |
search = DuckDuckGoSearchAPIWrapper()
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
except Exception as e:
|
| 60 |
-
logger.error(f"Error
|
| 61 |
-
return f"Error
|
| 62 |
|
| 63 |
|
| 64 |
@tool
|
|
@@ -96,7 +106,7 @@ def generate_image_prompt(description: str) -> str:
|
|
| 96 |
|
| 97 |
# Create tools list
|
| 98 |
logger.info("Creating tools list...")
|
| 99 |
-
tools = [
|
| 100 |
|
| 101 |
# Set up the language model
|
| 102 |
logger.info("Initializing ChatOpenAI model...")
|
|
@@ -145,7 +155,7 @@ def create_agent_node():
|
|
| 145 |
# System prompt for the agent
|
| 146 |
system_prompt = """You are a helpful AI assistant with access to the following tools:
|
| 147 |
|
| 148 |
-
1.
|
| 149 |
2. calculate: Calculate the result of mathematical expressions
|
| 150 |
3. generate_image_prompt: Generate prompts for image generation
|
| 151 |
|
|
|
|
| 48 |
|
| 49 |
# Define tools
|
| 50 |
@tool
|
| 51 |
+
def weather_tool(query: str) -> str:
|
| 52 |
+
"""Get weather information for a specific location or query."""
|
| 53 |
+
logger.info(f"Getting weather information for: {query}")
|
| 54 |
try:
|
| 55 |
search = DuckDuckGoSearchAPIWrapper()
|
| 56 |
+
# Focus the search on weather information
|
| 57 |
+
weather_query = f"current weather {query} site:weather.com OR site:accuweather.com"
|
| 58 |
+
results = search.run(weather_query)
|
| 59 |
+
|
| 60 |
+
if not results:
|
| 61 |
+
# If no specific weather results, try a more general weather search
|
| 62 |
+
results = search.run(f"weather {query}")
|
| 63 |
+
|
| 64 |
+
if not results:
|
| 65 |
+
return f"I couldn't find weather information for '{query}'. Please specify a location or try rephrasing your question."
|
| 66 |
+
|
| 67 |
+
logger.info(f"Weather results: {results}")
|
| 68 |
+
return f"Here's the weather information for {query}:\n\n{results}"
|
| 69 |
except Exception as e:
|
| 70 |
+
logger.error(f"Error getting weather information: {str(e)}")
|
| 71 |
+
return f"Error getting weather information: {str(e)}"
|
| 72 |
|
| 73 |
|
| 74 |
@tool
|
|
|
|
| 106 |
|
| 107 |
# Create tools list
|
| 108 |
logger.info("Creating tools list...")
|
| 109 |
+
tools = [weather_tool, calculate, generate_image_prompt]
|
| 110 |
|
| 111 |
# Set up the language model
|
| 112 |
logger.info("Initializing ChatOpenAI model...")
|
|
|
|
| 155 |
# System prompt for the agent
|
| 156 |
system_prompt = """You are a helpful AI assistant with access to the following tools:
|
| 157 |
|
| 158 |
+
1. weather_tool: Get weather information
|
| 159 |
2. calculate: Calculate the result of mathematical expressions
|
| 160 |
3. generate_image_prompt: Generate prompts for image generation
|
| 161 |
|