diff --git a/week2/community-contributions/Samuel_Bootcamp_wk2/Samuel week2 EXERCISE.ipynb b/week2/community-contributions/Samuel_Bootcamp_wk2/Samuel week2 EXERCISE.ipynb index 3e098f6..fb31c2d 100644 --- a/week2/community-contributions/Samuel_Bootcamp_wk2/Samuel week2 EXERCISE.ipynb +++ b/week2/community-contributions/Samuel_Bootcamp_wk2/Samuel week2 EXERCISE.ipynb @@ -19,13 +19,16 @@ ] }, { + "cell_type": "code", + "execution_count": null, + "id": "f69a564870ec63b0", "metadata": { "ExecuteTime": { "end_time": "2025-10-24T16:15:26.039019Z", "start_time": "2025-10-24T16:15:25.888596Z" } }, - "cell_type": "code", + "outputs": [], "source": [ "#Imports\n", "from IPython.display import Markdown, display\n", @@ -43,19 +46,19 @@ "from datetime import datetime\n", "import json\n", "import re\n" - ], - "id": "f69a564870ec63b0", - "outputs": [], - "execution_count": 5 + ] }, { + "cell_type": "code", + "execution_count": null, + "id": "fa60913187dbe71d", "metadata": { "ExecuteTime": { "end_time": "2025-10-24T16:14:27.703743Z", "start_time": "2025-10-24T16:14:27.677172Z" } }, - "cell_type": "code", + "outputs": [], "source": [ "OLLAMA_BASE_URL=\"http://localhost:11434/v1/completions\"\n", "LOCAL_MODEL_NAME=\"llama3.2\"\n", @@ -81,27 +84,19 @@ " print(\"An API key was found, but it looks like it might have space or tab characters at the start or end - please remove them - see troubleshooting notebook\")\n", "else:\n", " print(\"API key found and looks good so far!\")" - ], - "id": "fa60913187dbe71d", - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "API key found and looks good so far!\n" - ] - } - ], - "execution_count": 2 + ] }, { + "cell_type": "code", + "execution_count": null, + "id": "1bf8ccf240e982da", "metadata": { "ExecuteTime": { "end_time": "2025-10-24T16:14:35.695654Z", "start_time": "2025-10-24T16:14:35.681319Z" } }, - "cell_type": "code", + "outputs": [], "source": [ "# Ollama configuration\n", "OLLAMA_URL = os.getenv(\"OLLAMA_BASE_URL\", \"http://localhost:11434/v1/completions\")\n", @@ -110,37 +105,37 @@ "# OpenAI configuration\n", "OPENAI_API_KEY = os.getenv(\"OPENAI_API_KEY\")\n", "OPENAI_MODEL = \"gpt-4\"" - ], - "id": "1bf8ccf240e982da", - "outputs": [], - "execution_count": 3 + ] }, { + "cell_type": "code", + "execution_count": null, + "id": "98d8f6481681ed57", "metadata": { "ExecuteTime": { "end_time": "2025-10-24T16:14:49.865353Z", "start_time": "2025-10-24T16:14:49.848662Z" } }, - "cell_type": "code", + "outputs": [], "source": [ "# Crypto Analysis Prompt\n", "CRYPTO_SYSTEM_PROMPT = \"\"\"You are a specialized AI assistant with expertise in cryptocurrency markets and data analysis.\n", "Your role is to help users identify and understand cryptocurrencies with the strongest growth patterns over recent weeks.\n", "Provide clear, data-driven insights about market trends and performance metrics.\"\"\"\n" - ], - "id": "98d8f6481681ed57", - "outputs": [], - "execution_count": 4 + ] }, { + "cell_type": "code", + "execution_count": null, + "id": "7729697aa8937c3", "metadata": { "ExecuteTime": { "end_time": "2025-10-24T16:15:37.367235Z", "start_time": "2025-10-24T16:15:35.409542Z" } }, - "cell_type": "code", + "outputs": [], "source": [ "\n", "def scrape_coingecko(limit=10, debug=False):\n", @@ -246,210 +241,14 @@ " print(\"Testing CoinMarketCap with debug...\")\n", " result = get_top_performers(\"coinmarketcap\", 10, True, debug=True)\n", " print(json.dumps(result, indent=2))" - ], - "id": "7729697aa8937c3", - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Testing CoinGecko with debug...\n", - "Status: 200\n", - "HTML saved to debug_coingecko.html\n", - "Found 10 rows\n", - "Row texts: ['665', 'tokenbot', 'CLANKER', '$60.46', '$62,533,755']\n", - "Row texts: ['908', 'BabyBoomToken', 'BBT', '$0.2828', '$127,780']\n", - "Row texts: ['799', 'Torch of Liberty', 'LIBERTY', '$0.04491', '$4,206,524']\n", - "Row texts: ['632', 'SynFutures', 'F', '$0.02488', '$449,989,560']\n", - "Row texts: ['191', 'Humanity', 'H', '$0.2380', '$144,563,375']\n", - "Row texts: ['614', 'GeorgePlaysClashRoyale', 'CLASH', '$0.06571', '$4,339,198']\n", - "Row texts: ['819', 'BankrCoin', 'BNKR', '$0.0004429', '$3,604,689']\n", - "Row texts: ['502', 'Orderly', 'ORDER', '$0.3030', '$120,774,733']\n", - "Row texts: ['667', 'KGeN', 'KGEN', '$0.3160', '$20,717,235']\n", - "Row texts: ['442', 'XYO Network', 'XYO', '$0.009066', '$13,819,011']\n", - "Saved to crypto_coingecko_20251024_161536.json\n", - "{\n", - " \"timeframe\": \"30d\",\n", - " \"timestamp\": \"2025-10-24T16:15:36.665627\",\n", - " \"count\": 10,\n", - " \"top_performers\": [\n", - " {\n", - " \"name\": \"tokenbot\",\n", - " \"symbol\": \"CLANKER\",\n", - " \"current_price\": 60.46,\n", - " \"price_change_percentage_30d\": 136.3,\n", - " \"source\": \"coingecko\"\n", - " },\n", - " {\n", - " \"name\": \"BabyBoomToken\",\n", - " \"symbol\": \"BBT\",\n", - " \"current_price\": 0.2828,\n", - " \"price_change_percentage_30d\": 135.1,\n", - " \"source\": \"coingecko\"\n", - " },\n", - " {\n", - " \"name\": \"Torch of Liberty\",\n", - " \"symbol\": \"LIBERTY\",\n", - " \"current_price\": 0.04491,\n", - " \"price_change_percentage_30d\": 88.1,\n", - " \"source\": \"coingecko\"\n", - " },\n", - " {\n", - " \"name\": \"SynFutures\",\n", - " \"symbol\": \"F\",\n", - " \"current_price\": 0.02488,\n", - " \"price_change_percentage_30d\": 70.7,\n", - " \"source\": \"coingecko\"\n", - " },\n", - " {\n", - " \"name\": \"Humanity\",\n", - " \"symbol\": \"H\",\n", - " \"current_price\": 0.238,\n", - " \"price_change_percentage_30d\": 60.4,\n", - " \"source\": \"coingecko\"\n", - " },\n", - " {\n", - " \"name\": \"GeorgePlaysClashRoyale\",\n", - " \"symbol\": \"CLASH\",\n", - " \"current_price\": 0.06571,\n", - " \"price_change_percentage_30d\": 44.7,\n", - " \"source\": \"coingecko\"\n", - " },\n", - " {\n", - " \"name\": \"BankrCoin\",\n", - " \"symbol\": \"BNKR\",\n", - " \"current_price\": 0.0004429,\n", - " \"price_change_percentage_30d\": 44.5,\n", - " \"source\": \"coingecko\"\n", - " },\n", - " {\n", - " \"name\": \"Orderly\",\n", - " \"symbol\": \"ORDER\",\n", - " \"current_price\": 0.303,\n", - " \"price_change_percentage_30d\": 43.2,\n", - " \"source\": \"coingecko\"\n", - " },\n", - " {\n", - " \"name\": \"KGeN\",\n", - " \"symbol\": \"KGEN\",\n", - " \"current_price\": 0.316,\n", - " \"price_change_percentage_30d\": 30.5,\n", - " \"source\": \"coingecko\"\n", - " },\n", - " {\n", - " \"name\": \"XYO Network\",\n", - " \"symbol\": \"XYO\",\n", - " \"current_price\": 0.009066,\n", - " \"price_change_percentage_30d\": 29.8,\n", - " \"source\": \"coingecko\"\n", - " }\n", - " ]\n", - "}\n", - "\n", - "============================================================\n", - "\n", - "Testing CoinMarketCap with debug...\n", - "Status: 200\n", - "HTML saved to debug_coinmarketcap.html\n", - "Total rows found: 62\n", - "Row texts: ['91', 'MYX Finance', '91', 'MYX', '$3.10']\n", - "Row texts: ['95', 'Virtuals Protocol', '95', 'VIRTUAL', '$0.8882']\n", - "Row texts: ['65', 'Jupiter', '65', 'JUP', '$0.3792']\n", - "Row texts: ['34', 'World Liberty Financial', '34', 'WLFI', '$0.1357']\n", - "Row texts: ['28', 'Zcash', '28', 'ZEC', '$250.07']\n", - "Row texts: ['56', 'Pump.fun', '56', 'PUMP', '$0.003977']\n", - "Row texts: ['86', 'Morpho', '86', 'MORPHO', '$1.94']\n", - "Row texts: ['93', 'Artificial Superintelligence Alliance', '93', 'FET', '$0.2586']\n", - "Row texts: ['5', 'XRP', '5', 'XRP', '$2.48']\n", - "Row texts: ['15', 'Bitcoin Cash', '15', 'BCH', '$496.89']\n", - "Saved to crypto_coinmarketcap_20251024_161537.json\n", - "{\n", - " \"timeframe\": \"30d\",\n", - " \"timestamp\": \"2025-10-24T16:15:37.364932\",\n", - " \"count\": 10,\n", - " \"top_performers\": [\n", - " {\n", - " \"name\": \"MYX Finance\",\n", - " \"symbol\": \"91\",\n", - " \"current_price\": 3.1,\n", - " \"price_change_percentage_30d\": 14.83,\n", - " \"source\": \"coinmarketcap\"\n", - " },\n", - " {\n", - " \"name\": \"Virtuals Protocol\",\n", - " \"symbol\": \"95\",\n", - " \"current_price\": 0.8882,\n", - " \"price_change_percentage_30d\": 14.27,\n", - " \"source\": \"coinmarketcap\"\n", - " },\n", - " {\n", - " \"name\": \"Jupiter\",\n", - " \"symbol\": \"65\",\n", - " \"current_price\": 0.3792,\n", - " \"price_change_percentage_30d\": 7.51,\n", - " \"source\": \"coinmarketcap\"\n", - " },\n", - " {\n", - " \"name\": \"World Liberty Financial\",\n", - " \"symbol\": \"34\",\n", - " \"current_price\": 0.1357,\n", - " \"price_change_percentage_30d\": 5.59,\n", - " \"source\": \"coinmarketcap\"\n", - " },\n", - " {\n", - " \"name\": \"Zcash\",\n", - " \"symbol\": \"28\",\n", - " \"current_price\": 250.07,\n", - " \"price_change_percentage_30d\": 5.24,\n", - " \"source\": \"coinmarketcap\"\n", - " },\n", - " {\n", - " \"name\": \"Pump.fun\",\n", - " \"symbol\": \"56\",\n", - " \"current_price\": 0.003977,\n", - " \"price_change_percentage_30d\": 4.33,\n", - " \"source\": \"coinmarketcap\"\n", - " },\n", - " {\n", - " \"name\": \"Morpho\",\n", - " \"symbol\": \"86\",\n", - " \"current_price\": 1.94,\n", - " \"price_change_percentage_30d\": 4.17,\n", - " \"source\": \"coinmarketcap\"\n", - " },\n", - " {\n", - " \"name\": \"Artificial Superintelligence Alliance\",\n", - " \"symbol\": \"93\",\n", - " \"current_price\": 0.2586,\n", - " \"price_change_percentage_30d\": 3.97,\n", - " \"source\": \"coinmarketcap\"\n", - " },\n", - " {\n", - " \"name\": \"XRP\",\n", - " \"symbol\": \"5\",\n", - " \"current_price\": 2.48,\n", - " \"price_change_percentage_30d\": 2.84,\n", - " \"source\": \"coinmarketcap\"\n", - " },\n", - " {\n", - " \"name\": \"Bitcoin Cash\",\n", - " \"symbol\": \"15\",\n", - " \"current_price\": 496.89,\n", - " \"price_change_percentage_30d\": 2.76,\n", - " \"source\": \"coinmarketcap\"\n", - " }\n", - " ]\n", - "}\n" - ] - } - ], - "execution_count": 6 + ] }, { - "metadata": {}, "cell_type": "code", - "outputs": [], "execution_count": null, + "id": "2e3de36fa13f2dec", + "metadata": {}, + "outputs": [], "source": [ "def scrape_coinmarketcap(limit=10, debug=False):\n", " try:\n", @@ -521,17 +320,19 @@ " return {\"timeframe\": \"30d\", \"timestamp\": datetime.now().isoformat(), \"count\": len(top_performers), \"top_performers\": top_performers}\n", " except Exception as e:\n", " return {\"error\": str(e)}" - ], - "id": "2e3de36fa13f2dec" + ] }, { + "cell_type": "code", + "execution_count": null, + "id": "4a63cbcc7ae04c7e", "metadata": { "ExecuteTime": { "end_time": "2025-10-24T15:23:22.157803Z", "start_time": "2025-10-24T15:23:22.147500Z" } }, - "cell_type": "code", + "outputs": [], "source": [ "\n", "\n", @@ -546,27 +347,27 @@ " return True, get_top_performers(\"coingecko\", 10, True, debug=True)\n", "\n", "\n" - ], - "id": "4a63cbcc7ae04c7e", - "outputs": [], - "execution_count": 30 + ] }, { - "metadata": {}, "cell_type": "code", - "outputs": [], "execution_count": null, - "source": "", - "id": "626a022b562bf73d" + "id": "626a022b562bf73d", + "metadata": {}, + "outputs": [], + "source": [] }, { + "cell_type": "code", + "execution_count": null, + "id": "e5c6db45fb4d53d9", "metadata": { "ExecuteTime": { "end_time": "2025-10-24T15:23:25.205927Z", "start_time": "2025-10-24T15:23:25.199801Z" } }, - "cell_type": "code", + "outputs": [], "source": [ "def ask_ollama(prompt: str) -> str:\n", " try:\n", @@ -577,27 +378,27 @@ " return data.get(\"choices\", [{}])[0].get(\"text\", \"\").strip()\n", " except Exception as e:\n", " return f\"[Ollama error: {e}]\"" - ], - "id": "e5c6db45fb4d53d9", - "outputs": [], - "execution_count": 31 + ] }, { - "metadata": {}, "cell_type": "code", - "outputs": [], "execution_count": null, - "source": "", - "id": "2f81a00e9584d184" + "id": "2f81a00e9584d184", + "metadata": {}, + "outputs": [], + "source": [] }, { + "cell_type": "code", + "execution_count": null, + "id": "c2686a6503cf62a4", "metadata": { "ExecuteTime": { "end_time": "2025-10-24T15:23:29.556036Z", "start_time": "2025-10-24T15:23:29.552763Z" } }, - "cell_type": "code", + "outputs": [], "source": [ "def ask_openai(prompt: str) -> str:\n", " try:\n", @@ -615,19 +416,19 @@ " return response.choices[0].message.content\n", " except Exception as e:\n", " return f\"[OpenAI error: {e}]\"" - ], - "id": "c2686a6503cf62a4", - "outputs": [], - "execution_count": 32 + ] }, { + "cell_type": "code", + "execution_count": null, + "id": "2313e5940e9fa3da", "metadata": { "ExecuteTime": { "end_time": "2025-10-24T15:27:33.546418Z", "start_time": "2025-10-24T15:27:18.318834Z" } }, - "cell_type": "code", + "outputs": [], "source": [ "def chat_fn(user_message: str, history: List[List[str]], model_choice: str):\n", " tool_used, tool_output = detect_and_run_tool(user_message)\n", @@ -720,49 +521,15 @@ " demo.launch(server_name=\"0.0.0.0\", share=False)\n", "\n", "if __name__ == \"__main__\":\n", - " main()" - ], - "id": "2313e5940e9fa3da", - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "ERROR: [Errno 48] error while attempting to bind on address ('0.0.0.0', 7860): address already in use\n", - "ERROR: [Errno 48] error while attempting to bind on address ('0.0.0.0', 7861): address already in use\n", - "ERROR: [Errno 48] error while attempting to bind on address ('0.0.0.0', 7862): address already in use\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "* Running on local URL: http://0.0.0.0:7863\n", - "* To create a public link, set `share=True` in `launch()`.\n" - ] - }, - { - "data": { - "text/plain": [ - "" - ], - "text/html": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data", - "jetTransient": { - "display_id": null - } - } - ], - "execution_count": 35 + " main()\n", + "\n", + " " + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -776,7 +543,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.13" + "version": "3.12.12" } }, "nbformat": 4,