Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
random-forests committed Jun 18, 2024
1 parent 51b243d commit 01ac3d0
Showing 1 changed file with 56 additions and 76 deletions.
132 changes: 56 additions & 76 deletions quickstarts/Caching.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"cellView": "form",
"id": "0lpR41ozqBFp"
Expand Down Expand Up @@ -57,7 +57,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {
"id": "5yRLvyPhrXSf"
},
Expand All @@ -68,7 +68,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {
"id": "4xdJSvLerazn"
},
Expand All @@ -91,7 +91,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {
"id": "EgO56yWoriI0"
},
Expand All @@ -117,7 +117,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {
"id": "Sa-r2s_ltBXy"
},
Expand Down Expand Up @@ -146,7 +146,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {
"id": "b3bU9AvcvZ_x"
},
Expand All @@ -168,7 +168,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {
"id": "55V-QkaWv4tb"
},
Expand All @@ -177,19 +177,19 @@
"data": {
"text/plain": [
"CachedContent(\n",
" name='cachedContents/7k9fow3y6xx5',\n",
" name='cachedContents/40k37vcojf2o',\n",
" model='models/gemini-1.5-flash-001',\n",
" display_name='',\n",
" usage_metadata={\n",
" 'total_token_count': 323394,\n",
" 'total_token_count': 323383,\n",
" },\n",
" create_time=2024-06-18 06:03:36.541562+00:00,\n",
" update_time=2024-06-18 06:03:36.541562+00:00,\n",
" expire_time=2024-06-18 07:03:35.195945+00:00\n",
" create_time=2024-06-18 16:15:48.903792+00:00,\n",
" update_time=2024-06-18 16:15:48.903792+00:00,\n",
" expire_time=2024-06-18 17:15:48.514878+00:00\n",
")"
]
},
"execution_count": 45,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -200,7 +200,7 @@
"\n",
"apollo_cache = caching.CachedContent.create(\n",
" model=model_name,\n",
" system_instruction=\"You are a NASA transcript analyst. You understand spaceflight and can provide important context to transcripts.\",\n",
" system_instruction=\"You are an expert at analyzing transcripts.\",\n",
" contents=[document],\n",
")\n",
"\n",
Expand All @@ -220,7 +220,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {
"id": "cUJT2ESUyTGb"
},
Expand All @@ -229,19 +229,19 @@
"data": {
"text/plain": [
"CachedContent(\n",
" name='cachedContents/7k9fow3y6xx5',\n",
" name='cachedContents/40k37vcojf2o',\n",
" model='models/gemini-1.5-flash-001',\n",
" display_name='',\n",
" usage_metadata={\n",
" 'total_token_count': 323394,\n",
" 'total_token_count': 323383,\n",
" },\n",
" create_time=2024-06-18 06:03:36.541562+00:00,\n",
" update_time=2024-06-18 06:03:38.612328+00:00,\n",
" expire_time=2024-06-18 08:03:38.593924+00:00\n",
" create_time=2024-06-18 16:15:48.903792+00:00,\n",
" update_time=2024-06-18 16:15:49.983070+00:00,\n",
" expire_time=2024-06-18 18:15:49.822943+00:00\n",
")"
]
},
"execution_count": 46,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -266,7 +266,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {
"id": "EG8VNpuIzGwT"
},
Expand All @@ -275,38 +275,22 @@
"name": "stdout",
"output_type": "stream",
"text": [
"The transcript is full of technical jargon, but there's a moment of levity when Buzz Aldrin, the Lunar Module Pilot, responds to a request for a crew status report. \n",
"A lighthearted moment occurs on page 31 of the transcript. The astronauts are discussing their view of Earth and Mission Control comments on how good the view must be from up there. \n",
"\n",
"**02 00 20 31 CMP**\n",
"If we're late in answering you, it's because we're munching sandwiches.\n",
"**CMP:** I didn't know what I was looking at, but I sure did like it.\n",
"**CC:** Okay. I guess the view must be pretty good from up there. We show you just roughly somewhere around 19,000 miles out now.\n",
"**CMP:** I didn't have much outside my window.\n",
"**CC:** We'll get you into the PTC one of these days, and you take turns looking. \n",
"\n",
"**02 00 20 36 CC**\n",
"Roger. I wish I could do the same here.\n",
"\n",
"**02 00 20 40 CMP**\n",
"No. Don't leave the console!\n",
"\n",
"**02 00 20 42 CC**\n",
"Don't worry. I won't.\n",
"\n",
"**02 00 20 47 CMP**\n",
"FLIGHT doesn't like it.\n",
"\n",
"**02 00 20 54 CMP**\n",
"How is FLIGHT today?\n",
"\n",
"**02 00 20 58 CC**\n",
"Oh, he's doing quite well. \n",
"\n",
"This humorous exchange highlights the fact that even during a monumental mission like Apollo 11, crew members and ground control find time to lighten the mood and share a laugh. It's a reminder that even when facing incredible pressure, the human spirit still finds ways to connect and inject some humor. \n",
"This exchange is lighthearted because the astronauts are joking about the limited view from their individual windows and the Mission Control is playfully suggesting they share the view by switching positions. This lighthearted moment shows the astronauts' sense of humor and camaraderie even during a stressful mission. \n",
"\n"
]
}
],
"source": [
"apollo_model = genai.GenerativeModel.from_cached_content(cached_content=apollo_cache)\n",
"\n",
"response = apollo_model.generate_content(\"Find a lighthearted moment from this mission\")\n",
"response = apollo_model.generate_content(\"Find a lighthearted moment from this transcript\")\n",
"print(response.text)"
]
},
Expand All @@ -321,21 +305,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {
"id": "MLFd8DFZ29lC"
},
"outputs": [
{
"data": {
"text/plain": [
"prompt_token_count: 323403\n",
"candidates_token_count: 283\n",
"total_token_count: 292\n",
"cached_content_token_count: 323394"
"prompt_token_count: 323392\n",
"candidates_token_count: 189\n",
"total_token_count: 198\n",
"cached_content_token_count: 323383"
]
},
"execution_count": 29,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -355,7 +339,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {
"id": "pZngmGj13k9O"
},
Expand All @@ -364,24 +348,22 @@
"name": "stdout",
"output_type": "stream",
"text": [
"The most important part of this transcript is when Neil Armstrong takes his \"one small step\" on the moon. Here is that quote: \n",
"The most important part of the transcript is when Neil Armstrong steps onto the lunar surface. Here's his famous quote: \n",
"\n",
"\"THAT'S ONE SMALL STEP FOR (A) MAN, ONE GIANT LEAP FOR MANKIND.\"\n",
"\n",
"This iconic quote is spoken at 04:13:24 in the transcript and marks the moment when humankind first set foot on the moon.\n",
"\"**That's one small step for (a) man, one giant leap for mankind.**\" \n",
"\n"
]
}
],
"source": [
"chat = apollo_model.start_chat()\n",
"response = chat.send_message(\"Give me a quote from the most important part.\")\n",
"response = chat.send_message(\"Give me a quote from the most important part of the transcript.\")\n",
"print(response.text)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {
"id": "GhGTutW65u7h"
},
Expand All @@ -390,16 +372,14 @@
"name": "stdout",
"output_type": "stream",
"text": [
"After Neil Armstrong's iconic statement, \"That's one small step for (a) man, one giant leap for mankind,\" he goes on to describe the lunar surface in more detail:\n",
"\n",
"* **The surface is fine and powdery.** Armstrong describes the moon's surface as \"fine and powdery\" and says he can pick it up loosely with his toe. He also notes that it adheres in fine layers to his boots, similar to powdered charcoal.\n",
"* **Footprints are clearly visible.** He mentions seeing the footprints of his boots and the tread marks in the sand-like particles. \n",
"* **The surface is easy to move around on.** Armstrong says there's no difficulty in moving around, and it's even easier than the simulations on Earth. \n",
"* **The descent engine did not leave a crater.** He mentions that the engine has about 1 foot of clearance from the ground, and there's no significant crater from the landing.\n",
"After Neil Armstrong's famous quote, the transcript details his initial observations of the lunar surface:\n",
"\n",
"He also briefly mentions seeing rays emanating from the descent engine, suggesting that the engine exhaust did affect the surface in a minor way.\n",
"* **The surface is fine and powdery.** He describes being able to pick up the dust with his toe, and how it sticks to his boots.\n",
"* **There seems to be no difficulty in moving around.** He found it easier than the simulations on Earth, and that walking is comfortable.\n",
"* **The descent engine did not leave a crater of any size.** He notes that the LM had about a foot of clearance from the surface.\n",
"* **There is some evidence of rays emanating from the descent engine.** This is an indication of the engine's impact on the lunar surface. \n",
"\n",
"This initial description of the moon's surface is crucial, as it gives the first-hand account of what it's like to walk on another celestial body. \n",
"These initial observations provide the first detailed description of the lunar surface, marking a historic moment in human exploration. \n",
"\n"
]
}
Expand All @@ -411,21 +391,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {
"id": "SB5Ywx2D6cOn"
},
"outputs": [
{
"data": {
"text/plain": [
"prompt_token_count: 323497\n",
"candidates_token_count: 257\n",
"total_token_count: 360\n",
"cached_content_token_count: 323394"
"prompt_token_count: 323455\n",
"candidates_token_count: 164\n",
"total_token_count: 236\n",
"cached_content_token_count: 323383"
]
},
"execution_count": 38,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -447,7 +427,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {
"id": "1zzHVCAK7ahI"
},
Expand All @@ -458,7 +438,7 @@
"total_tokens: 9"
]
},
"execution_count": 41,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -480,7 +460,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {
"id": "HdP83dj08Nb1"
},
Expand All @@ -489,7 +469,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"cachedContents/7k9fow3y6xx5\n"
"cachedContents/40k37vcojf2o\n"
]
}
],
Expand Down

0 comments on commit 01ac3d0

Please sign in to comment.