Skip to content

Commit 9e5a2b5

Browse files
committed
add key instructions
1 parent 5ea65bb commit 9e5a2b5

4 files changed

Lines changed: 118 additions & 35 deletions

File tree

β€Žchapter_2/background.mdβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The accompanying `python notebooks` provide step-by-step implementations that re
1616

1717
:::{admonition} πŸš€ How to run the notebooks
1818

19-
Tutorials can be launched using the rocket (πŸš€) button at the top of the page.
19+
Tutorials with coding example can be launched using the rocket (πŸš€) button at the top of the page.
2020

2121
### Option 1 β€” Google Colab (**recommended**)
2222
Opens the notebook in Google Colab with the fastest and most reliable experience.
@@ -48,6 +48,8 @@ ANTHROPIC_API_KEY=your_key_here
4848
- You only need API keys for the providers used in a given notebook.
4949
- Never commit or publicly share your API keys.
5050
- If a cell fails due to missing credentials, verify that your keys were loaded correctly before rerunning the cell.
51+
- When you run a cell, a green check mark (βœ…) will appear at the top once the execution completes successfully. If the execution fails, you’ll see a red cross mark (❌) instead.
52+
- Some cells may not produce any visible output, so don’t worry if nothing appears below the cell. As long as you see the green check mark, you’re good to continue.
5153
:::
5254

5355
**Provide Feedback**

β€Žchapter_2/llms_for_biology.ipynbβ€Ž

