Update main.py
Browse files
main.py
CHANGED
|
@@ -13,7 +13,7 @@ from pydantic import BaseModel
|
|
| 13 |
from dotenv import load_dotenv
|
| 14 |
import aiohttp
|
| 15 |
from bs4 import BeautifulSoup
|
| 16 |
-
from duckduckgo_search import
|
| 17 |
|
| 18 |
# --- Configuration ---
|
| 19 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
@@ -47,7 +47,7 @@ class DeepResearchRequest(BaseModel):
|
|
| 47 |
app = FastAPI(
|
| 48 |
title="AI Deep Research API",
|
| 49 |
description="Provides robust, long-form, streaming deep research completions using the DuckDuckGo Search API.",
|
| 50 |
-
version="9.1.
|
| 51 |
)
|
| 52 |
|
| 53 |
# Enable CORS for all origins
|
|
@@ -66,8 +66,10 @@ async def call_duckduckgo_search(query: str, max_results: int = 10) -> List[dict
|
|
| 66 |
"""Performs a search using the DuckDuckGo Search API."""
|
| 67 |
logger.info(f"Searching DuckDuckGo API for: '{query}'")
|
| 68 |
try:
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
| 71 |
|
| 72 |
# Map the response keys to the expected format
|
| 73 |
results = [
|
|
|
|
| 13 |
from dotenv import load_dotenv
|
| 14 |
import aiohttp
|
| 15 |
from bs4 import BeautifulSoup
|
| 16 |
+
from duckduckgo_search import DDGS # Corrected import
|
| 17 |
|
| 18 |
# --- Configuration ---
|
| 19 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
|
|
| 47 |
app = FastAPI(
|
| 48 |
title="AI Deep Research API",
|
| 49 |
description="Provides robust, long-form, streaming deep research completions using the DuckDuckGo Search API.",
|
| 50 |
+
version="9.1.1" # Patched version
|
| 51 |
)
|
| 52 |
|
| 53 |
# Enable CORS for all origins
|
|
|
|
| 66 |
"""Performs a search using the DuckDuckGo Search API."""
|
| 67 |
logger.info(f"Searching DuckDuckGo API for: '{query}'")
|
| 68 |
try:
|
| 69 |
+
# Use the unified DDGS client
|
| 70 |
+
async with DDGS() as ddgs:
|
| 71 |
+
# Use the async `atext` method and an async list comprehension
|
| 72 |
+
raw_results = [r async for r in ddgs.atext(query, max_results=max_results)]
|
| 73 |
|
| 74 |
# Map the response keys to the expected format
|
| 75 |
results = [
|