Wrong type of credentials for creating tuning model in quickstart

72 views Asked by At

I am trying to set up a tuning model for Palm api.

It requires authorization so I am following the Oauth quick start

I have configured the consent screen and created the desktop app credetials as stated in the guilde.

Click Application type > Desktop app.

{
  "installed": {
    "client_id": "[REDACTED].googleusercontent.com",
    "project_id": "[REDACTED]",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "[REDACTED]",
    "redirect_uris": [
      "http://localhost"
    ]
  }
}

When I run the code found in tuning QuickStart python

import google.generativeai as palm
import os

os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'C:\Development\FreeLance\machineLearning\GaTraining\creds.json'

def check_for_existing_tuned_models():
    print('Available base models:', [m.name for m in palm.list_models()])


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    check_for_existing_tuned_models()

I get the following error.

The file C:\Development\FreeLance\machineLearning\GaTraining\creds.json does not have a valid type. Type is None, expected one of ('authorized_user', 'service_account', 'external_account', 'external_account_authorized_user', 'impersonated_service_account', 'gdch_service_account').

Which implies to me that it requires a service account authorization which is completely opposite of what the tutorial says i should use.

How do I authorize to palm api to create my own tuning model?

Note:

Creating a service account does work. I just dont understand why the tutorial says to use Oauth2 and configure the consent screen. Which one should i use a service account or oauth2.

1

There are 1 answers

3
Mark McDonald On

In the tutorial you linked, it uses gcloud to convert the downloaded token to usable credentials. It looks like you have skipped that step here.

Check out the oauth guide for the way to do this manually, using Credentials.from_authorized_user_file('token.json', SCOPES).