Lines changed: 110 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"- You only need API keys for the providers used in a given notebook.\n",
4949
"- Never commit or publicly share your API keys.\n",
5050
"- If a cell fails due to missing credentials, verify that your keys were loaded correctly before rerunning the cell.\n",
51+
"- Some cells may not produce any visible output, so don’t worry if nothing appears below the cell. As long as you see a green check mark, you’re good to continue.\n",
5152
"</details>\n"
5253
]
5354
},
@@ -69,13 +70,9 @@
6970
"**1) Set your API key**\n",
7071
"If you're using this notebook as a `Google Colab notebook`, follow the instruction below.\n",
7172
"\n",
72-
"- Once you have received a unique API key from OpenAI (or another provider), setup the API keys by clicking key icon on the left tab. More info [here](https://colab.research.google.com/github/google-gemini/cookbook/blob/main/quickstarts/Authentication.ipynb)\n",
73+
"- Once you have received a unique API key from OpenAI (or another provider), setup the API keys by clicking key icon (πŸ”‘) on the left tab. Under the **Name** column make sure to enter `OPENAI_API_KEY`. These names are case-sensitive, and the notebook code looks for API keys using these exact names. More info [here](https://colab.research.google.com/github/google-gemini/cookbook/blob/main/quickstarts/Authentication.ipynb)\n",
7374
"\n",
74-
"- Alternatively, you can add a key to your environment. For example add a `.env` file to the root directory and add all the api keys. Or do `export OPENAI_API_KEY='your-key-here'`\n",
75-
"\n",
76-
"If you're using the **Live Coding** option, make sure to input your API when prompted.\n",
77-
"\n",
78-
"This notebook is written to work with all above cases. \n",
75+
"- Alternatively, you can add a key to your environment directly. For example add a `.env` file to the root directory and add all the api keys. Or do `export OPENAI_API_KEY='your-key-here'`\n",
7976
"\n",
8077
"**2) If you're using Google Colab install the requirements by running the cell below.**\n"
8178
]
@@ -235,6 +232,44 @@
235232
{
236233
"cell_type": "markdown",
237234
"id": "7",
235+
"metadata": {},
236+
"source": [
237+
"Now if you want to test a different model from OpenAI you can change the model name here and run the cell again:\n",
238+
"\n",
239+
"`LLM_MODEL = \"gpt-4.1-nano\"`\n",
240+
"\n",
241+
"You can also try another question by updating the `QUESTION` variable.\n",
242+
"\n",
243+
"**What if you want to try an Claude model?**\n",
244+
"\n",
245+
"The most important line to change are the following. You see we are using the OpenAI client here. It only has access to OpenAI models. To use a Claude model, you have to import the client from Anthropic. You can use the following steps.\n",
246+
"\n",
247+
"1. Install `anthropic` package\n",
248+
"2. Instead of OpenAI client, instantiate Anthropic client\n",
249+
"3. Change the model name\n",
250+
"\n",
251+
"Same concept goes to whichever the Client and Model you want to use. "
252+
]
253+
},
254+
{
255+
"cell_type": "code",
256+
"execution_count": null,
257+
"id": "8",
258+
"metadata": {},
259+
"outputs": [],
260+
"source": [
261+
"! uv pip install anthropic\n",
262+
"\n",
263+
"from anthropic import Anthropic\n",
264+
"\n",
265+
"anthropic_api_key = get_api_key(\"anthropic\")\n",
266+
"client = Anthropic(api_key=anthropic_api_key)\n",
267+
"LLM_MODEL = \"claude-3-5-sonnet-20240620\""
268+
]
269+
},
270+
{
271+
"cell_type": "markdown",
272+
"id": "9",
238273
"metadata": {
239274
"id": "huoitiLpLHsz"
240275
},
@@ -258,7 +293,7 @@
258293
},
259294
{
260295
"cell_type": "markdown",
261-
"id": "8",
296+
"id": "10",
262297
"metadata": {
263298
"id": "p5aQfAAYgTIJ"
264299
},
@@ -309,7 +344,7 @@
309344
{
310345
"cell_type": "code",
311346
"execution_count": null,
312-
"id": "9",
347+
"id": "11",
313348
"metadata": {
314349
"id": "xmx2Qos0gRW4"
315350
},
@@ -358,7 +393,7 @@
358393
},
359394
{
360395
"cell_type": "markdown",
361-
"id": "10",
396+
"id": "12",
362397
"metadata": {
363398
"id": "mxc05xdYkT6M"
364399
},
@@ -377,7 +412,7 @@
377412
{
378413
"cell_type": "code",
379414
"execution_count": null,
380-
"id": "11",
415+
"id": "13",
381416
"metadata": {
382417
"colab": {
383418
"base_uri": "https://localhost:8080/"
@@ -403,7 +438,7 @@
403438
},
404439
{
405440
"cell_type": "markdown",
406-
"id": "12",
441+
"id": "14",
407442
"metadata": {
408443
"id": "yt-6Y046kkU8"
409444
},
@@ -422,26 +457,29 @@
422457
"\n",
423458
"- Here, the retrieved abstracts (chunks) are combined into one text block (context), which is sent to the LLM. The LLM then reads all the information and generates an informative answer.\n",
424459
"\n",
425-
"- You can edit the prompt and see how it affects the model output."
460+
"**Adding a prompt**\n",
461+
"\n",
462+
"A prompt is the set of instructions or input you provide to the LLM to guide its behavior and responses. Small changes to the prompt can significantly affect the quality, style, and accuracy of the output. **The prompt is how you tell the LLM what task to perform.**\n",
463+
"\n",
464+
"In the example below, we’ve included a placeholders `{query}` and `{context_text}`. These placeholder lets you update the prompt with new user questions and contexts for each run while keeping the rest of the instructions unchanged. You can continue updating and populating this field as you experiment.\n",
465+
"\n",
466+
"In code block below, we do so with this line:\n",
467+
"\n",
468+
"```python\n",
469+
"PROMPT.format(context_text=context_text, query=query)\n",
470+
"```\n",
471+
"\n",
472+
"*Test if yourself:* Edit the prompt below to see how different instructions affect the model’s output."
426473
]
427474
},
428475
{
429476
"cell_type": "code",
430477
"execution_count": null,
431-
"id": "13",
432-
"metadata": {
433-
"id": "7v_giOlhkeW_"
434-
},
478+
"id": "15",
479+
"metadata": {},
435480
"outputs": [],
436481
"source": [
437-
"from openai import OpenAI\n",
438-
"from google.colab import userdata\n",
439-
"\n",
440-
"#set openai api key\n",
441-
"openai_api_key = get_api_key(\"openai\")\n",
442-
"\n",
443-
"client = OpenAI(api_key=openai_api_key)\n",
444-
"\n",
482+
"# ================================================\n",
445483
"PROMPT = \"\"\"Answer the question based on the context provided.\n",
446484
"\n",
447485
"Context:\n",
@@ -451,8 +489,33 @@
451489
"Question:\n",
452490
"{query}\n",
453491
"\n",
454-
"Answer: \"\"\"\n",
492+
"Answer: \"\"\""
493+
]
494+
},
495+
{
496+
"cell_type": "code",
497+
"execution_count": null,
498+
"id": "16",
499+
"metadata": {},
500+
"outputs": [],
501+
"source": [
502+
"# set openai api key\n",
503+
"from openai import OpenAI\n",
504+
"from google.colab import userdata\n",
455505
"\n",
506+
"openai_api_key = get_api_key(\"openai\")\n",
507+
"client = OpenAI(api_key=openai_api_key)"
508+
]
509+
},
510+
{
511+
"cell_type": "code",
512+
"execution_count": null,
513+
"id": "17",
514+
"metadata": {
515+
"id": "7v_giOlhkeW_"
516+
},
517+
"outputs": [],
518+
"source": [
456519
"# === Use OpenAI LLM to generate answer given retrieved abstracts and query ===\n",
457520
"def generate_answer_with_openai(contexts: list[str], query: str, llm_model: str=\"gpt-4\") -> str:\n",
458521
" context_text = \"\\n\\n\".join(contexts)\n",
@@ -473,7 +536,24 @@
473536
},
474537
{
475538
"cell_type": "markdown",
476-
"id": "14",
539+
"id": "18",
540+
"metadata": {},
541+
"source": [
542+
"> πŸ’‘Tip\n",
543+
"> In the message to the LLM, we added a \"system prompt\"\n",
544+
"> ```\n",
545+
"> {\"role\": \"system\", \n",
546+
"> \"content\": \"You are a helpful scientific assistant.\"}\n",
547+
">```\n",
548+
"\n",
549+
"> A system prompt is a special set of instructions given to an LLM before the user’s prompt. It defines the model’s overall behavior, rules, tone, and constraints throughout the conversation.\n",
550+
"\n",
551+
"> You can think of it as the model’s β€œoperating instructions.”\n"
552+
]
553+
},
554+
{
555+
"cell_type": "markdown",
556+
"id": "19",
477557
"metadata": {
478558
"id": "BjrdJvpglnw3"
479559
},
@@ -492,7 +572,7 @@
492572
{
493573
"cell_type": "code",
494574
"execution_count": null,
495-
"id": "15",
575+
"id": "20",
496576
"metadata": {
497577
"id": "XBoJfhz5lznd"
498578
},
@@ -533,7 +613,7 @@
533613
{
534614
"cell_type": "code",
535615
"execution_count": null,
536-
"id": "16",
616+
"id": "21",
537617
"metadata": {
538618
"colab": {
539619
"base_uri": "https://localhost:8080/"
@@ -552,7 +632,7 @@
552632
},
553633
{
554634
"cell_type": "markdown",
555-
"id": "17",
635+
"id": "22",
556636
"metadata": {},
557637
"source": [
558638
"Now that you have seen what RAG can do, what are your thoughts on the following?\n",
@@ -599,7 +679,7 @@
599679
},
600680
{
601681
"cell_type": "markdown",
602-
"id": "18",
682+
"id": "23",
603683
"metadata": {
604684
"id": "YzPq2CjyAl7H"
605685
},

β€Žchapter_2/uniprot_example.ipynbβ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818
"\n",
1919
"Before running the tutorial, add your API keys using **either**:\n",
2020
"\n",
21-
"- a `.env` file, or\n",
22-
"- **Colab Secrets** (`πŸ”‘ Secrets` tab in the left sidebar)\n",
21+
"- a `.env` file OR\n",
2322
"\n",
2423
"Example `.env`:\n",
2524
"```bash\n",
2625
"OPENAI_API_KEY=your_key_here\n",
2726
"ANTHROPIC_API_KEY=your_key_here\n",
2827
"```\n",
2928
"\n",
29+
"- **Colab Secrets** (`πŸ”‘ Secrets` tab in the left sidebar).Under the **Name** column make sure to enter `ANTHROPIC_API_KEY`. These names are case-sensitive, and the notebook code looks for API keys using these exact names.\n",
30+
"\n",
3031
"### Option 2 β€” MyBinder\n",
3132
"Launches a temporary cloud Jupyter environment directly in your browser.\n",
3233
"\n",

β€Žindex.mdβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ By the end of this series, you should:
2525

2626
# How to Use the Tutorials
2727

28-
The tutorials can be launched using the rocket (πŸš€) button at the top of the page.
28+
The tutorials **with coding examples** can be launched using the rocket (πŸš€) button at the top of the page.
2929

3030
<details>
31-
<summary> πŸ‘‡ Expand to see more details </summary>
31+
<summary> πŸ”½ Expand to see more details πŸ”½ </summary>
3232

3333
### Option 1 β€” Google Colab (**recommended**)
3434
Opens the notebook in Google Colab with the fastest and most reliable experience.

0 commit comments

Comments
Β (0)