| |
|
|
| def search_for_example_answers(query: str, num_results: int = 2): |
| """ |
| Performs a targeted web search for high-quality example answers to an interview question. |
| Note: Web search is disabled in this deployment to ensure compatibility. |
| """ |
| try: |
| from ddgs import DDGS |
| |
| search_query = f"expert sample answer for interview question: \"{query}\"" |
| print(f"π Searching for expert answers with query: '{search_query}'") |
| |
| with DDGS(timeout=10) as ddgs: |
| results = list(ddgs.text(search_query, max_results=num_results)) |
| |
| if not results: |
| print(" -> No example answers found.") |
| return "No example answers found on the web." |
| |
| formatted_results = "" |
| for i, res in enumerate(results): |
| formatted_results += f"Example Answer Source {i+1}:\nTitle: {res.get('title', 'N/A')}\nSnippet: {res.get('body', 'N/A')}\n\n" |
| |
| print(f" -> Found {len(results)} example answers.") |
| return formatted_results |
| |
| except ImportError: |
| print("π‘ Web search not available in this deployment (ddgs not installed)") |
| return "Web search not available in this deployment environment." |
| except Exception as e: |
| print(f"π₯ Web search failed: {e}") |
| return "Web search for example answers failed." |