Skip to content

Commit

Permalink
genai.protos
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkDaoust committed Jun 7, 2024
1 parent 3f89dcc commit bd3b159
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions site/en/gemini-api/docs/get-started/python.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@
"id": "AwCqtZ6D4kvk"
},
"source": [
"`protos.Content` objects contain a list of `protos.Part` objects that each contain either a text (string) or inline_data (`protos.Blob`), where a blob contains binary data and a `mime_type`. The chat history is available as a list of `protos.Content` objects in `ChatSession.history`:"
"`genai.protos.Content` objects contain a list of `genai.protos.Part` objects that each contain either a text (string) or inline_data (`genai.protos.Blob`), where a blob contains binary data and a `mime_type`. The chat history is available as a list of `genai.protos.Content` objects in `ChatSession.history`:"
]
},
{
Expand Down Expand Up @@ -1033,7 +1033,7 @@
"source": [
"## Count tokens\n",
"\n",
"Large language models have a context window, and the context length is often measured in terms of the **number of tokens**. With the Gemini API, you can determine the number of tokens per any `protos.Content` object. In the simplest case, you can pass a query string to the `GenerativeModel.count_tokens` method as follows:"
"Large language models have a context window, and the context length is often measured in terms of the **number of tokens**. With the Gemini API, you can determine the number of tokens per any `genai.protos.Content` object. In the simplest case, you can pass a query string to the `GenerativeModel.count_tokens` method as follows:"
]
},
{
Expand Down Expand Up @@ -1188,9 +1188,9 @@
"id": "zBg0eNeml3d4"
},
"source": [
"While the `genai.embed_content` function accepts simple strings or lists of strings, it is actually built around the `protos.Content` type (like <a href=\"https://ai.google.dev/api/python/google/generativeai/GenerativeModel#generate_content\"><code>GenerativeModel.generate_content</code></a>). `protos.Content` objects are the primary units of conversation in the API.\n",
"While the `genai.embed_content` function accepts simple strings or lists of strings, it is actually built around the `genai.protos.Content` type (like <a href=\"https://ai.google.dev/api/python/google/generativeai/GenerativeModel#generate_content\"><code>GenerativeModel.generate_content</code></a>). `genai.protos.Content` objects are the primary units of conversation in the API.\n",
"\n",
"While the `protos.Content` object is multimodal, the `embed_content` method only supports text embeddings. This design gives the API the *possibility* to expand to multimodal embeddings."
"While the `genai.protos.Content` object is multimodal, the `embed_content` method only supports text embeddings. This design gives the API the *possibility* to expand to multimodal embeddings."
]
},
{
Expand Down Expand Up @@ -1248,7 +1248,7 @@
"id": "jU8juHCxoUKG"
},
"source": [
"Similarly, the chat history contains a list of `protos.Content` objects, which you can pass directly to the `embed_content` function:"
"Similarly, the chat history contains a list of `genai.protos.Content` objects, which you can pass directly to the `embed_content` function:"
]
},
{
Expand Down Expand Up @@ -1491,27 +1491,16 @@
"The [`google.generativeai.protos`](https://ai.google.dev/api/python/google/generativeai/protos) submodule provides access to the low level classes used by the API behind the scenes:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "l6aafWECnpX6"
},
"outputs": [],
"source": [
"from google.generativeai import protos"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "gm1RWcB3n_n0"
},
"source": [
"The SDK attempts to convert your message to a `protos.Content` object, which contains a list of `protos.Part` objects that each contain either:\n",
"The SDK attempts to convert your message to a `genai.protos.Content` object, which contains a list of `genai.protos.Part` objects that each contain either:\n",
"\n",
"1. a <a href=\"https://www.tensorflow.org/text/api_docs/python/text\"><code>text</code></a> (string)\n",
"2. `inline_data` (`protos.Blob`), where a blob contains binary `data` and a `mime_type`.\n",
"2. `inline_data` (`genai.protos.Blob`), where a blob contains binary `data` and a `mime_type`.\n",
"\n",
"You can also pass any of these classes as an equivalent dictionary.\n",
"\n",
Expand All @@ -1530,11 +1519,11 @@
"source": [
"model = genai.GenerativeModel('gemini-1.5-flash')\n",
"response = model.generate_content(\n",
" protos.Content(\n",
" genai.protos.Content(\n",
" parts = [\n",
" protos.Part(text=\"Write a short, engaging blog post based on this picture.\"),\n",
" protos.Part(\n",
" inline_data=protos.Blob(\n",
" genai.protos.Part(text=\"Write a short, engaging blog post based on this picture.\"),\n",
" genai.protos.Part(\n",
" inline_data=genai.protos.Blob(\n",
" mime_type='image/jpeg',\n",
" data=pathlib.Path('image.jpg').read_bytes()\n",
" )\n",
Expand Down Expand Up @@ -1581,9 +1570,9 @@
"\n",
"While the `genai.ChatSession` class shown earlier can handle many use cases, it does make some assumptions. If your use case doesn't fit into this chat implementation it's good to remember that `genai.ChatSession` is just a wrapper around <a href=\"https://ai.google.dev/api/python/google/generativeai/GenerativeModel#generate_content\"><code>GenerativeModel.generate_content</code></a>. In addition to single requests, it can handle multi-turn conversations.\n",
"\n",
"The individual messages are `protos.Content` objects or compatible dictionaries, as seen in previous sections. As a dictionary, the message requires `role` and `parts` keys. The `role` in a conversation can either be the `user`, which provides the prompts, or `model`, which provides the responses.\n",
"The individual messages are `genai.protos.Content` objects or compatible dictionaries, as seen in previous sections. As a dictionary, the message requires `role` and `parts` keys. The `role` in a conversation can either be the `user`, which provides the prompts, or `model`, which provides the responses.\n",
"\n",
"Pass a list of `protos.Content` objects and it will be treated as multi-turn chat:"
"Pass a list of `genai.protos.Content` objects and it will be treated as multi-turn chat:"
]
},
{
Expand Down

0 comments on commit bd3b159

Please sign in to comment.