Update app.py
Browse files
app.py
CHANGED
|
@@ -54,7 +54,7 @@ def play_voice_output(response):
|
|
| 54 |
|
| 55 |
# NumPy Code Calculator Tool
|
| 56 |
class NumpyCodeCalculator(Tool):
|
| 57 |
-
name = "
|
| 58 |
description = "Useful only for performing numerical computations, not for general searches"
|
| 59 |
|
| 60 |
def _run(self, query: str) -> str:
|
|
@@ -119,32 +119,11 @@ class DocumentQuestionAnswering(Tool):
|
|
| 119 |
response = self.qa_chain.run(query)
|
| 120 |
return str(response)
|
| 121 |
|
| 122 |
-
class DuckDuckGoSearchRun(Tool):
|
| 123 |
-
name = "Search"
|
| 124 |
-
description = "Useful for searching the internet for general information"
|
| 125 |
-
|
| 126 |
-
def _run(self, query: str) -> str:
|
| 127 |
-
url = "https://api.duckduckgo.com/"
|
| 128 |
-
params = {
|
| 129 |
-
"q": query,
|
| 130 |
-
"format": "json"
|
| 131 |
-
}
|
| 132 |
-
response = requests.get(url, params=params)
|
| 133 |
-
data = response.json()
|
| 134 |
-
answer = data["Abstract"]
|
| 135 |
-
return answer
|
| 136 |
|
| 137 |
# Function to handle different input types and choose the right tool
|
| 138 |
def handle_input(user_prompt, image=None, audio=None, websearch=False, document=None):
|
| 139 |
-
# Initialize the search tool
|
| 140 |
-
search = DuckDuckGoSearchRun()
|
| 141 |
|
| 142 |
tools = [
|
| 143 |
-
Tool(
|
| 144 |
-
name="Search",
|
| 145 |
-
func=search.run,
|
| 146 |
-
description="Useful for searching the internet for general information"
|
| 147 |
-
),
|
| 148 |
Tool(
|
| 149 |
name="Image",
|
| 150 |
func=ImageGeneration()._run,
|
|
@@ -154,7 +133,7 @@ def handle_input(user_prompt, image=None, audio=None, websearch=False, document=
|
|
| 154 |
|
| 155 |
# Add the numpy tool, but with a more specific description
|
| 156 |
tools.append(Tool(
|
| 157 |
-
name="
|
| 158 |
func=NumpyCodeCalculator()._run,
|
| 159 |
description="Useful only for performing numerical computations, not for general searches"
|
| 160 |
))
|
|
|
|
| 54 |
|
| 55 |
# NumPy Code Calculator Tool
|
| 56 |
class NumpyCodeCalculator(Tool):
|
| 57 |
+
name = "Calculator"
|
| 58 |
description = "Useful only for performing numerical computations, not for general searches"
|
| 59 |
|
| 60 |
def _run(self, query: str) -> str:
|
|
|
|
| 119 |
response = self.qa_chain.run(query)
|
| 120 |
return str(response)
|
| 121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
# Function to handle different input types and choose the right tool
|
| 124 |
def handle_input(user_prompt, image=None, audio=None, websearch=False, document=None):
|
|
|
|
|
|
|
| 125 |
|
| 126 |
tools = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
Tool(
|
| 128 |
name="Image",
|
| 129 |
func=ImageGeneration()._run,
|
|
|
|
| 133 |
|
| 134 |
# Add the numpy tool, but with a more specific description
|
| 135 |
tools.append(Tool(
|
| 136 |
+
name="Calculator",
|
| 137 |
func=NumpyCodeCalculator()._run,
|
| 138 |
description="Useful only for performing numerical computations, not for general searches"
|
| 139 |
))
|