From 8338dfc2487ab1eefb433b6e1a30d3145d26ce78 Mon Sep 17 00:00:00 2001 From: Edward Donner Date: Sat, 1 Mar 2025 15:03:18 -0500 Subject: [PATCH] Minor improvements including consistently setting override to True when loading dotenv --- week1/troubleshooting.ipynb | 7 ++- ...day4-airlines-project-fullyCustomize.ipynb | 18 ++++---- week3/day3.ipynb | 8 ---- week4/day3.ipynb | 2 +- week4/day4.ipynb | 2 +- week5/day1.ipynb | 2 +- week5/day2.ipynb | 2 +- week5/day3.ipynb | 2 +- week5/day4.5.ipynb | 2 +- week5/day4.ipynb | 2 +- week5/day5.ipynb | 2 +- week6/day1.ipynb | 2 +- week6/day2.ipynb | 2 +- week6/day3.ipynb | 2 +- week6/day4-results.ipynb | 2 +- week6/day4.ipynb | 2 +- week6/day5-results.ipynb | 4 +- week6/day5.ipynb | 2 +- week8/day1.ipynb | 45 +++++++++++++++++-- week8/day2.0.ipynb | 2 +- week8/day2.3.ipynb | 2 +- week8/day2.4.ipynb | 2 +- week8/day3.ipynb | 2 +- week8/day4.ipynb | 2 +- week8/hello.py | 11 +++++ week8/pricer_service2.py | 1 - 26 files changed, 89 insertions(+), 43 deletions(-) diff --git a/week1/troubleshooting.ipynb b/week1/troubleshooting.ipynb index c9dfe43..51146a4 100644 --- a/week1/troubleshooting.ipynb +++ b/week1/troubleshooting.ipynb @@ -427,7 +427,12 @@ "with: \n", "`import httpx` \n", "`openai = OpenAI(http_client=httpx.Client(verify=False))` \n", - "And if that works, you're in good shape. You'll just have to change the labs in the same way any time you hit this cert error.\n", + "And also please replace: \n", + "`requests.get(url, headers=headers)` \n", + "with: \n", + "`requests.get(url, headers=headers, verify=False)` \n", + "And if that works, you're in good shape. You'll just have to change the labs in the same way any time you hit this cert error. \n", + "This approach isn't OK for production code, but it's fine for our experiments. You may need to contact IT support to understand whether there are restrictions in your environment.\n", "\n", "## If all else fails:\n", "\n", diff --git a/week2/community-contributions/day4-airlines-project-fullyCustomize.ipynb b/week2/community-contributions/day4-airlines-project-fullyCustomize.ipynb index 04a0cf4..576c4e9 100644 --- a/week2/community-contributions/day4-airlines-project-fullyCustomize.ipynb +++ b/week2/community-contributions/day4-airlines-project-fullyCustomize.ipynb @@ -82,7 +82,7 @@ }, { "cell_type": "code", - "execution_count": 155, + "execution_count": null, "id": "0a521d84-d07c-49ab-a0df-d6451499ed97", "metadata": {}, "outputs": [], @@ -116,7 +116,7 @@ }, { "cell_type": "code", - "execution_count": 156, + "execution_count": null, "id": "61a2a15d-b559-4844-b377-6bd5cb4949f6", "metadata": {}, "outputs": [], @@ -212,7 +212,7 @@ }, { "cell_type": "code", - "execution_count": 157, + "execution_count": null, "id": "0696acb1-0b05-4dc2-80d5-771be04f1fb2", "metadata": {}, "outputs": [], @@ -223,7 +223,7 @@ }, { "cell_type": "code", - "execution_count": 158, + "execution_count": null, "id": "80ca4e09-6287-4d3f-997d-fa6afbcf6c85", "metadata": {}, "outputs": [], @@ -373,7 +373,7 @@ }, { "cell_type": "code", - "execution_count": 159, + "execution_count": null, "id": "39fb9008", "metadata": {}, "outputs": [], @@ -475,7 +475,7 @@ }, { "cell_type": "code", - "execution_count": 160, + "execution_count": null, "id": "1f003836", "metadata": {}, "outputs": [], @@ -547,7 +547,7 @@ }, { "cell_type": "code", - "execution_count": 161, + "execution_count": null, "id": "f6b34b32", "metadata": {}, "outputs": [], @@ -618,7 +618,7 @@ ], "metadata": { "kernelspec": { - "display_name": "llm_env", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -632,7 +632,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week3/day3.ipynb b/week3/day3.ipynb index 03c847e..de7b73b 100644 --- a/week3/day3.ipynb +++ b/week3/day3.ipynb @@ -11,14 +11,6 @@ "\n", "https://colab.research.google.com/drive/1WD6Y2N7ctQi1X9wa6rpkg8UfyA4iSVuz?usp=sharing" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "e9289ba7-200c-43a9-b67a-c5ce826c9537", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/week4/day3.ipynb b/week4/day3.ipynb index bfa8765..68cca5b 100644 --- a/week4/day3.ipynb +++ b/week4/day3.ipynb @@ -86,7 +86,7 @@ "source": [ "# environment\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['ANTHROPIC_API_KEY'] = os.getenv('ANTHROPIC_API_KEY', 'your-key-if-not-using-env')" ] diff --git a/week4/day4.ipynb b/week4/day4.ipynb index 9317f9a..91802cf 100644 --- a/week4/day4.ipynb +++ b/week4/day4.ipynb @@ -69,7 +69,7 @@ "source": [ "# environment\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['ANTHROPIC_API_KEY'] = os.getenv('ANTHROPIC_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['HF_TOKEN'] = os.getenv('HF_TOKEN', 'your-key-if-not-using-env')" diff --git a/week5/day1.ipynb b/week5/day1.ipynb index f4bc48e..416a1a0 100644 --- a/week5/day1.ipynb +++ b/week5/day1.ipynb @@ -57,7 +57,7 @@ "source": [ "# Load environment variables in a file called .env\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n", "openai = OpenAI()" ] diff --git a/week5/day2.ipynb b/week5/day2.ipynb index 8c19368..9ca0cb4 100644 --- a/week5/day2.ipynb +++ b/week5/day2.ipynb @@ -64,7 +64,7 @@ "source": [ "# Load environment variables in a file called .env\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')" ] }, diff --git a/week5/day3.ipynb b/week5/day3.ipynb index 349cb6b..6d2523c 100644 --- a/week5/day3.ipynb +++ b/week5/day3.ipynb @@ -70,7 +70,7 @@ "source": [ "# Load environment variables in a file called .env\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')" ] }, diff --git a/week5/day4.5.ipynb b/week5/day4.5.ipynb index a02b9cd..cf30df3 100644 --- a/week5/day4.5.ipynb +++ b/week5/day4.5.ipynb @@ -71,7 +71,7 @@ "source": [ "# Load environment variables in a file called .env\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')" ] }, diff --git a/week5/day4.ipynb b/week5/day4.ipynb index de5e45a..78b0ed7 100644 --- a/week5/day4.ipynb +++ b/week5/day4.ipynb @@ -72,7 +72,7 @@ "source": [ "# Load environment variables in a file called .env\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')" ] }, diff --git a/week5/day5.ipynb b/week5/day5.ipynb index cbd17b6..b9643a6 100644 --- a/week5/day5.ipynb +++ b/week5/day5.ipynb @@ -76,7 +76,7 @@ "source": [ "# Load environment variables in a file called .env\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')" ] }, diff --git a/week6/day1.ipynb b/week6/day1.ipynb index c424656..804f1d0 100644 --- a/week6/day1.ipynb +++ b/week6/day1.ipynb @@ -47,7 +47,7 @@ "source": [ "# environment\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['ANTHROPIC_API_KEY'] = os.getenv('ANTHROPIC_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['HF_TOKEN'] = os.getenv('HF_TOKEN', 'your-key-if-not-using-env')" diff --git a/week6/day2.ipynb b/week6/day2.ipynb index d365869..55c1446 100644 --- a/week6/day2.ipynb +++ b/week6/day2.ipynb @@ -60,7 +60,7 @@ "source": [ "# environment\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['ANTHROPIC_API_KEY'] = os.getenv('ANTHROPIC_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['HF_TOKEN'] = os.getenv('HF_TOKEN', 'your-key-if-not-using-env')" diff --git a/week6/day3.ipynb b/week6/day3.ipynb index 45bbac2..93e0928 100644 --- a/week6/day3.ipynb +++ b/week6/day3.ipynb @@ -118,7 +118,7 @@ "source": [ "# environment\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['ANTHROPIC_API_KEY'] = os.getenv('ANTHROPIC_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['HF_TOKEN'] = os.getenv('HF_TOKEN', 'your-key-if-not-using-env')" diff --git a/week6/day4-results.ipynb b/week6/day4-results.ipynb index a3a44eb..75db5e1 100644 --- a/week6/day4-results.ipynb +++ b/week6/day4-results.ipynb @@ -69,7 +69,7 @@ "source": [ "# environment\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['ANTHROPIC_API_KEY'] = os.getenv('ANTHROPIC_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['HF_TOKEN'] = os.getenv('HF_TOKEN', 'your-key-if-not-using-env')" diff --git a/week6/day4.ipynb b/week6/day4.ipynb index d1c5500..6644ce2 100644 --- a/week6/day4.ipynb +++ b/week6/day4.ipynb @@ -69,7 +69,7 @@ "source": [ "# environment\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['ANTHROPIC_API_KEY'] = os.getenv('ANTHROPIC_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['HF_TOKEN'] = os.getenv('HF_TOKEN', 'your-key-if-not-using-env')" diff --git a/week6/day5-results.ipynb b/week6/day5-results.ipynb index f936c80..77ed407 100644 --- a/week6/day5-results.ipynb +++ b/week6/day5-results.ipynb @@ -61,7 +61,7 @@ "source": [ "# environment\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['ANTHROPIC_API_KEY'] = os.getenv('ANTHROPIC_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['HF_TOKEN'] = os.getenv('HF_TOKEN', 'your-key-if-not-using-env')" @@ -904,7 +904,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.10" + "version": "3.11.11" } }, "nbformat": 4, diff --git a/week6/day5.ipynb b/week6/day5.ipynb index 1886310..4a733eb 100644 --- a/week6/day5.ipynb +++ b/week6/day5.ipynb @@ -61,7 +61,7 @@ "source": [ "# environment\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['ANTHROPIC_API_KEY'] = os.getenv('ANTHROPIC_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['HF_TOKEN'] = os.getenv('HF_TOKEN', 'your-key-if-not-using-env')" diff --git a/week8/day1.ipynb b/week8/day1.ipynb index 5da624a..18159fd 100644 --- a/week8/day1.ipynb +++ b/week8/day1.ipynb @@ -92,7 +92,7 @@ "metadata": {}, "outputs": [], "source": [ - "from hello import app, hello" + "from hello import app, hello, hello_europe" ] }, { @@ -119,6 +119,35 @@ "reply" ] }, + { + "cell_type": "markdown", + "id": "a1c075e9-49c7-4ebd-812f-83196d32de32", + "metadata": {}, + "source": [ + "## Added thanks to student Tue H.\n", + "\n", + "If you look in hello.py, I've added a simple function hello_europe\n", + "\n", + "That uses the decorator: \n", + "`@app.function(image=image, region=\"eu\")`\n", + "\n", + "See the result below! More region specific settings are [here](https://modal.com/docs/guide/region-selection)\n", + "\n", + "Note that it does consume marginally more credits to specify a region." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b027da1a-c79d-42cb-810d-32ddca31aa02", + "metadata": {}, + "outputs": [], + "source": [ + "with app.run():\n", + " reply=hello_europe.remote()\n", + "reply" + ] + }, { "cell_type": "markdown", "id": "22e8d804-c027-45fb-8fef-06e7bba6295a", @@ -247,8 +276,8 @@ "metadata": {}, "outputs": [], "source": [ - "# You can also run \"modal deploy pricer_service2\" at the command line in an activated environment\n", - "!modal deploy pricer_service2" + "# You can also run \"modal deploy -m pricer_service2\" at the command line in an activated environment\n", + "!modal deploy -m pricer_service2" ] }, { @@ -264,6 +293,16 @@ "print(reply)" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "c29b8c58-4cb7-44b0-ab7e-6469d3a318e8", + "metadata": {}, + "outputs": [], + "source": [ + "!pip install --upgrade modal" + ] + }, { "cell_type": "markdown", "id": "9c1b1451-6249-4462-bf2d-5937c059926c", diff --git a/week8/day2.0.ipynb b/week8/day2.0.ipynb index 088b460..c15ff2f 100644 --- a/week8/day2.0.ipynb +++ b/week8/day2.0.ipynb @@ -58,7 +58,7 @@ "source": [ "# environment\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['HF_TOKEN'] = os.getenv('HF_TOKEN', 'your-key-if-not-using-env')\n", "DB = \"products_vectorstore\"" diff --git a/week8/day2.3.ipynb b/week8/day2.3.ipynb index da6c3e3..b607e45 100644 --- a/week8/day2.3.ipynb +++ b/week8/day2.3.ipynb @@ -61,7 +61,7 @@ "source": [ "# environment\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['HF_TOKEN'] = os.getenv('HF_TOKEN', 'your-key-if-not-using-env')" ] diff --git a/week8/day2.4.ipynb b/week8/day2.4.ipynb index 7d357e2..3f141ab 100644 --- a/week8/day2.4.ipynb +++ b/week8/day2.4.ipynb @@ -79,7 +79,7 @@ "source": [ "# environment\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['HF_TOKEN'] = os.getenv('HF_TOKEN', 'your-key-if-not-using-env')" ] diff --git a/week8/day3.ipynb b/week8/day3.ipynb index 9effc96..9188717 100644 --- a/week8/day3.ipynb +++ b/week8/day3.ipynb @@ -35,7 +35,7 @@ "source": [ "# Initialize and constants\n", "\n", - "load_dotenv()\n", + "load_dotenv(override=True)\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n", "MODEL = 'gpt-4o-mini'\n", "openai = OpenAI()" diff --git a/week8/day4.ipynb b/week8/day4.ipynb index 6895681..bb4c993 100644 --- a/week8/day4.ipynb +++ b/week8/day4.ipynb @@ -42,7 +42,7 @@ "metadata": {}, "outputs": [], "source": [ - "load_dotenv()\n", + "load_dotenv(override=True)\n", "DB = \"products_vectorstore\"" ] }, diff --git a/week8/hello.py b/week8/hello.py index 6b97092..bc0599e 100644 --- a/week8/hello.py +++ b/week8/hello.py @@ -16,3 +16,14 @@ def hello() -> str: data = response.json() city, region, country = data['city'], data['region'], data['country'] return f"Hello from {city}, {region}, {country}!!" + +# New - added thanks to student Tue H.! + +@app.function(image=image, region="eu") +def hello_europe() -> str: + import requests + + response = requests.get('https://ipinfo.io/json') + data = response.json() + city, region, country = data['city'], data['region'], data['country'] + return f"Hello from {city}, {region}, {country}!!" diff --git a/week8/pricer_service2.py b/week8/pricer_service2.py index a09c882..16d276b 100644 --- a/week8/pricer_service2.py +++ b/week8/pricer_service2.py @@ -24,7 +24,6 @@ FINETUNED_DIR = MODEL_DIR + FINETUNED_MODEL QUESTION = "How much does this cost to the nearest dollar?" PREFIX = "Price is $" - @app.cls(image=image, secrets=secrets, gpu=GPU, timeout=1800) class Pricer: @modal.build()