Ubik80 commited on
Commit
46b9160
·
verified ·
1 Parent(s): 5acef43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -43,8 +43,6 @@ final_answer = FinalAnswerTool()
43
 
44
  from smolagents import tool, DuckDuckGoSearchTool
45
 
46
- from smolagents import tool, DuckDuckGoSearchTool
47
-
48
  @tool
49
  def search_duckduckgo(query: str, num_results: int = 3) -> str:
50
  """Performs a web search using DuckDuckGo and returns multiple relevant results.
@@ -69,9 +67,16 @@ def search_duckduckgo(query: str, num_results: int = 3) -> str:
69
  if result_lines[i].startswith("[") and len(parsed_results) < num_results:
70
  title = result_lines[i][1:-1] # Extract title
71
  link = result_lines[i+1].strip() # Extract link
 
 
 
 
 
72
  summary = result_lines[i+2].strip() if i+2 < len(result_lines) else "No summary available."
73
 
74
- parsed_results.append(f"🔎 {title}\n{summary}\n🔗 {link}")
 
 
75
 
76
  if not parsed_results:
77
  return f"No valid results found for '{query}'."
@@ -80,6 +85,7 @@ def search_duckduckgo(query: str, num_results: int = 3) -> str:
80
 
81
 
82
 
 
83
  model = OpenAIServerModel(
84
  max_tokens=2096,
85
  temperature=0.5,
 
43
 
44
  from smolagents import tool, DuckDuckGoSearchTool
45
 
 
 
46
  @tool
47
  def search_duckduckgo(query: str, num_results: int = 3) -> str:
48
  """Performs a web search using DuckDuckGo and returns multiple relevant results.
 
67
  if result_lines[i].startswith("[") and len(parsed_results) < num_results:
68
  title = result_lines[i][1:-1] # Extract title
69
  link = result_lines[i+1].strip() # Extract link
70
+
71
+ # Fix broken links and remove extra characters
72
+ if not link.startswith("http"):
73
+ continue # Skip invalid links
74
+
75
  summary = result_lines[i+2].strip() if i+2 < len(result_lines) else "No summary available."
76
 
77
+ # Ensure the link format is clean
78
+ formatted_result = f"🔎 **[{title}]({link})**\n📌 {summary}"
79
+ parsed_results.append(formatted_result)
80
 
81
  if not parsed_results:
82
  return f"No valid results found for '{query}'."
 
85
 
86
 
87
 
88
+
89
  model = OpenAIServerModel(
90
  max_tokens=2096,
91
  temperature=0.5,