Skip to content

Commit 8e725de

Browse files
committed
fix: api helper func chapter 2
1 parent 4400d9a commit 8e725de

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ share/python-wheels/
4141
.installed.cfg
4242
*.egg
4343
MANIFEST
44+
chapter_2/.env
45+
chapter_3/.env
4446

4547
# PyInstaller
4648
# Usually these files are written by a python script from a template

chapter_2/llms_for_biology.ipynb

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@
100100
" return userdata.get('OPENAI_API_KEY')\n",
101101
" except ImportError:\n",
102102
" # Not in Colab — fall back to environment variable\n",
103+
" from dotenv import load_dotenv\n",
104+
" load_dotenv()\n",
103105
" api_key = os.environ.get('OPENAI_API_KEY')\n",
104106
" if not api_key:\n",
105107
" raise ValueError(\n",
@@ -144,14 +146,13 @@
144146
"source": [
145147
"\n",
146148
"from openai import OpenAI\n",
147-
"from google.colab import userdata\n",
148149
"\n",
149150
"# Access the OpenAI API key\n",
150-
"openai_api_key = userdata.get('OPENAI_API_KEY')\n",
151+
"openai_api_key = get_api_key()\n",
151152
"# Tell the OpenAI client to use your API key\n",
152153
"client = OpenAI(api_key=openai_api_key)\n",
153154
"# LLM model to generate answer. Replace model name if deprecated\n",
154-
"LLM_MODEL = \"gpt-4.1-nano-2025-04-14\"\n",
155+
"LLM_MODEL = \"gpt-5.5\"\n",
155156
"# Add your question here\n",
156157
"QUESTION = \"What is the difference between Machine Learning and Deep Learning?\" \n",
157158
"\n",
@@ -573,11 +574,21 @@
573574
"provenance": []
574575
},
575576
"kernelspec": {
576-
"display_name": "Python 3",
577-
"name": "python3"
577+
"display_name": "tutorials",
578+
"language": "python",
579+
"name": "fh-fellows-tutorials"
578580
},
579581
"language_info": {
580-
"name": "python"
582+
"codemirror_mode": {
583+
"name": "ipython",
584+
"version": 3
585+
},
586+
"file_extension": ".py",
587+
"mimetype": "text/x-python",
588+
"name": "python",
589+
"nbconvert_exporter": "python",
590+
"pygments_lexer": "ipython3",
591+
"version": "3.12.5"
581592
}
582593
},
583594
"nbformat": 4,

0 commit comments

Comments
 (0)