Scott Cogan
commited on
Commit
·
7153704
1
Parent(s):
b78f79e
debug
Browse files
app.py
CHANGED
|
@@ -101,14 +101,32 @@ def open_youtube_video(url: str, query: str) -> str:
|
|
| 101 |
|
| 102 |
@tool
|
| 103 |
def google_search(query: str) -> str:
|
| 104 |
-
'''Performs a
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
def log_message(message: BaseMessage, prefix: str = ""):
|
| 114 |
"""Helper function to log message details."""
|
|
@@ -150,12 +168,23 @@ class BasicAgent:
|
|
| 150 |
self.tool_executor = ToolExecutor(self.tools)
|
| 151 |
|
| 152 |
# System message
|
| 153 |
-
self.sys_msg = SystemMessage('''You are a general AI assistant. I will ask you a question.
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
If
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
# Create the graph
|
| 161 |
self.workflow = StateGraph(AgentState)
|
|
|
|
| 101 |
|
| 102 |
@tool
|
| 103 |
def google_search(query: str) -> str:
|
| 104 |
+
'''Performs a web search for the given query using DuckDuckGo.'''
|
| 105 |
+
try:
|
| 106 |
+
response = requests.get(
|
| 107 |
+
"https://api.duckduckgo.com/",
|
| 108 |
+
params={
|
| 109 |
+
"q": query,
|
| 110 |
+
"format": "json",
|
| 111 |
+
"no_html": 1,
|
| 112 |
+
"no_redirect": 1
|
| 113 |
+
}
|
| 114 |
+
)
|
| 115 |
+
response.raise_for_status()
|
| 116 |
+
data = response.json()
|
| 117 |
+
|
| 118 |
+
# Combine Abstract and Related Topics for a comprehensive response
|
| 119 |
+
result = []
|
| 120 |
+
if data.get("Abstract"):
|
| 121 |
+
result.append(data["Abstract"])
|
| 122 |
+
if data.get("RelatedTopics"):
|
| 123 |
+
for topic in data["RelatedTopics"][:3]: # Limit to first 3 related topics
|
| 124 |
+
if "Text" in topic:
|
| 125 |
+
result.append(topic["Text"])
|
| 126 |
+
|
| 127 |
+
return "\n".join(result) if result else "No results found."
|
| 128 |
+
except Exception as e:
|
| 129 |
+
return f"Error performing search: {str(e)}"
|
| 130 |
|
| 131 |
def log_message(message: BaseMessage, prefix: str = ""):
|
| 132 |
"""Helper function to log message details."""
|
|
|
|
| 168 |
self.tool_executor = ToolExecutor(self.tools)
|
| 169 |
|
| 170 |
# System message
|
| 171 |
+
self.sys_msg = SystemMessage('''You are a general AI assistant. I will ask you a question. Follow these steps:
|
| 172 |
+
1. First, use the google_search tool to find relevant information about the question.
|
| 173 |
+
2. Analyze the search results to find the specific information needed.
|
| 174 |
+
3. If needed, use additional tools to gather more information.
|
| 175 |
+
4. Only after gathering all necessary information, provide YOUR FINAL ANSWER.
|
| 176 |
+
|
| 177 |
+
YOUR FINAL ANSWER should be:
|
| 178 |
+
- A number (not written as a word) if asked for a quantity
|
| 179 |
+
- As few words as possible if asked for a string
|
| 180 |
+
- A comma separated list of numbers and/or strings if asked for a list
|
| 181 |
+
|
| 182 |
+
Rules for formatting:
|
| 183 |
+
- For numbers: Don't use commas or units ($, %, etc.) unless specified
|
| 184 |
+
- For strings: Don't use articles or abbreviations
|
| 185 |
+
- For lists: Apply the above rules based on whether each element is a number or string
|
| 186 |
+
|
| 187 |
+
You MUST use tools to verify information before providing your final answer.''')
|
| 188 |
|
| 189 |
# Create the graph
|
| 190 |
self.workflow = StateGraph(AgentState)
|