Update app.py
Browse files
app.py
CHANGED
|
@@ -7,10 +7,10 @@ import requests
|
|
| 7 |
import random
|
| 8 |
import urllib.parse
|
| 9 |
from tempfile import NamedTemporaryFile
|
| 10 |
-
from typing import List
|
| 11 |
from bs4 import BeautifulSoup
|
| 12 |
import logging
|
| 13 |
-
from duckduckgo_search import
|
| 14 |
|
| 15 |
from langchain_community.llms import HuggingFaceHub
|
| 16 |
from langchain_community.vectorstores import FAISS
|
|
@@ -152,7 +152,8 @@ def google_search(term, num_results=5, lang="en", timeout=5, safe="active", ssl_
|
|
| 152 |
|
| 153 |
def duckduckgo_search(query, max_results=5):
|
| 154 |
try:
|
| 155 |
-
|
|
|
|
| 156 |
formatted_results = []
|
| 157 |
for result in results:
|
| 158 |
formatted_results.append({
|
|
@@ -163,6 +164,7 @@ def duckduckgo_search(query, max_results=5):
|
|
| 163 |
except Exception as e:
|
| 164 |
print(f"Error in DuckDuckGo search: {e}")
|
| 165 |
return [{"link": None, "text": "No information found in the web search results."}]
|
|
|
|
| 166 |
|
| 167 |
def respond(
|
| 168 |
message,
|
|
|
|
| 7 |
import random
|
| 8 |
import urllib.parse
|
| 9 |
from tempfile import NamedTemporaryFile
|
| 10 |
+
from typing import List, Dict, Optional
|
| 11 |
from bs4 import BeautifulSoup
|
| 12 |
import logging
|
| 13 |
+
from duckduckgo_search import DDGS
|
| 14 |
|
| 15 |
from langchain_community.llms import HuggingFaceHub
|
| 16 |
from langchain_community.vectorstores import FAISS
|
|
|
|
| 152 |
|
| 153 |
def duckduckgo_search(query, max_results=5):
|
| 154 |
try:
|
| 155 |
+
search = DDGSearch()
|
| 156 |
+
results = search.text(query, max_results=max_results)
|
| 157 |
formatted_results = []
|
| 158 |
for result in results:
|
| 159 |
formatted_results.append({
|
|
|
|
| 164 |
except Exception as e:
|
| 165 |
print(f"Error in DuckDuckGo search: {e}")
|
| 166 |
return [{"link": None, "text": "No information found in the web search results."}]
|
| 167 |
+
Now, let's update the imports at the begin
|
| 168 |
|
| 169 |
def respond(
|
| 170 |
message,
|