Skip to content

Commit 9e4878f

Browse files
committed
update content - no live coding
1 parent 08b5748 commit 9e4878f

6 files changed

Lines changed: 413 additions & 242 deletions

File tree

_config.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,16 @@ repository:
1616
sphinx:
1717
extra_extensions:
1818
- sphinxcontrib.bibtex
19-
- sphinx_thebe
2019
config:
2120
numfig: false
22-
thebe_config:
23-
repository_url: "https://github.com/Future-House/tutorial-series"
24-
repository_branch: "main"
25-
binderhub_url: "https://mybinder.org"
26-
path_to_book: "."
27-
selector: ".cell" # ← added
28-
use_thebe_lite: false # ← added
29-
codemirror_config:
30-
theme: "default"
31-
3221
html_theme_options:
3322
use_issues_button: true
3423
use_repository_button: true
3524
repository_url: "https://github.com/Future-House/tutorial-series"
3625
repository_branch: "main"
3726
path_to_book: "."
3827
launch_buttons:
39-
thebe: true
28+
thebe: false
4029
colab_url: "https://colab.research.google.com"
4130
binderhub_url: "https://mybinder.org"
4231
notebook_interface: "jupyterlab"
@@ -55,3 +44,4 @@ exclude_patterns:
5544
- _build/**
5645
- .git/**
5746
- references.bib
47+
- "**/.env"

chapter_2/llms_for_biology.ipynb

