|
64 | 64 | },
|
65 | 65 | {
|
66 | 66 | "cell_type": "code",
|
67 |
| - "execution_count": 8, |
| 67 | + "execution_count": 5, |
68 | 68 | "metadata": {
|
69 | 69 | "id": "Ne-3gnXqR0hI"
|
70 | 70 | },
|
71 | 71 | "outputs": [],
|
72 | 72 | "source": [
|
73 |
| - "!pip install -U -q \"google-generativeai>=0.7.2\"" |
74 |
| - ] |
75 |
| - }, |
76 |
| - { |
77 |
| - "cell_type": "code", |
78 |
| - "execution_count": 9, |
79 |
| - "metadata": { |
80 |
| - "id": "EconMHePQHGw" |
81 |
| - }, |
82 |
| - "outputs": [], |
83 |
| - "source": [ |
84 |
| - "import google.generativeai as genai\n", |
85 |
| - "\n", |
86 |
| - "import json\n", |
87 |
| - "from enum import Enum\n", |
88 |
| - "from typing_extensions import TypedDict # in python 3.12 replace typing_extensions with typing" |
| 73 | + "%pip install -U -q \"google-genai>=1.0.0\"" |
89 | 74 | ]
|
90 | 75 | },
|
91 | 76 | {
|
|
101 | 86 | },
|
102 | 87 | {
|
103 | 88 | "cell_type": "code",
|
104 |
| - "execution_count": 10, |
| 89 | + "execution_count": 6, |
105 | 90 | "metadata": {
|
106 | 91 | "id": "v-JZzORUpVR2"
|
107 | 92 | },
|
108 | 93 | "outputs": [],
|
109 | 94 | "source": [
|
110 | 95 | "from google.colab import userdata\n",
|
111 |
| - "GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')\n", |
| 96 | + "from google import genai\n", |
112 | 97 | "\n",
|
113 |
| - "genai.configure(api_key=GOOGLE_API_KEY)" |
| 98 | + "GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')\n", |
| 99 | + "client = genai.Client(api_key=GOOGLE_API_KEY)" |
114 | 100 | ]
|
115 | 101 | },
|
116 | 102 | {
|
|
124 | 110 | },
|
125 | 111 | {
|
126 | 112 | "cell_type": "code",
|
127 |
| - "execution_count": 20, |
| 113 | + "execution_count": 7, |
128 | 114 | "metadata": {
|
129 | 115 | "id": "QGdJnd0AOKbu"
|
130 | 116 | },
|
131 | 117 | "outputs": [],
|
132 | 118 | "source": [
|
| 119 | + "from enum import Enum\n", |
| 120 | + "from typing_extensions import TypedDict # in python 3.12 replace typing_extensions with typing\n", |
| 121 | + "from google.genai import types\n", |
| 122 | + "\n", |
133 | 123 | "entity_recognition_text = \"John Johnson, the CEO of the Oil Inc. and Coal Inc. companies, has unveiled plans to build a new factory in Houston, Texas.\"\n",
|
134 | 124 | "prompt = f\"\"\"\n",
|
135 | 125 | "Generate list of entities in text based on the following Python class structure:\n",
|
|
148 | 138 | " entities: list[Entity]\n",
|
149 | 139 | "\n",
|
150 | 140 | "{entity_recognition_text}\"\"\"\n",
|
151 |
| - "model = genai.GenerativeModel(model_name='gemini-2.0-flash', generation_config={\"temperature\": 0})\n", |
152 |
| - "response = model.generate_content(prompt, generation_config={\"response_mime_type\": \"application/json\"})" |
| 141 | + "MODEL_ID = \"gemini-2.0-flash\" # @param [\"gemini-2.0-flash-lite\",\"gemini-2.0-flash\",\"gemini-2.0-pro-exp-02-05\"] {\"allow-input\":true, isTemplate: true}\n", |
| 142 | + "\n", |
| 143 | + "response = client.models.generate_content(\n", |
| 144 | + " model=MODEL_ID,\n", |
| 145 | + " contents=prompt,\n", |
| 146 | + " config=types.GenerateContentConfig(\n", |
| 147 | + " temperature=0,\n", |
| 148 | + " response_mime_type=\"application/json\"\n", |
| 149 | + " )\n", |
| 150 | + " )" |
153 | 151 | ]
|
154 | 152 | },
|
155 | 153 | {
|
156 | 154 | "cell_type": "code",
|
157 |
| - "execution_count": 21, |
| 155 | + "execution_count": 8, |
158 | 156 | "metadata": {
|
159 | 157 | "id": "d5tOgde6ONo3"
|
160 | 158 | },
|
|
191 | 189 | }
|
192 | 190 | ],
|
193 | 191 | "source": [
|
| 192 | + "import json\n", |
| 193 | + "\n", |
194 | 194 | "print(json.dumps(json.loads(response.text), indent=4))"
|
195 | 195 | ]
|
196 | 196 | },
|
|
0 commit comments