ameglei-external commited on
Commit
ff707c1
·
verified ·
1 Parent(s): 41672d1

Use Tavily Search instead of DuckDuckGoSearch

Browse files
Files changed (1) hide show
  1. app.py +11 -14
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 DuckDuckGo and return the best result snippet.",
134
  )
135
- def search_tool(question: str, max_length: int = 20000) -> str:
136
  print(f"\nCalling search tool with: {question}, max_lentgh: {max_length}")
137
- with DDGS() as ddgs:
138
- hits = list(ddgs.text(question, max_results=5))
139
- print("\nGot from DDGS:", hits)
140
- ans = "\n".join((r.get("body") or r.get("snippet", "") for r in hits))
141
-
142
- if not ans:
143
- result = "No instant answer available for that query."
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