Lines changed: 82 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,50 @@
1313
"\n",
1414
"As the volume of scientific literature continues to grow rapidly, manually extracting and organizing this information becomes increasingly difficult and time-consuming. Therefore, automating data extraction from the literature using AI can help researchers to rapidly identify relevant findings, convert unstructured text into structured datasets, and integrate knowledge across thousands of publications. \n",
1515
"\n",
16-
":::{note}\n",
17-
"To run the code snippets, you can click the **Live Code** button OR the 🚀 icon at the top of the page to launch the page as an interactive Google Colab notebook.\n",
16+
"::{admonition} 🚀 Getting Started\n",
17+
":class: tip\n",
1818
"\n",
19-
"Clicking **Live Code** will launch a Binder environment (~1-2 min). \n",
20-
"Your code will run directly in the page once it's ready.\n",
21-
":::\n",
19+
"This tutorial can be launched using the rocket button at the top of the page.\n",
2220
"\n",
23-
"## 2.2.1 Getting started with LLMs\n",
21+
"### Option 1 — Google Colab (**recommended**)\n",
22+
"Opens the notebook in Google Colab with the fastest and most reliable experience.\n",
23+
"\n",
24+
"Before running the tutorial, add your API keys using **either**:\n",
25+
"\n",
26+
"- a `.env` file, or\n",
27+
"- **Colab Secrets** (`🔑 Secrets` tab in the left sidebar)\n",
28+
"\n",
29+
"Example `.env`:\n",
30+
"```bash\n",
31+
"OPENAI_API_KEY=your_key_here\n",
32+
"ANTHROPIC_API_KEY=your_key_here\n",
33+
"```\n",
34+
"\n",
35+
"### Option 2 — MyBinder\n",
36+
"Launches a temporary cloud Jupyter environment directly in your browser.\n",
37+
"\n",
38+
"⚠️ Binder environments can take a few minutes to build and start.\n",
39+
"\n",
40+
"After the notebook loads, create a `.env` file in the notebook directory containing your API keys:\n",
41+
"\n",
42+
"```bash\n",
43+
"OPENAI_API_KEY=your_key_here\n",
44+
"ANTHROPIC_API_KEY=your_key_here\n",
45+
"```\n",
46+
"\n",
47+
"### Notes\n",
48+
"- You only need API keys for the providers used in a given notebook.\n",
49+
"- Never commit or publicly share your API keys.\n",
50+
"- If a cell fails due to missing credentials, verify that your keys were loaded correctly before rerunning the cell.\n",
51+
":::\n"
52+
]
53+
},
54+
{
55+
"cell_type": "markdown",
56+
"id": "79a2787b",
57+
"metadata": {},
58+
"source": [
59+
"## 2.2.1 Accessing LLMs through APIs\n",
2460
"\n",
2561
"You might have used LLMs through chat interfaces such as ChatGPT or Claude before. But to access them through a python code as what we have here, we need to use an API.\n",
2662
"\n",
@@ -98,58 +134,58 @@
98134
"source": [
99135
"import os\n",
100136
"\n",
101-
"def get_api_key():\n",
102-
" \"\"\"Load API key from Colab secrets, environment variable, or user input.\"\"\"\n",
137+
"LLM_API_KEYS = {\n",
138+
" \"openai\": \"OPENAI_API_KEY\",\n",
139+
" \"anthropic\": \"ANTHROPIC_API_KEY\",\n",
140+
"}\n",
141+
"\n",
142+
"def get_api_key(llm: str = \"openai\") -> str:\n",
143+
" \"\"\"\n",
144+
" Load API key for the specified LLM from Colab secrets,\n",
145+
" environment variable, or user input.\n",
146+
" \n",
147+
" Args:\n",
148+
" llm: LLM provider name. eg: 'openai', 'anthropic'\n",
103149
" \n",
150+
" Returns:\n",
151+
" API key string\n",
152+
" \n",
153+
" Example:\n",
154+
" api_key = get_api_key(\"anthropic\")\n",
155+
" \"\"\"\n",
156+
"\n",
157+
" llm = llm.lower()\n",
158+
" if llm not in LLM_API_KEYS:\n",
159+
" raise ValueError(\n",
160+
" f\"Unknown LLM '{llm}'. Choose from: {list(LLM_API_KEYS.keys())}\"\n",
161+
" )\n",
162+
"\n",
163+
" env_var = LLM_API_KEYS[llm]\n",
164+
"\n",
104165
" # 1. Try Colab secrets\n",
105166
" try:\n",
106167
" from google.colab import userdata\n",
107-
" return userdata.get('OPENAI_API_KEY')\n",
168+
" key = userdata.get(env_var)\n",
169+
" if key:\n",
170+
" return key\n",
108171
" except ImportError:\n",
109172
" pass\n",
110173
"\n",
111174
" # 2. Try environment variable / .env file\n",
112175
" try:\n",
113176
" from dotenv import load_dotenv\n",
114177
" load_dotenv()\n",
115-
" api_key = os.environ.get('OPENAI_API_KEY')\n",
116-
" if api_key:\n",
117-
" return api_key\n",
178+
" key = os.environ.get(env_var)\n",
179+
" if key:\n",
180+
" return key\n",
118181
" except ImportError:\n",
119182
" pass\n",
120183
"\n",
121-
" # 3. For live code in Binder/Thebe — ask user to input it\n",
122-
" try:\n",
123-
" import ipywidgets as widgets\n",
124-
" from IPython.display import display\n",
125-
"\n",
126-
" key_input = widgets.Password(\n",
127-
" placeholder='Paste your OpenAI API key here',\n",
128-
" description='API Key:',\n",
129-
" layout=widgets.Layout(width='400px')\n",
130-
" )\n",
131-
" submit = widgets.Button(description='Submit', button_style='primary')\n",
132-
" output = widgets.Output()\n",
133-
"\n",
134-
" result = {'key': None}\n",
135-
"\n",
136-
" def on_submit(b):\n",
137-
" result['key'] = key_input.value\n",
138-
" os.environ['OPENAI_API_KEY'] = key_input.value\n",
139-
" with output:\n",
140-
" print(\"✅ API key set successfully!\")\n",
141-
"\n",
142-
" submit.on_click(on_submit)\n",
143-
" display(widgets.VBox([key_input, submit, output]))\n",
144-
"\n",
145-
" # wait for user to submit\n",
146-
" return result\n",
147-
"\n",
148-
" except ImportError:\n",
149-
" raise ValueError(\n",
150-
" \"API key not found. Please set OPENAI_API_KEY:\\n\"\n",
151-
" \" export OPENAI_API_KEY='your-key-here'\"\n",
152-
" )"
184+
" raise ValueError(\n",
185+
" f\"API key not found. Please set {env_var}:\\n\"\n",
186+
" f\" export {env_var}='your-key-here'\\n\"\n",
187+
" f\" or add it to a .env file\"\n",
188+
" )"
153189
]
154190
},
155191
{
@@ -177,15 +213,14 @@
177213
},
178214
"outputs": [],
179215
"source": [
180-
"\n",
181216
"from openai import OpenAI\n",
182217
"\n",
183218
"# Access the OpenAI API key\n",
184-
"openai_api_key = get_api_key()\n",
219+
"openai_api_key = get_api_key(\"openai\")\n",
185220
"# Tell the OpenAI client to use your API key\n",
186221
"client = OpenAI(api_key=openai_api_key)\n",
187222
"# LLM model to generate answer. Replace model name if deprecated\n",
188-
"LLM_MODEL = \"gpt-5.5\"\n",
223+
"LLM_MODEL = \"gpt-4.1-nano\"\n",
189224
"# Add your question here\n",
190225
"QUESTION = \"What is the difference between Machine Learning and Deep Learning?\" \n",
191226
"\n",

chapter_2/uniprot_example.ipynb

Lines changed: 89 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,41 @@
88
"# 2.3 Integrating External Databases\n",
99
"The goal of this section is to show you how LLMs can easily be integrated into research workflows to accelerate scientific discovery. On top of everything, AI can take care of the most mundane trivial tasks.\n",
1010
"\n",
11-
":::{note}\n",
12-
"To run the code snippets, you can click the **Live Code** button OR the 🚀 icon at the top of the page to launch the page as an interactive Google Colab notebook.\n",
11+
":::{admonition} 🚀 Getting Started\n",
12+
":class: tip\n",
1313
"\n",
14-
"Clicking **Live Code** will launch a Binder environment (~1-2 min). \n",
15-
"Your code will run directly in the page once it's ready.\n",
14+
"This tutorial can be launched using the rocket button at the top of the page.\n",
15+
"\n",
16+
"### Option 1 — Google Colab (**recommended**)\n",
17+
"Opens the notebook in Google Colab with the fastest and most reliable experience.\n",
18+
"\n",
19+
"Before running the tutorial, add your API keys using **either**:\n",
20+
"\n",
21+
"- a `.env` file, or\n",
22+
"- **Colab Secrets** (`🔑 Secrets` tab in the left sidebar)\n",
23+
"\n",
24+
"Example `.env`:\n",
25+
"```bash\n",
26+
"OPENAI_API_KEY=your_key_here\n",
27+
"ANTHROPIC_API_KEY=your_key_here\n",
28+
"```\n",
29+
"\n",
30+
"### Option 2 — MyBinder\n",
31+
"Launches a temporary cloud Jupyter environment directly in your browser.\n",
32+
"\n",
33+
"⚠️ Binder environments can take a few minutes to build and start.\n",
34+
"\n",
35+
"After the notebook loads, create a `.env` file in the notebook directory containing your API keys:\n",
36+
"\n",
37+
"```bash\n",
38+
"OPENAI_API_KEY=your_key_here\n",
39+
"ANTHROPIC_API_KEY=your_key_here\n",
40+
"```\n",
41+
"\n",
42+
"### Notes\n",
43+
"- You only need API keys for the providers used in a given notebook.\n",
44+
"- Never commit or publicly share your API keys.\n",
45+
"- If a cell fails due to missing credentials, verify that your keys were loaded correctly before rerunning the cell.\n",
1646
":::\n",
1747
"\n",
1848
"## 2.3.1 Example 1: Uniprot integration\n",
@@ -25,11 +55,7 @@
2555
"\n",
2656
"UniProt offers a free, no-authentication REST API. You can fetch data for p53 (human) using its UniProt accession ID `P04637`.\n",
2757
"\n",
28-
"\n",
29-
"Let's begin!\n",
30-
"\n",
31-
"If you're using Google Colab to run the notebook, make sure to install the requirements using the cell below. If you're using the \"Live Code\" option, you don't have to do anything.\n",
32-
"\n"
58+
"**If you're using Google Colab install the requirements by running the cell below.**"
3359
]
3460
},
3561
{
@@ -98,25 +124,59 @@
98124
"outputs": [],
99125
"source": [
100126
"import os\n",
101-
"from dotenv import load_dotenv\n",
102127
"\n",
103-
"def get_api_key():\n",
104-
" \"\"\"Load Anthropic API key from Colab secrets or environment variable.\"\"\"\n",
128+
"LLM_API_KEYS = {\n",
129+
" \"openai\": \"OPENAI_API_KEY\",\n",
130+
" \"anthropic\": \"ANTHROPIC_API_KEY\",\n",
131+
"}\n",
132+
"\n",
133+
"def get_api_key(llm: str = \"anthropic\") -> str:\n",
134+
" \"\"\"\n",
135+
" Load API key for the specified LLM from Colab secrets,\n",
136+
" environment variable, or user input.\n",
137+
" \n",
138+
" Args:\n",
139+
" llm: LLM provider name. eg: 'openai', 'anthropic'\n",
140+
" \n",
141+
" Returns:\n",
142+
" API key string\n",
143+
" \n",
144+
" Example:\n",
145+
" api_key = get_api_key(\"anthropic\")\n",
146+
" \"\"\"\n",
147+
"\n",
148+
" llm = llm.lower()\n",
149+
" if llm not in LLM_API_KEYS:\n",
150+
" raise ValueError(\n",
151+
" f\"Unknown LLM '{llm}'. Choose from: {list(LLM_API_KEYS.keys())}\"\n",
152+
" )\n",
153+
"\n",
154+
" env_var = LLM_API_KEYS[llm]\n",
155+
"\n",
156+
" # 1. Try Colab secrets\n",
105157
" try:\n",
106158
" from google.colab import userdata\n",
107-
" return userdata.get(\"ANTHROPIC_API_KEY\")\n",
159+
" key = userdata.get(env_var)\n",
160+
" if key:\n",
161+
" return key\n",
108162
" except ImportError:\n",
109-
" # Not in Colab — fall back to environment variable\n",
110-
" load_dotenv() \n",
111-
" api_key = os.environ.get(\"ANTHROPIC_API_KEY\")\n",
112-
" if not api_key:\n",
113-
" raise ValueError(\n",
114-
" \"API key not found. Please set the ANTHROPIC_API_KEY or OPENAI_API_KEY environment variable.\\n\"\n",
115-
" \"You can do this by running the following in your terminal. Example:\\n\"\n",
116-
" \" export ANTHROPIC_API_KEY='your-key-here'\\n\"\n",
117-
" \"Or add it to a .env file in your project root.\"\n",
118-
" )\n",
119-
" return api_key\n"
163+
" pass\n",
164+
"\n",
165+
" # 2. Try environment variable / .env file\n",
166+
" try:\n",
167+
" from dotenv import load_dotenv\n",
168+
" load_dotenv()\n",
169+
" key = os.environ.get(env_var)\n",
170+
" if key:\n",
171+
" return key\n",
172+
" except ImportError:\n",
173+
" pass\n",
174+
"\n",
175+
" raise ValueError(\n",
176+
" f\"API key not found. Please set {env_var}:\\n\"\n",
177+
" f\" export {env_var}='your-key-here'\\n\"\n",
178+
" f\" or add it to a .env file\"\n",
179+
" )"
120180
]
121181
},
122182
{
@@ -128,7 +188,8 @@
128188
"source": [
129189
"import anthropic\n",
130190
"\n",
131-
"client = anthropic.Anthropic(api_key=get_api_key())\n",
191+
"api_key = get_api_key(llm=\"anthropic\")\n",
192+
"client = anthropic.Anthropic(api_key=api_key)\n",
132193
"\n",
133194
"# Build a prompt using the retrieved UniProt data\n",
134195
"prompt = f\"\"\"\n",
@@ -160,10 +221,10 @@
160221
"source": [
161222
"If you want to use an OpenAI model instead, you only have to swap the clients and load the correct API Key. See example below or check the previous section on \"Extracting information from literature\"\n",
162223
"\n",
163-
"```\n",
224+
"```python\n",
164225
"from openai import OpenAI\n",
165226
"\n",
166-
"client = OpenAI(api_key=get_api_key(provider=\"openai\"))\n",
227+
"client = OpenAI(api_key=get_api_key(llm=\"openai\"))\n",
167228
"\n",
168229
"response = client.responses.create(\n",
169230
" model=\"gpt-4.1-mini\",\n",
@@ -392,7 +453,7 @@
392453
"source": [
393454
"import anthropic\n",
394455
"\n",
395-
"client = anthropic.Anthropic(api_key=get_api_key())\n",
456+
"client = anthropic.Anthropic(api_key=get_api_key(llm=\"anthropic\"))\n",
396457
"\n",
397458
"structure_prompt = f\"\"\"\n",
398459
"I retrieved the following information about a protein crystal structure from the RCSB PDB:\n",

0 commit comments

Comments
 (0)