Use Tavily Search instead of DuckDuckGoSearch
Browse files
app.py
CHANGED
|
@@ -14,7 +14,7 @@ from pydub import AudioSegment
|
|
| 14 |
import whisper
|
| 15 |
import pandas as pd
|
| 16 |
|
| 17 |
-
from duckduckgo_search import DDGS
|
| 18 |
|
| 19 |
from langgraph.graph import MessagesState, StateGraph, START
|
| 20 |
from langgraph.graph.message import add_messages
|
|
@@ -23,6 +23,7 @@ from langgraph.prebuilt import ToolNode, tools_condition
|
|
| 23 |
from langchain_openai import ChatOpenAI
|
| 24 |
from langchain_core.messages import SystemMessage, HumanMessage, AnyMessage
|
| 25 |
from langchain_core.tools import tool
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
# --- Constants ---
|
|
@@ -130,21 +131,17 @@ class BasicAgent:
|
|
| 130 |
|
| 131 |
@staticmethod
|
| 132 |
@tool(
|
| 133 |
-
description="Search the web using
|
| 134 |
)
|
| 135 |
-
def search_tool(question: str, max_length: int =
|
| 136 |
print(f"\nCalling search tool with: {question}, max_lentgh: {max_length}")
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
else:
|
| 145 |
-
result = ans[:max_length]
|
| 146 |
-
|
| 147 |
-
print("\nTool result:", result)
|
| 148 |
return result[:max_length]
|
| 149 |
|
| 150 |
@staticmethod
|
|
|
|
| 14 |
import whisper
|
| 15 |
import pandas as pd
|
| 16 |
|
| 17 |
+
# from duckduckgo_search import DDGS
|
| 18 |
|
| 19 |
from langgraph.graph import MessagesState, StateGraph, START
|
| 20 |
from langgraph.graph.message import add_messages
|
|
|
|
| 23 |
from langchain_openai import ChatOpenAI
|
| 24 |
from langchain_core.messages import SystemMessage, HumanMessage, AnyMessage
|
| 25 |
from langchain_core.tools import tool
|
| 26 |
+
from langchain_tavily import TavilySearch
|
| 27 |
|
| 28 |
|
| 29 |
# --- Constants ---
|
|
|
|
| 131 |
|
| 132 |
@staticmethod
|
| 133 |
@tool(
|
| 134 |
+
description="Search the web using TavilySearch and return the final snippet.",
|
| 135 |
)
|
| 136 |
+
def search_tool(question: str, max_length: int = 100000) -> str:
|
| 137 |
print(f"\nCalling search tool with: {question}, max_lentgh: {max_length}")
|
| 138 |
+
search_ = TavilySearch(
|
| 139 |
+
max_results=5,
|
| 140 |
+
topic="general",
|
| 141 |
+
)
|
| 142 |
+
info = search_.invoke({"query": question})
|
| 143 |
+
result = "\n".join(m["content"] for m in info["results"])
|
| 144 |
+
print("f\nSearch result: {result}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
return result[:max_length]
|
| 146 |
|
| 147 |
@staticmethod
|