web-search-mcp / utils /helpers.py
Shrijeeth-Suresh
feat: create web search MCP with DuckDuckGo integration and Gradio UI
3e53b8b
raw
history blame contribute delete
786 Bytes
import pandas as pd
async def map_results(results: list[dict], mapping: dict[str, str]) -> pd.DataFrame:
values = list(mapping.values())
if "title" not in values:
raise ValueError("title is required in the mapping")
if "link" not in values:
raise ValueError("link is required in the mapping")
if "body" not in values:
raise ValueError("body is required in the mapping")
mapped_data = [
{mapping.get(key, key): value for key, value in result.items()}
for result in results
]
result = {"title": [], "link": [], "body": []}
for data in mapped_data:
result["title"].append(data["title"])
result["link"].append(data["link"])
result["body"].append(data["body"])
return pd.DataFrame(result)