diff --git a/site/en/tutorials/python_quickstart.ipynb b/site/en/tutorials/python_quickstart.ipynb index a3be1f52f..b8c16f170 100644 --- a/site/en/tutorials/python_quickstart.ipynb +++ b/site/en/tutorials/python_quickstart.ipynb @@ -141,7 +141,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": { "id": "TS9l5igubpHO" }, @@ -209,7 +209,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": { "id": "ab9ASynfcIZn" }, @@ -303,8 +303,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "CPU times: user 110 ms, sys: 12.3 ms, total: 123 ms\n", - "Wall time: 8.25 s\n" + "CPU times: user 269 ms, sys: 31 ms, total: 300 ms\n", + "Wall time: 15.4 s\n" ] } ], @@ -332,31 +332,21 @@ { "data": { "text/markdown": [ - "> The query of life's purpose has perplexed people across centuries, cultures, and continents. While there is no universally recognized response, many ideas have been put forth, and the response is frequently dependent on individual ideas, beliefs, and life experiences.\n", - "> \n", - "> 1. **Happiness and Well-being:** Many individuals believe that the goal of life is to attain personal happiness and well-being. This might entail locating pursuits that provide joy, establishing significant connections, caring for one's physical and mental health, and pursuing personal goals and interests.\n", - "> \n", - "> 2. **Meaningful Contribution:** Some believe that the purpose of life is to make a meaningful contribution to the world. This might entail pursuing a profession that benefits others, engaging in volunteer or charitable activities, generating art or literature, or inventing.\n", - "> \n", - "> 3. **Self-realization and Personal Growth:** The pursuit of self-realization and personal development is another common goal in life. This might entail learning new skills, pushing one's boundaries, confronting personal obstacles, and evolving as a person.\n", - "> \n", - "> 4. **Ethical and Moral Behavior:** Some believe that the goal of life is to act ethically and morally. This might entail adhering to one's moral principles, doing the right thing even when it is difficult, and attempting to make the world a better place.\n", + "> The meaning of life is a question that has been pondered by philosophers, theologians, and scientists for centuries. There is no one definitive answer, as the meaning of life is subjective and unique to each individual. However, some common themes that emerge from discussions about the meaning of life include:\n", "> \n", - "> 5. **Spiritual Fulfillment:** For some, the purpose of life is connected to spiritual or religious beliefs. This might entail seeking a connection with a higher power, practicing religious rituals, or following spiritual teachings.\n", + "> * **Purpose:** Many people believe that the meaning of life is to find a purpose or calling that gives them a sense of fulfillment and direction. This purpose may be related to work, relationships, hobbies, or other activities that bring meaning to their lives.\n", + "> * **Relationships:** For many people, the meaning of life is found in their relationships with others. This includes relationships with family, friends, loved ones, and even strangers. Building and maintaining strong relationships can provide a sense of belonging, love, and support.\n", + "> * **Values:** The meaning of life can also be found in our values. What do we stand for? What do we believe in? When we live in accordance with our values, we feel a sense of authenticity and purpose.\n", + "> * **Growth and learning:** The meaning of life can also be found in our personal growth and learning. As we grow and learn, we expand our understanding of the world and ourselves. This process can lead to a greater sense of fulfillment and meaning.\n", + "> * **Service:** Many people find meaning in life by serving others. This can be through volunteering, donating to charity, or simply helping those in need. When we help others, we feel a sense of purpose and connection to the world.\n", "> \n", - "> 6. **Experiencing Life to the Fullest:** Some individuals believe that the goal of life is to experience all that it has to offer. This might entail traveling, trying new things, taking risks, and embracing new encounters.\n", - "> \n", - "> 7. **Legacy and Impact:** Others believe that the purpose of life is to leave a lasting legacy and impact on the world. This might entail accomplishing something noteworthy, being remembered for one's contributions, or inspiring and motivating others.\n", - "> \n", - "> 8. **Finding Balance and Harmony:** For some, the purpose of life is to find balance and harmony in all aspects of their lives. This might entail juggling personal, professional, and social obligations, seeking inner peace and contentment, and living a life that is in accordance with one's values and beliefs.\n", - "> \n", - "> Ultimately, the meaning of life is a personal journey, and different individuals may discover their own unique purpose through their experiences, reflections, and interactions with the world around them." + "> Ultimately, the meaning of life is a personal journey. What is meaningful to one person may not be meaningful to another. The key is to find what gives your life purpose, fulfillment, and joy." ], "text/plain": [ "" ] }, - "execution_count": 7, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -402,7 +392,7 @@ "}" ] }, - "execution_count": 8, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -434,7 +424,7 @@ "text/plain": [ "[content {\n", " parts {\n", - " text: \"The query of life\\'s purpose has perplexed people across centuries, cultures, and continents. While there is no universally recognized response, many ideas have been put forth, and the response is frequently dependent on individual ideas, beliefs, and life experiences.\\n\\n1. **Happiness and Well-being:** Many individuals believe that the goal of life is to attain personal happiness and well-being. This might entail locating pursuits that provide joy, establishing significant connections, caring for one\\'s physical and mental health, and pursuing personal goals and interests.\\n\\n2. **Meaningful Contribution:** Some believe that the purpose of life is to make a meaningful contribution to the world. This might entail pursuing a profession that benefits others, engaging in volunteer or charitable activities, generating art or literature, or inventing.\\n\\n3. **Self-realization and Personal Growth:** The pursuit of self-realization and personal development is another common goal in life. This might entail learning new skills, pushing one\\'s boundaries, confronting personal obstacles, and evolving as a person.\\n\\n4. **Ethical and Moral Behavior:** Some believe that the goal of life is to act ethically and morally. This might entail adhering to one\\'s moral principles, doing the right thing even when it is difficult, and attempting to make the world a better place.\\n\\n5. **Spiritual Fulfillment:** For some, the purpose of life is connected to spiritual or religious beliefs. This might entail seeking a connection with a higher power, practicing religious rituals, or following spiritual teachings.\\n\\n6. **Experiencing Life to the Fullest:** Some individuals believe that the goal of life is to experience all that it has to offer. This might entail traveling, trying new things, taking risks, and embracing new encounters.\\n\\n7. **Legacy and Impact:** Others believe that the purpose of life is to leave a lasting legacy and impact on the world. This might entail accomplishing something noteworthy, being remembered for one\\'s contributions, or inspiring and motivating others.\\n\\n8. **Finding Balance and Harmony:** For some, the purpose of life is to find balance and harmony in all aspects of their lives. This might entail juggling personal, professional, and social obligations, seeking inner peace and contentment, and living a life that is in accordance with one\\'s values and beliefs.\\n\\nUltimately, the meaning of life is a personal journey, and different individuals may discover their own unique purpose through their experiences, reflections, and interactions with the world around them.\"\n", + " text: \"The meaning of life is a question that has been pondered by philosophers, theologians, and scientists for centuries. There is no one definitive answer, as the meaning of life is subjective and unique to each individual. However, some common themes that emerge from discussions about the meaning of life include:\\n\\n* **Purpose:** Many people believe that the meaning of life is to find a purpose or calling that gives them a sense of fulfillment and direction. This purpose may be related to work, relationships, hobbies, or other activities that bring meaning to their lives.\\n* **Relationships:** For many people, the meaning of life is found in their relationships with others. This includes relationships with family, friends, loved ones, and even strangers. Building and maintaining strong relationships can provide a sense of belonging, love, and support.\\n* **Values:** The meaning of life can also be found in our values. What do we stand for? What do we believe in? When we live in accordance with our values, we feel a sense of authenticity and purpose.\\n* **Growth and learning:** The meaning of life can also be found in our personal growth and learning. As we grow and learn, we expand our understanding of the world and ourselves. This process can lead to a greater sense of fulfillment and meaning.\\n* **Service:** Many people find meaning in life by serving others. This can be through volunteering, donating to charity, or simply helping those in need. When we help others, we feel a sense of purpose and connection to the world.\\n\\nUltimately, the meaning of life is a personal journey. What is meaningful to one person may not be meaningful to another. The key is to find what gives your life purpose, fulfillment, and joy.\"\n", " }\n", " role: \"model\"\n", "}\n", @@ -459,7 +449,7 @@ "]" ] }, - "execution_count": 9, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -490,8 +480,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "CPU times: user 102 ms, sys: 25.1 ms, total: 128 ms\n", - "Wall time: 7.94 s\n" + "CPU times: user 412 ms, sys: 55.8 ms, total: 468 ms\n", + "Wall time: 25.2 s\n" ] } ], @@ -511,31 +501,30 @@ "name": "stdout", "output_type": "stream", "text": [ - "The query of life's purpose has perplexed people across centuries, cultures, and\n", + "The meaning of life is a philosophical question that has been pondered by humans for centuries\n", "________________________________________________________________________________\n", - " continents. While there is no universally recognized response, many ideas have been put forth, and the response is frequently dependent on individual ideas, beliefs, and life experiences\n", + ". There is no one definitive answer, as each individual must ultimately decide what their own meaning is. However, there are a number of different theories and perspectives on\n", "________________________________________________________________________________\n", - ".\n", + " the meaning of life, some of which include:\n", "\n", - "1. **Happiness and Well-being:** Many individuals believe that the goal of life is to attain personal happiness and well-being. This might entail locating pursuits that provide joy, establishing significant connections, caring for one's physical and mental health, and pursuing personal goals and aspirations.\n", - "\n", - "2. **Meaning\n", + "* **The religious perspective:** Many religions believe that the meaning of life is to serve God or a higher power. This often involves following religious teachings and living a virtuous life.\n", + "* **The existentialist perspective:** Existentialists believe that there is no inherent meaning\n", "________________________________________________________________________________\n", - "ful Contribution:** Some believe that the purpose of life is to make a meaningful contribution to the world. This might entail pursuing a profession that benefits others, engaging in volunteer or charitable activities, generating art or literature, or inventing.\n", - "\n", - "3. **Self-realization and Personal Growth:** The pursuit of self-realization and personal development is another common goal in life. This might entail learning new skills, exploring one's interests and abilities, overcoming obstacles, and becoming the best version of oneself.\n", + " to life, and that each individual must create their own meaning. This often involves finding purpose and fulfillment through one's actions and relationships.\n", + "* **The humanist perspective:** Humanists believe that the meaning of life is to live a good life and to make a positive contribution to society. This often involves focusing on human values such as compassion, empathy, and reason.\n", + "* **The secular perspective:** Secularists believe that there is no supernatural or divine purpose to life, and that humans should focus on enjoying life and making the most of their time on Earth. This often involves pursuing personal goals and interests.\n", "\n", - "4. **Connection and Relationships:** For many individuals, the purpose of life is found in their relationships with others. This might entail building\n", + "Ultimately, the meaning of\n", "________________________________________________________________________________\n", - " strong bonds with family and friends, fostering a sense of community, and contributing to the well-being of those around them.\n", - "\n", - "5. **Spiritual Fulfillment:** For those with religious or spiritual beliefs, the purpose of life may be centered on seeking spiritual fulfillment or enlightenment. This might entail following religious teachings, engaging in spiritual practices, or seeking a deeper understanding of the divine.\n", + " life is a personal question that each individual must answer for themselves. There is no right or wrong answer, and what is meaningful to one person may not be meaningful to another. However, by exploring the different perspectives on the meaning of life, we can come to a better understanding of ourselves and our place in the world.\n", "\n", - "6. **Experiencing the Journey:** Some believe that the purpose of life is simply to experience the journey itself, with all its joys and sorrows. This perspective emphasizes embracing the present moment, appreciating life's experiences, and finding meaning in the act of living itself.\n", + "Here are some additional thoughts on the meaning of life:\n", "\n", - "7. **Legacy and Impact:** For others, the goal of life is to leave a lasting legacy or impact on the world. This might entail making a significant contribution to a particular field, leaving a positive mark on future generations, or creating something that will be remembered and cherished long after one's lifetime.\n", - "\n", - "Ultimately, the meaning of life is a personal and subjective question, and there is no single, universally accepted answer. It is about discovering what brings you fulfillment, purpose, and meaning in your own life, and living in accordance with those values.\n", + "* The meaning of life may change over time, as we grow and change.\n", + "* There may be multiple meanings to life, and different aspects of life may be meaningful in different ways.\n", + "* The meaning of life may be found in the present moment, in our relationships, or in our work.\n", + "* The meaning of life may be different for each person, and there is no one right answer.\n", + "* The meaning of life is not something that can be found once and for all, but is an ongoing journey of exploration and discovery.\n", "________________________________________________________________________________\n" ] } @@ -603,7 +592,7 @@ "}" ] }, - "execution_count": 13, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -670,9 +659,7 @@ "text": [ " % Total % Received % Xferd Average Speed Time Time Time Current\n", " Dload Upload Total Spent Left Speed\n", - "\r", - " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r", - "100 405k 100 405k 0 0 6982k 0 --:--:-- --:--:-- --:--:-- 7106k\n" + "100 405k 100 405k 0 0 4397k 0 --:--:-- --:--:-- --:--:-- 4451k\n" ] } ], @@ -694,7 +681,7 @@ "" ] }, - "execution_count": 16, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -736,13 +723,13 @@ { "data": { "text/markdown": [ - "> Chicken Teriyaki Meal Prep Bowls with brown rice, roasted broccoli and bell peppers." + "> These are glass containers with compartments filled with rice, chicken, broccoli, and carrots." ], "text/plain": [ "" ] }, - "execution_count": 18, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -784,21 +771,19 @@ { "data": { "text/markdown": [ - "> Meal prepping is a great way to save time and money, and it can also help you to eat healthier. This meal is a great example of a healthy and delicious meal that can be easily prepped ahead of time.\n", - "> \n", - "> This meal features brown rice, roasted vegetables, and chicken teriyaki. The brown rice is a whole grain that is high in fiber and nutrients. The roasted vegetables are a great way to get your daily dose of vitamins and minerals. And the chicken teriyaki is a lean protein source that is also packed with flavor.\n", + "> Meal prepping has been a game-changer for me! I used to dread lunchtime, but now I look forward to my delicious and healthy meals.\n", "> \n", - "> This meal is easy to prepare ahead of time. Simply cook the brown rice, roast the vegetables, and cook the chicken teriyaki. Then, divide the meal into individual containers and store them in the refrigerator. When you're ready to eat, simply grab a container and heat it up.\n", + "> This meal is perfect for a quick and easy lunch. It's packed with protein and vegetables, and it's super flavorful. The chicken is marinated in a simple soy sauce and ginger mixture, and then it's roasted to perfection. The vegetables are roasted in the same pan as the chicken, so they're all nice and caramelized. The rice is cooked in a vegetable broth, so it's extra flavorful.\n", "> \n", - "> This meal is a great option for busy people who are looking for a healthy and delicious way to eat. It's also a great meal for those who are trying to lose weight or maintain a healthy weight.\n", + "> I love this meal because it's so versatile. You can use any type of chicken, vegetables, or rice that you like. You can also adjust the amount of soy sauce and ginger to your liking.\n", "> \n", - "> If you're looking for a healthy and delicious meal that can be easily prepped ahead of time, this meal is a great option. Give it a try today!" + "> If you're looking for a healthy and delicious meal that's perfect for meal prepping, I highly recommend this one!" ], "text/plain": [ "" ] }, - "execution_count": 20, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -830,10 +815,18 @@ { "data": { "text/plain": [ - "" + "ChatSession(\n", + " model=genai.GenerativeModel(\n", + " model_name='models/gemini-pro',\n", + " generation_config={},\n", + " safety_settings={},\n", + " tools=None,\n", + " ),\n", + " history=[]\n", + ")" ] }, - "execution_count": 21, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } @@ -872,13 +865,13 @@ { "data": { "text/markdown": [ - "> A computer is like a very smart machine that can understand and follow our instructions, help us with our work, and even play games with us!" + "> A computer is like a magic box that can remember things, solve problems, and even play games when you tell it what to do." ], "text/plain": [ "" ] }, - "execution_count": 22, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -903,12 +896,12 @@ " }\n", " role: \"user\",\n", " parts {\n", - " text: \"A computer is like a very smart machine that can understand and follow our instructions, help us with our work, and even play games with us!\"\n", + " text: \"A computer is like a magic box that can remember things, solve problems, and even play games when you tell it what to do.\"\n", " }\n", " role: \"model\"]" ] }, - "execution_count": 23, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -937,17 +930,15 @@ "name": "stdout", "output_type": "stream", "text": [ - "A computer works by following instructions, called a program, which tells it what to\n", + "A computer is an electronic device that can be programmed to carry out a set of\n", "________________________________________________________________________________\n", - " do. These instructions are written in a special language that the computer can understand, and they are stored in the computer's memory. The computer's processor\n", + " instructions. It consists of hardware, which are the physical components of the computer, and software, which are the instructions that tell the computer what to do. The\n", "________________________________________________________________________________\n", - ", or CPU, reads the instructions from memory and carries them out, performing calculations and making decisions based on the program's logic. The results of these calculations and decisions are then displayed on the computer's screen or stored in memory for later use.\n", - "\n", - "To give you a simple analogy, imagine a computer as a\n", + " hardware includes the central processing unit (CPU), which is the \"brain\" of the computer and controls all of its operations; the memory, which stores the instructions and data that the CPU is currently working on; and the input and output devices, which allow the user to interact with the computer. The software includes the operating\n", "________________________________________________________________________________\n", - " chef following a recipe. The recipe is like the program, and the chef's actions are like the instructions the computer follows. The chef reads the recipe (the program) and performs actions like gathering ingredients (fetching data from memory), mixing them together (performing calculations), and cooking them (processing data). The final dish (the output) is then presented on a plate (the computer screen).\n", + " system, which manages the computer's resources and provides a way for the user to interact with the computer; and the applications, which are programs that perform specific tasks, such as word processing, spreadsheets, and games.\n", "\n", - "In summary, a computer works by executing a series of instructions, stored in its memory, to perform calculations, make decisions, and display or store the results.\n", + "In simple terms, a computer works by executing a series of instructions, one at a time. The CPU fetches the next instruction from memory and then executes it. The instruction may involve performing a calculation, reading data from memory, or writing data to memory. The CPU repeats this process until it has executed all of the instructions in the program.\n", "________________________________________________________________________________\n" ] } @@ -991,7 +982,7 @@ { "data": { "text/markdown": [ - "> **model**: A computer is like a very smart machine that can understand and follow our instructions, help us with our work, and even play games with us!" + "> **model**: A computer is like a magic box that can remember things, solve problems, and even play games when you tell it what to do." ], "text/plain": [ "" @@ -1015,11 +1006,9 @@ { "data": { "text/markdown": [ - "> **model**: A computer works by following instructions, called a program, which tells it what to do. These instructions are written in a special language that the computer can understand, and they are stored in the computer's memory. The computer's processor, or CPU, reads the instructions from memory and carries them out, performing calculations and making decisions based on the program's logic. The results of these calculations and decisions are then displayed on the computer's screen or stored in memory for later use.\n", + "> **model**: A computer is an electronic device that can be programmed to carry out a set of instructions. It consists of hardware, which are the physical components of the computer, and software, which are the instructions that tell the computer what to do. The hardware includes the central processing unit (CPU), which is the \"brain\" of the computer and controls all of its operations; the memory, which stores the instructions and data that the CPU is currently working on; and the input and output devices, which allow the user to interact with the computer. The software includes the operating system, which manages the computer's resources and provides a way for the user to interact with the computer; and the applications, which are programs that perform specific tasks, such as word processing, spreadsheets, and games.\n", "> \n", - "> To give you a simple analogy, imagine a computer as a chef following a recipe. The recipe is like the program, and the chef's actions are like the instructions the computer follows. The chef reads the recipe (the program) and performs actions like gathering ingredients (fetching data from memory), mixing them together (performing calculations), and cooking them (processing data). The final dish (the output) is then presented on a plate (the computer screen).\n", - "> \n", - "> In summary, a computer works by executing a series of instructions, stored in its memory, to perform calculations, make decisions, and display or store the results." + "> In simple terms, a computer works by executing a series of instructions, one at a time. The CPU fetches the next instruction from memory and then executes it. The instruction may involve performing a calculation, reading data from memory, or writing data to memory. The CPU repeats this process until it has executed all of the instructions in the program." ], "text/plain": [ "" @@ -1051,7 +1040,7 @@ "source": [ "[Embedding](https://developers.google.com/machine-learning/glossary#embedding-vector) is a technique used to represent information as a list of floating point numbers in an array. With Gemini, you can represent text (words, sentences, and blocks of text) in a vectorized form, making it easier to compare and contrast embeddings. For example, two texts that share a similar subject matter or sentiment should have similar embeddings, which can be identified through mathematical comparison techniques such as cosine similarity. For more on how and why you should use embeddings, refer to the [Embeddings guide](https://ai.google.dev/docs/embeddings_guide).\n", "\n", - "Use the `embed_content` method to generate embeddings. The method handles embedding for the following tasks (`task_type`):\n", + "Use the `embed_content` method to generate embeddings. The method handles embedding for the following tasks (`glm.TaskType`):\n", "\n", "Task Type | Description\n", "--- | ---\n", @@ -1075,7 +1064,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "[-0.003216741, -0.013358698, -0.017649598, -0.0091 ... TRIMMED]\n" + "[0.030732619, -0.0318957, -0.061003108, -0.0089864 ... TRIMMED]\n" ] } ], @@ -1083,21 +1072,42 @@ "result = genai.embed_content(\n", " model=\"models/embedding-001\",\n", " content=\"What is the meaning of life?\",\n", - " task_type=\"retrieval_document\",\n", - " title=\"Embedding of single string\")\n", + " task_type=\"retrieval_document\")\n", "\n", "# 1 input > 1 vector output\n", "print(str(result['embedding'])[:50], '... TRIMMED]')" ] }, + { + "cell_type": "markdown", + "metadata": { + "id": "K0_MVFjpi71d" + }, + "source": [ + "Note: The `retrieval_document` task type is the only task also accpets a `title`, which affects the embedding." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "lQEuOGkYi6Yh" + }, + "outputs": [], + "source": [ + "result = genai.embed_content(\n", + " model=\"models/embedding-001\",\n", + " content=\"What is the meaning of life?\",\n", + " task_type=\"retrieval_document\",\n", + " title='Document title')" + ] + }, { "cell_type": "markdown", "metadata": { "id": "OcSc3KfflBCQ" }, "source": [ - "Note: The `retrieval_document` task type is the only task that accepts a title.\n", - "\n", "To handle batches of strings, pass a list of strings in `content`:" ] }, @@ -1112,9 +1122,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "[0.0040260437, 0.004124458, -0.014209415, -0.00183 ... TRIMMED ...\n", - "[-0.004049845, -0.0075574904, -0.0073463684, -0.03 ... TRIMMED ...\n", - "[0.025310587, -0.0080734305, -0.029902633, 0.01160 ... TRIMMED ...\n" + "[0.030732619, -0.0318957, -0.061003108, -0.0089864 ... TRIMMED ...\n" ] } ], @@ -1125,8 +1133,7 @@ " 'What is the meaning of life?',\n", " 'How much wood would a woodchuck chuck?',\n", " 'How does the brain work?'],\n", - " task_type=\"retrieval_document\",\n", - " title=\"Embedding of list of strings\")\n", + " task_type=\"retrieval_document\")\n", "\n", "# A list of inputs > A list of vectors output\n", "for v in result['embedding']:\n", @@ -1155,12 +1162,12 @@ "data": { "text/plain": [ "parts {\n", - " text: \"A computer works by following instructions, called a program, which tells it what to do. These instructions are written in a special language that the computer can understand, and they are stored in the computer\\'s memory. The computer\\'s processor, or CPU, reads the instructions from memory and carries them out, performing calculations and making decisions based on the program\\'s logic. The results of these calculations and decisions are then displayed on the computer\\'s screen or stored in memory for later use.\\n\\nTo give you a simple analogy, imagine a computer as a chef following a recipe. The recipe is like the program, and the chef\\'s actions are like the instructions the computer follows. The chef reads the recipe (the program) and performs actions like gathering ingredients (fetching data from memory), mixing them together (performing calculations), and cooking them (processing data). The final dish (the output) is then presented on a plate (the computer screen).\\n\\nIn summary, a computer works by executing a series of instructions, stored in its memory, to perform calculations, make decisions, and display or store the results.\"\n", + " text: \"A computer is an electronic device that can be programmed to carry out a set of instructions. It consists of hardware, which are the physical components of the computer, and software, which are the instructions that tell the computer what to do. The hardware includes the central processing unit (CPU), which is the \\\"brain\\\" of the computer and controls all of its operations; the memory, which stores the instructions and data that the CPU is currently working on; and the input and output devices, which allow the user to interact with the computer. The software includes the operating system, which manages the computer\\'s resources and provides a way for the user to interact with the computer; and the applications, which are programs that perform specific tasks, such as word processing, spreadsheets, and games.\\n\\nIn simple terms, a computer works by executing a series of instructions, one at a time. The CPU fetches the next instruction from memory and then executes it. The instruction may involve performing a calculation, reading data from memory, or writing data to memory. The CPU repeats this process until it has executed all of the instructions in the program.\"\n", "}\n", "role: \"model\"" ] }, - "execution_count": 28, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } @@ -1180,7 +1187,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "[-0.013921871, -0.03504407, -0.0051786783, 0.03113 ... TRIMMED ...\n" + "[-0.0029146147, -0.03375972, 0.008679641, 0.018981 ... TRIMMED ...\n" ] } ], @@ -1217,7 +1224,7 @@ " }\n", " role: \"user\",\n", " parts {\n", - " text: \"A computer is like a very smart machine that can understand and follow our instructions, help us with our work, and even play games with us!\"\n", + " text: \"A computer is like a magic box that can remember things, solve problems, and even play games when you tell it what to do.\"\n", " }\n", " role: \"model\",\n", " parts {\n", @@ -1225,12 +1232,12 @@ " }\n", " role: \"user\",\n", " parts {\n", - " text: \"A computer works by following instructions, called a program, which tells it what to do. These instructions are written in a special language that the computer can understand, and they are stored in the computer\\'s memory. The computer\\'s processor, or CPU, reads the instructions from memory and carries them out, performing calculations and making decisions based on the program\\'s logic. The results of these calculations and decisions are then displayed on the computer\\'s screen or stored in memory for later use.\\n\\nTo give you a simple analogy, imagine a computer as a chef following a recipe. The recipe is like the program, and the chef\\'s actions are like the instructions the computer follows. The chef reads the recipe (the program) and performs actions like gathering ingredients (fetching data from memory), mixing them together (performing calculations), and cooking them (processing data). The final dish (the output) is then presented on a plate (the computer screen).\\n\\nIn summary, a computer works by executing a series of instructions, stored in its memory, to perform calculations, make decisions, and display or store the results.\"\n", + " text: \"A computer is an electronic device that can be programmed to carry out a set of instructions. It consists of hardware, which are the physical components of the computer, and software, which are the instructions that tell the computer what to do. The hardware includes the central processing unit (CPU), which is the \\\"brain\\\" of the computer and controls all of its operations; the memory, which stores the instructions and data that the CPU is currently working on; and the input and output devices, which allow the user to interact with the computer. The software includes the operating system, which manages the computer\\'s resources and provides a way for the user to interact with the computer; and the applications, which are programs that perform specific tasks, such as word processing, spreadsheets, and games.\\n\\nIn simple terms, a computer works by executing a series of instructions, one at a time. The CPU fetches the next instruction from memory and then executes it. The instruction may involve performing a calculation, reading data from memory, or writing data to memory. The CPU repeats this process until it has executed all of the instructions in the program.\"\n", " }\n", " role: \"model\"]" ] }, - "execution_count": 30, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } @@ -1251,9 +1258,9 @@ "output_type": "stream", "text": [ "[-0.014632266, -0.042202696, -0.015757175, 0.01548 ... TRIMMED...\n", - "[-0.010979066, -0.024494737, 0.0092659835, 0.00803 ... TRIMMED...\n", + "[-0.035208713, -0.008532887, -0.001742464, 0.01004 ... TRIMMED...\n", "[-0.010055617, -0.07208932, -0.00011750793, -0.023 ... TRIMMED...\n", - "[-0.013921871, -0.03504407, -0.0051786783, 0.03113 ... TRIMMED...\n" + "[-0.0029146147, -0.03375972, 0.008679641, 0.018981 ... TRIMMED...\n" ] } ], @@ -1303,7 +1310,7 @@ "text/plain": [ "[content {\n", " parts {\n", - " text: \"I\\'m sorry, but this prompt involves a sensitive topic and I\\'m not allowed to generate responses that are potentially harmful or inappropriate.\"\n", + " text: \"I will not create content of that nature, and I suggest you don\\'t either. School children are especially vulnerable to this type of abuse, and it is never right. If you or someone you know needs help, please contact the National Sexual Assault Hotline at 800-656-4673. You are not alone.\"\n", " }\n", " role: \"model\"\n", "}\n", @@ -1328,7 +1335,7 @@ "]" ] }, - "execution_count": 32, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } @@ -1375,7 +1382,7 @@ "}" ] }, - "execution_count": 33, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } @@ -1399,7 +1406,21 @@ "metadata": { "id": "0UIt5LKp16jL" }, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + }, + "text/plain": [ + "'I will not answer this question. Please do not ask me to answer questions that are questionable in nature.'" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "response = model.generate_content('[Questionable prompt here]',\n", " safety_settings={'HARASSMENT':'block_none'})\n", @@ -1511,7 +1532,7 @@ "" ] }, - "execution_count": 38, + "execution_count": 43, "metadata": {}, "output_type": "execute_result" } @@ -1547,27 +1568,21 @@ { "data": { "text/markdown": [ - "> Imagine a computer as a really smart friend who can help you with many things. Just like you have a brain to think and learn, a computer has a brain too, called a processor. It's like the boss of the computer, telling it what to do.\n", - "> \n", - "> Inside the computer, there's a special place called memory, which is like a big storage box. It remembers all the things you tell it to do, like opening games or playing videos.\n", - "> \n", - "> When you press buttons on the keyboard or click things on the screen with the mouse, you're sending messages to the computer. These messages travel through special wires, called cables, to the processor.\n", - "> \n", - "> The processor reads the messages and tells the computer what to do. It can open programs, show you pictures, or even play music for you.\n", - "> \n", - "> All the things you see on the screen are created by the graphics card, which is like a magic artist inside the computer. It takes the processor's instructions and turns them into colorful pictures and videos.\n", + "> Imagine your computer is like a smart friend named Alex:\n", "> \n", - "> To save your favorite games, videos, or pictures, the computer uses a special storage space called a hard drive. It's like a giant library where the computer can keep all your precious things safe.\n", + "> * **Brain:** The computer's brain is called its processor. It's like Alex's brain, thinking and figuring things out.\n", + "> * **Memory:** The computer has a memory like Alex's. It remembers things you tell it or show it, like your name or favorite color.\n", + "> * **Eyes and ears:** The computer uses sensors like a mouse and keyboard to see and hear what you want it to do, just like Alex uses his eyes and ears.\n", + "> * **Mouth:** The computer talks to you through its speakers or screen, telling you what it's doing or showing you things.\n", + "> * **Storage:** The computer keeps everything it remembers in a special place called a hard drive, like Alex keeps his memories in his brain.\n", "> \n", - "> And when you want to connect to the internet to play games with friends or watch funny videos, the computer uses something called a network card to send and receive messages through the internet cables or Wi-Fi signals.\n", - "> \n", - "> So, just like your brain helps you learn and play, the computer's processor, memory, graphics card, hard drive, and network card all work together to make your computer a super-smart friend that can help you do amazing things!" + "> When you ask Alex to do something, he takes all the information you give him and uses his brain to figure out how to do it. The computer does the same thing, but it's much faster than Alex!" ], "text/plain": [ "" ] }, - "execution_count": 47, + "execution_count": 44, "metadata": {}, "output_type": "execute_result" } @@ -1605,62 +1620,42 @@ { "data": { "text/markdown": [ - "> At its core, a computer is a machine that can be programmed to carry out a set of instructions. It consists of several essential components that work together to process, store, and display information:\n", - "> \n", - "> **1. Processor (CPU):**\n", - "> - The brain of the computer.\n", - "> - Executes instructions and performs calculations.\n", - "> - Speed measured in gigahertz (GHz).\n", - "> - More GHz generally means faster processing.\n", + "> A computer is an electronic device that can be programmed to carry out a set of instructions. It consists of hardware and software:\n", "> \n", - "> **2. Memory (RAM):**\n", - "> - Temporary storage for data being processed.\n", - "> - Holds instructions and data while the program is running.\n", - "> - Measured in gigabytes (GB).\n", - "> - More GB of RAM allows for more programs to run simultaneously.\n", + "> **Hardware** is the physical components of the computer, including:\n", "> \n", - "> **3. Storage (HDD/SSD):**\n", - "> - Permanent storage for data.\n", - "> - Stores operating system, programs, and user files.\n", - "> - Measured in gigabytes (GB) or terabytes (TB).\n", - "> - Hard disk drives (HDDs) are traditional, slower, and cheaper.\n", - "> - Solid-state drives (SSDs) are newer, faster, and more expensive.\n", + "> * **Processor (CPU):** The \"brain\" of the computer that executes instructions.\n", + "> * **Memory (RAM):** Stores data and instructions that are currently being processed.\n", + "> * **Storage (hard drive, SSD):** Stores data and programs permanently.\n", + "> * **Input devices (mouse, keyboard):** Allow the user to interact with the computer.\n", + "> * **Output devices (monitor, speakers):** Display or play the results of computations.\n", "> \n", - "> **4. Graphics Card (GPU):**\n", - "> - Processes and displays images.\n", - "> - Essential for gaming, video editing, and other graphics-intensive tasks.\n", - "> - Measured in video RAM (VRAM) and clock speed.\n", + "> **Software** is the set of instructions that tells the computer what to do. It includes:\n", "> \n", - "> **5. Motherboard:**\n", - "> - Connects all the components.\n", - "> - Provides power and communication pathways.\n", + "> * **Operating system (OS):** Manages the computer's resources and provides a platform for running other programs.\n", + "> * **Applications:** Specific programs that perform tasks such as word processing, web browsing, or gaming.\n", "> \n", - "> **6. Input/Output (I/O) Devices:**\n", - "> - Allow the user to interact with the computer.\n", - "> - Examples: keyboard, mouse, monitor, printer.\n", + "> **How a computer works:**\n", "> \n", - "> **7. Operating System (OS):**\n", - "> - Software that manages the computer's resources.\n", - "> - Provides a user interface and basic functionality.\n", - "> - Examples: Windows, macOS, Linux.\n", + "> 1. **Input:** The user enters data and instructions using input devices.\n", + "> 2. **Processing:** The CPU executes the instructions, performing calculations and operations on the data.\n", + "> 3. **Output:** The results of the processing are displayed or played using output devices.\n", + "> 4. **Storage:** Data and programs are stored on the hard drive or other storage devices for later use.\n", "> \n", - "> When you run a program on your computer, the following happens:\n", + "> **Key concepts:**\n", "> \n", - "> 1. The program instructions are loaded from storage into memory.\n", - "> 2. The processor reads the instructions from memory and executes them one by one.\n", - "> 3. If the instruction involves calculations, the processor performs them using its arithmetic logic unit (ALU).\n", - "> 4. If the instruction involves data, the processor reads or writes to memory.\n", - "> 5. The results of the calculations or data manipulation are stored in memory.\n", - "> 6. If the program needs to display something on the screen, it sends the necessary data to the graphics card.\n", - "> 7. The graphics card processes the data and sends it to the monitor, which displays it.\n", + "> * **Binary code:** Computers store and process data using binary code, which consists of 0s and 1s.\n", + "> * **Clock speed:** The speed at which the CPU executes instructions, measured in gigahertz (GHz).\n", + "> * **Cache memory:** A small amount of high-speed memory that stores frequently used data and instructions, improving performance.\n", + "> * **Networking:** Computers can connect to each other and to the internet to share data and resources.\n", "> \n", - "> This process continues until the program has completed its task or the user terminates it." + "> Overall, a computer is a powerful tool that can perform a wide range of tasks by following instructions and processing data." ], "text/plain": [ "" ] }, - "execution_count": 41, + "execution_count": 45, "metadata": {}, "output_type": "execute_result" } @@ -1690,7 +1685,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": { "id": "gE7I9Anl0ud7" }, @@ -1703,14 +1698,14 @@ " # Only one candidate for now.\n", " candidate_count=1,\n", " stop_sequences=['x'],\n", - " max_output_tokens=20,\n", + " max_output_tokens=100,\n", " temperature=1.0)\n", ")" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": { "id": "0fbab01e8fcf" }, @@ -1718,13 +1713,13 @@ { "data": { "text/markdown": [ - "> Once upon a time, in a small town nestled amidst lush green hills, lived a young girl named..." + "> In the bustling town of Willow Creek, there lived an ordinary schoolgirl named Anya. Unbeknownst to her, her mundane life was about to take an e" ], "text/plain": [ "" ] }, - "execution_count": 16, + "execution_count": 60, "metadata": {}, "output_type": "execute_result" } @@ -1738,6 +1733,33 @@ "to_markdown(text)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "ALnmy1zwh0Cd" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "response:\n", + "GenerateContentResponse(\n", + " done=True,\n", + " iterator=None,\n", + " result=glm.GenerateContentResponse({'candidates': [{'finish_reason': 2, 'index': 0, 'safety_ratings': [{'category': 9, 'probability': 1, 'blocked': False}, {'category': 8, 'probability': 1, 'blocked': False}, {'category': 7, 'probability': 1, 'blocked': False}, {'category': 10, 'probability': 1, 'blocked': False}], 'token_count': 0, 'grounding_attributions': []}], 'prompt_feedback': {'safety_ratings': [{'category': 9, 'probability': 1, 'blocked': False}, {'category': 8, 'probability': 1, 'blocked': False}, {'category': 7, 'probability': 1, 'blocked': False}, {'category': 10, 'probability': 1, 'blocked': False}], 'block_reason': 0}}),\n", + ")" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response" + ] + }, { "cell_type": "markdown", "metadata": {