Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix notebooks #445

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
}
],
"source": [
"!pip install --quiet langchain"
"!pip install --quiet langchain langchain-community"
]
},
{
Expand Down Expand Up @@ -221,10 +221,10 @@
],
"source": [
"# Run this cell and paste the API key in the prompt\n",
"import os\n",
"import getpass\n",
"from google.colab import userdata\n",
"GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')\n",
"\n",
"os.environ['GOOGLE_API_KEY'] = getpass.getpass('Gemini API Key:')"
"genai.configure(api_key=GOOGLE_API_KEY)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
}
],
"source": [
"!pip install --quiet langchain"
"!pip install --quiet langchain langchain-community"
]
},
{
Expand Down Expand Up @@ -153,7 +153,9 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/211.0 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m\u001b[90m━━━\u001b[0m \u001b[32m194.6/211.0 kB\u001b[0m \u001b[31m5.7 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m211.0/211.0 kB\u001b[0m \u001b[31m4.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/211.0 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r",
"\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m\u001b[90m━━━\u001b[0m \u001b[32m194.6/211.0 kB\u001b[0m \u001b[31m5.7 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m211.0/211.0 kB\u001b[0m \u001b[31m4.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25h"
]
}
Expand Down Expand Up @@ -182,7 +184,9 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/201.4 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m\u001b[90m━\u001b[0m \u001b[32m194.6/201.4 kB\u001b[0m \u001b[31m5.7 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m201.4/201.4 kB\u001b[0m \u001b[31m4.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/201.4 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r",
"\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m\u001b[90m━\u001b[0m \u001b[32m194.6/201.4 kB\u001b[0m \u001b[31m5.7 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m201.4/201.4 kB\u001b[0m \u001b[31m4.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25h"
]
}
Expand Down Expand Up @@ -222,10 +226,9 @@
],
"source": [
"# Run this cell and paste the API key in the prompt\n",
"import os\n",
"import getpass\n",
"\n",
"os.environ['GOOGLE_API_KEY'] = getpass.getpass('Gemini API Key:')"
"from google.colab import userdata\n",
"GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')\n",
"genai.configure(api_key=GOOGLE_API_KEY)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
}
],
"source": [
"!pip install --quiet langchain"
"!pip install --quiet langchain langchain-community"
]
},
{
Expand Down Expand Up @@ -168,10 +168,10 @@
],
"source": [
"# Run this cell and paste the API key in the prompt\n",
"import os\n",
"import getpass\n",
"from google.colab import userdata\n",
"GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')\n",
"\n",
"os.environ['GOOGLE_API_KEY'] = getpass.getpass('Gemini API Key:')"
"genai.configure(api_key=GOOGLE_API_KEY)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"outputs": [],
"source": [
"# This guide was tested with 0.10.17, but feel free to try newer versions.\n",
"!pip install -q llama-index==0.10.17"
"!pip install -q llama-index==0.10.17 llama-index-vector-stores-chroma"
]
},
{
Expand Down Expand Up @@ -194,27 +194,39 @@
"In this tutorial, you will set the variable `gemini_api_key` to configure Gemini to use your API key."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "d3316f4b3b5e"
},
"outputs": [],
"source": [
"import os"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Wp3pYcnh60vt"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Gemini API Key:··········\n"
]
}
],
"outputs": [],
"source": [
"# Run this cell and paste the API key in the prompt\n",
"import os\n",
"import getpass\n",
"\n",
"gemini_api_key = getpass.getpass('Gemini API Key:')"
"from google.colab import userdata\n",
"os.environ['GOOGLE_API_KEY'] = userdata.get('GOOGLE_API_KEY')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "9f968d66b8cf"
},
"outputs": [],
"source": [
"gemini_api_key = os.environ['GOOGLE_API_KEY']"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@
"import google.generativeai as genai\n",
"import google.ai.generativelanguage as glm\n",
"\n",
"# Used to securely store your API key\n",
"from google.colab import userdata\n",
"\n",
"from IPython.display import Markdown\n",
"from chromadb import Documents, EmbeddingFunction, Embeddings"
]
Expand Down Expand Up @@ -175,7 +172,9 @@
},
"outputs": [],
"source": [
"# Used to securely store your API key\n",
"# Or use `os.getenv('API_KEY')` to fetch an environment variable.\n",
"from google.colab import userdata\n",
"API_KEY=userdata.get('API_KEY')\n",
"\n",
"genai.configure(api_key=API_KEY)"
Expand Down
20 changes: 15 additions & 5 deletions site/en/examples/chat_calculator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,20 @@
},
"outputs": [],
"source": [
"import google.generativeai as genai\n",
"genai.configure(api_key=\"YOUR API KEY\")"
"import google.generativeai as genai"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "75c7d4b67511"
},
"outputs": [],
"source": [
"from google.colab import userdata\n",
"GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')\n",
"genai.configure(api_key=GOOGLE_API_KEY)"
]
},
{
Expand All @@ -139,9 +151,7 @@
},
"outputs": [],
"source": [
"models = [m for m in genai.list_models() if 'generateMessage' in m.supported_generation_methods]\n",
"model = models[0].name\n",
"print(model)"
"model = 'models/chat-bison-001'"
]
},
{
Expand Down
18 changes: 14 additions & 4 deletions site/en/examples/text_calculator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
"outputs": [],
"source": [
"import google.generativeai as genai\n",
"genai.configure(api_key='YOUR API KEY')\n",
"\n",
"from google.api_core import retry\n",
"\n",
Expand All @@ -116,6 +115,19 @@
" return genai.generate_text(*args, **kwargs)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "14c8b88a75ef"
},
"outputs": [],
"source": [
"from google.colab import userdata\n",
"GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')\n",
"genai.configure(api_key=GOOGLE_API_KEY)"
]
},
{
"cell_type": "code",
"execution_count": 3,
Expand All @@ -132,9 +144,7 @@
}
],
"source": [
"models = [m for m in genai.list_models() if 'generateText' in m.supported_generation_methods]\n",
"model = models[0].name\n",
"print(model)"
"model = 'models/text-bison-001'"
]
},
{
Expand Down
5 changes: 1 addition & 4 deletions site/en/gemini-api/docs/model-tuning/python.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,7 @@
}
],
"source": [
"base_model = [\n",
" m for m in genai.list_models()\n",
" if \"createTunedModel\" in m.supported_generation_methods][0]\n",
"base_model"
"base_model = genai.get_model('models/gemini-1.0-pro-001')\n"
]
},
{
Expand Down
9 changes: 7 additions & 2 deletions site/en/gemini-api/docs/model-tuning/rest.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@
"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\r100 2280 0 296 100 1984 611 4098 --:--:-- --:--:-- --:--:-- 4720\n"
"\r",
" 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r",
"100 2280 0 296 100 1984 611 4098 --:--:-- --:--:-- --:--:-- 4720\n"
]
}
],
Expand Down Expand Up @@ -437,7 +439,10 @@
"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 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r100 5921 0 5921 0 0 13164 0 --:--:-- --:--:-- --:--:-- 13157\n"
"\r",
" 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r",
" 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r",
"100 5921 0 5921 0 0 13164 0 --:--:-- --:--:-- --:--:-- 13157\n"
]
}
],
Expand Down
6 changes: 3 additions & 3 deletions site/en/gemini-api/tutorials/anomaly_detection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@
"import google.generativeai as genai\n",
"import google.ai.generativelanguage as glm\n",
"\n",
"# Used to securely store your API key\n",
"from google.colab import userdata\n",
"\n",
"from sklearn.datasets import fetch_20newsgroups\n",
"from sklearn.manifold import TSNE"
]
Expand Down Expand Up @@ -148,6 +145,9 @@
},
"outputs": [],
"source": [
"# Used to securely store your API key\n",
"from google.colab import userdata\n",
"\n",
"# Or use `os.getenv('API_KEY')` to fetch an environment variable.\n",
"API_KEY=userdata.get('API_KEY')\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@
"import google.generativeai as genai\n",
"import google.ai.generativelanguage as glm\n",
"\n",
"# Used to securely store your API key\n",
"from google.colab import userdata\n",
"\n",
"from sklearn.datasets import fetch_20newsgroups\n",
"from sklearn.manifold import TSNE\n",
"from sklearn.cluster import KMeans\n",
Expand Down Expand Up @@ -151,6 +148,9 @@
},
"outputs": [],
"source": [
"# Used to securely store your API key\n",
"from google.colab import userdata\n",
"\n",
"# Or use `os.getenv('API_KEY')` to fetch an environment variable.\n",
"API_KEY=userdata.get('API_KEY')\n",
"\n",
Expand Down
6 changes: 3 additions & 3 deletions site/en/gemini-api/tutorials/document_search.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@
"import google.generativeai as genai\n",
"import google.ai.generativelanguage as glm\n",
"\n",
"# Used to securely store your API key\n",
"from google.colab import userdata\n",
"\n",
"from IPython.display import Markdown"
]
},
Expand Down Expand Up @@ -145,6 +142,9 @@
},
"outputs": [],
"source": [
"# Used to securely store your API key\n",
"from google.colab import userdata\n",
"\n",
"# Or use `os.getenv('API_KEY')` to fetch an environment variable.\n",
"API_KEY=userdata.get('API_KEY')\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@
"import google.generativeai as genai\n",
"import google.ai.generativelanguage as glm\n",
"\n",
"# Used to securely store your API key\n",
"from google.colab import userdata\n",
"\n",
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"\n",
Expand Down Expand Up @@ -153,6 +150,8 @@
},
"outputs": [],
"source": [
"# Used to securely store your API key\n",
"from google.colab import userdata\n",
"# Or use `os.getenv('API_KEY')` to fetch an environment variable.\n",
"API_KEY=userdata.get('API_KEY')\n",
"\n",
Expand Down Expand Up @@ -1226,7 +1225,7 @@
"embedding_size = len(df_train['Embeddings'].iloc[0])\n",
"\n",
"# Give your model a different name, as you have already used the variable name 'model'\n",
"classifier = build_classification_model(embedding_size, len(df_train['Class Name'].unique()))\n",
"classifier = build_classification_model([embedding_size], len(df_train['Class Name'].unique()))\n",
"classifier.summary()\n",
"\n",
"classifier.compile(loss = keras.losses.SparseCategoricalCrossentropy(from_logits=True),\n",
Expand Down
Loading
Loading