|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 2, |
| 6 | + "id": "d51ed763-72b9-4f29-b10e-b75c537597c9", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "# ! pip install google-generativeai" |
| 11 | + ] |
| 12 | + }, |
| 13 | + { |
| 14 | + "cell_type": "markdown", |
| 15 | + "id": "9d1d7b5d-b943-4bab-bbbe-8a176fd5130e", |
| 16 | + "metadata": {}, |
| 17 | + "source": [ |
| 18 | + "## **Importing Google Gemini AI**" |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "code", |
| 23 | + "execution_count": 3, |
| 24 | + "id": "dfb7d1b8-f430-4f9b-b2a4-417a8db6313c", |
| 25 | + "metadata": {}, |
| 26 | + "outputs": [], |
| 27 | + "source": [ |
| 28 | + "import google.generativeai as genai" |
| 29 | + ] |
| 30 | + }, |
| 31 | + { |
| 32 | + "cell_type": "markdown", |
| 33 | + "id": "b3e0b31b-e2db-43e7-9999-347e3c441724", |
| 34 | + "metadata": {}, |
| 35 | + "source": [ |
| 36 | + "## **Setting the API Key**" |
| 37 | + ] |
| 38 | + }, |
| 39 | + { |
| 40 | + "cell_type": "code", |
| 41 | + "execution_count": 4, |
| 42 | + "id": "0ad6eea9-585d-427f-aa76-da4d26111804", |
| 43 | + "metadata": {}, |
| 44 | + "outputs": [], |
| 45 | + "source": [ |
| 46 | + "f = open(\"keys/.gemini.txt\")\n", |
| 47 | + "key = f.read()\n", |
| 48 | + "\n", |
| 49 | + "genai.configure(api_key=key)" |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "markdown", |
| 54 | + "id": "991360dd-a618-479a-904d-5e07661e2697", |
| 55 | + "metadata": {}, |
| 56 | + "source": [ |
| 57 | + "## **Available Models**" |
| 58 | + ] |
| 59 | + }, |
| 60 | + { |
| 61 | + "cell_type": "code", |
| 62 | + "execution_count": 6, |
| 63 | + "id": "672b0037-b730-4955-9402-bbecf0f27fe1", |
| 64 | + "metadata": {}, |
| 65 | + "outputs": [ |
| 66 | + { |
| 67 | + "name": "stdout", |
| 68 | + "output_type": "stream", |
| 69 | + "text": [ |
| 70 | + "models/gemini-1.0-pro\n", |
| 71 | + "models/gemini-1.0-pro-001\n", |
| 72 | + "models/gemini-1.0-pro-latest\n", |
| 73 | + "models/gemini-1.0-pro-vision-latest\n", |
| 74 | + "models/gemini-1.5-pro-latest\n", |
| 75 | + "models/gemini-pro\n", |
| 76 | + "models/gemini-pro-vision\n" |
| 77 | + ] |
| 78 | + } |
| 79 | + ], |
| 80 | + "source": [ |
| 81 | + "for m in genai.list_models():\n", |
| 82 | + " if 'generateContent' in m.supported_generation_methods:\n", |
| 83 | + " print(m.name)" |
| 84 | + ] |
| 85 | + }, |
| 86 | + { |
| 87 | + "cell_type": "markdown", |
| 88 | + "id": "7ef743af-5075-469a-9126-200e13439f7c", |
| 89 | + "metadata": {}, |
| 90 | + "source": [ |
| 91 | + "## **Prompting the Gemini Model**" |
| 92 | + ] |
| 93 | + }, |
| 94 | + { |
| 95 | + "cell_type": "code", |
| 96 | + "execution_count": 7, |
| 97 | + "id": "74ced0d0-98ef-48a5-bb03-8372a4576604", |
| 98 | + "metadata": {}, |
| 99 | + "outputs": [ |
| 100 | + { |
| 101 | + "name": "stdout", |
| 102 | + "output_type": "stream", |
| 103 | + "text": [ |
| 104 | + "planet.\n" |
| 105 | + ] |
| 106 | + } |
| 107 | + ], |
| 108 | + "source": [ |
| 109 | + "model = genai.GenerativeModel(model_name=\"gemini-pro\")\n", |
| 110 | + "\n", |
| 111 | + "user_prompt = \"\"\"Complete the following:\n", |
| 112 | + " In our solar system, Earth is a \"\"\"\n", |
| 113 | + "\n", |
| 114 | + "response = model.generate_content(user_prompt)\n", |
| 115 | + "\n", |
| 116 | + "print(response.text)" |
| 117 | + ] |
| 118 | + }, |
| 119 | + { |
| 120 | + "cell_type": "code", |
| 121 | + "execution_count": 8, |
| 122 | + "id": "ab0e6f5b-63c6-4d7d-a488-ed22c6344a77", |
| 123 | + "metadata": {}, |
| 124 | + "outputs": [ |
| 125 | + { |
| 126 | + "name": "stdout", |
| 127 | + "output_type": "stream", |
| 128 | + "text": [ |
| 129 | + "In our solar system, Earth is a terrestrial or rocky planet, composed primarily of metals and minerals. It is the third planet from the Sun, residing in the inner solar system.\n" |
| 130 | + ] |
| 131 | + } |
| 132 | + ], |
| 133 | + "source": [ |
| 134 | + "model = genai.GenerativeModel(model_name=\"gemini-pro\")\n", |
| 135 | + "\n", |
| 136 | + "user_prompt = \"\"\"Generate some factual information to complete the following in 2-3 lines:\n", |
| 137 | + " In our solar system, Earth is a \"\"\"\n", |
| 138 | + "\n", |
| 139 | + "response = model.generate_content(user_prompt)\n", |
| 140 | + "\n", |
| 141 | + "print(response.text)" |
| 142 | + ] |
| 143 | + }, |
| 144 | + { |
| 145 | + "cell_type": "markdown", |
| 146 | + "id": "27c53a90-0a98-4404-87b2-1d17e5bca01f", |
| 147 | + "metadata": {}, |
| 148 | + "source": [ |
| 149 | + "## **Converstation AI using Gemini AI**" |
| 150 | + ] |
| 151 | + }, |
| 152 | + { |
| 153 | + "cell_type": "code", |
| 154 | + "execution_count": null, |
| 155 | + "id": "513a14c4-0211-473c-80d8-90a918376cac", |
| 156 | + "metadata": {}, |
| 157 | + "outputs": [], |
| 158 | + "source": [] |
| 159 | + } |
| 160 | + ], |
| 161 | + "metadata": { |
| 162 | + "kernelspec": { |
| 163 | + "display_name": "Python 3 (ipykernel)", |
| 164 | + "language": "python", |
| 165 | + "name": "python3" |
| 166 | + }, |
| 167 | + "language_info": { |
| 168 | + "codemirror_mode": { |
| 169 | + "name": "ipython", |
| 170 | + "version": 3 |
| 171 | + }, |
| 172 | + "file_extension": ".py", |
| 173 | + "mimetype": "text/x-python", |
| 174 | + "name": "python", |
| 175 | + "nbconvert_exporter": "python", |
| 176 | + "pygments_lexer": "ipython3", |
| 177 | + "version": "3.9.13" |
| 178 | + } |
| 179 | + }, |
| 180 | + "nbformat": 4, |
| 181 | + "nbformat_minor": 5 |
| 182 | +} |
0 commit comments