Skip to content

Commit

Permalink
Remove oauth from tuning notebook (#311)
Browse files Browse the repository at this point in the history
* Remove oauth from tuning notebook

* Add standard colab-secret-usage message
  • Loading branch information
MarkDaoust authored Oct 25, 2024
1 parent 1860ff2 commit 21c5ca0
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions quickstarts/Tuning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -82,62 +82,53 @@
{
"cell_type": "markdown",
"metadata": {
"id": "SWxKvwd-MSIV"
"id": "41fbd6a3290a"
},
"source": [
"## OAuth Authentication"
"## Setup"
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "JjS8Zy1ojIgc"
"id": "cbcf72bcb56d"
},
"outputs": [],
"source": [
"Unlike the other quickstarts which use API keys, model tuning uses OAuth.\n",
"\n",
"This tutorial assumes you have completed the [OAuth Quickstart](https://github.com/google-gemini/cookbook/blob/main/quickstarts/Authentication_with_OAuth.ipynb) and you have your client secret saved as `CLIENT_SECRET` in the Colab secrets manager.\n",
"\n",
"> Important: **Don't just click the link this command prints**. That will fail. Follow the instructions and copy the `gcloud` command it prints to your local machine and run it there, then paste the output from your local machine back\n",
"here."
"!pip install -q -U \"google-generativeai>=0.7.2\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "9FUwyB_MJ0-2"
"id": "8enrppafJPCX"
},
"outputs": [],
"source": [
"from google.colab import userdata\n",
"import pathlib\n",
"pathlib.Path('client_secret.json').write_text(userdata.get('CLIENT_SECRET'))\n",
"\n",
"# Use `--no-browser` in colab\n",
"!gcloud auth application-default login --no-browser --client-id-file client_secret.json --scopes='https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/generative-language.tuning'"
"import google.generativeai as genai"
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {
"id": "cbcf72bcb56d"
"id": "41fbd6a3290a"
},
"outputs": [],
"source": [
"!pip install -q -U \"google-generativeai>=0.7.2\""
"To run the following cell, your API key must be stored it in a Colab Secret named `GOOGLE_API_KEY`. If you don't already have an API key, or you're not sure how to create a Colab Secret, see the [Authentication](https://github.com/google-gemini/cookbook/blob/main/quickstarts/Authentication.ipynb) quickstart for an example."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "8enrppafJPCX"
"id": "dc09b1db88b7"
},
"outputs": [],
"source": [
"import google.generativeai as genai"
"from google.colab import userdata\n",
"genai.configure(api_key=userdata.get('GOOGLE_API_KEY'))"
]
},
{
Expand Down

0 comments on commit 21c5ca0

Please sign in to comment.