From aedfcfebb4f4e72f1baf430427002447826e203d Mon Sep 17 00:00:00 2001 From: Masih Moafi <132553157+MasihMoafi@users.noreply.github.com> Date: Mon, 3 Mar 2025 15:44:19 +0330 Subject: [PATCH] Update 5. URL-Scraper Agent.ipynb --- 5. URL-Scraper Agent.ipynb | 60 +------------------------------------- 1 file changed, 1 insertion(+), 59 deletions(-) diff --git a/5. URL-Scraper Agent.ipynb b/5. URL-Scraper Agent.ipynb index 3ef1a89..62d6964 100644 --- a/5. URL-Scraper Agent.ipynb +++ b/5. URL-Scraper Agent.ipynb @@ -113,62 +113,4 @@ "execution_count": null, "id": "cc9f2290-d16f-4722-857a-7996d4722857", "metadata": {}, - "outputs": [], - "source": [ - "import wikipedia\n", - "\n", - "def search_wikipedia(query, lang='fa'):\n", - " \"\"\"Search Wikipedia for the given query in Persian and return a summary of the page.\"\"\"\n", - " wikipedia.set_lang(lang) # Set language to Farsi\n", - " try:\n", - " # Fetch summary of the query from Persian Wikipedia\n", - " summary = wikipedia.summary(query, sentences=3)\n", - " return summary\n", - " except wikipedia.exceptions.DisambiguationError as e:\n", - " # Handle ambiguity, if there are multiple results\n", - " return f\"Multiple results found, try being more specific: {e.options}\"\n", - " except wikipedia.exceptions.HTTPTimeoutError:\n", - " return \"Error: Request timed out.\"\n", - " except wikipedia.exceptions.RedirectError:\n", - " return \"Error: The page has been redirected.\"\n", - " except wikipedia.exceptions.PageError:\n", - " return \"Error: The page doesn't exist.\"\n", - " except Exception as e:\n", - " return f\"An error occurred: {str(e)}\"\n", - "\n", - "def generate_answer(query):\n", - " \"\"\"Generate an answer by first checking Wikipedia.\"\"\"\n", - " # check Wikipedia\n", - " wikipedia_answer = search_wikipedia(query)\n", - " return wikipedia_answer\n", - "\n", - "if __name__ == \"__main__\":\n", - " query = \"شاه عباس صفوی که بود و چه کرد؟\"\n", - " \n", - " answer = generate_answer(query)\n", - " print(f\"Answer: {answer}\")" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.7" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} + "outputs": []