#@title API KEY IMPORT
from google.colab import userdata
select_api_key = 'GEMINI_API_KEY / OPENAI_API_KEY' # @param {type: "string"}
try:
TEMP_COLAB_API_KEY=userdata.get(select_api_key)
except userdata.SecretNotFoundError as e:
print(f'''Secret not found\n\nThis expects you to create a secret named {TEMP_COLAB_API_KEY} in Colab\n\nVisit https://makersuite.google.com/app/apikey to create an API key\n\nStore that in the secrets section on the left side of the notebook (key icon)\n\nName the secret {gemini_api_secret_name}''')
raise e
except userdata.NotebookAccessError as e:
print(f'''You need to grant this notebook access to the {TEMP_COLAB_API_KEY} secret in order for the notebook to access Gemini on your behalf.''')
raise e
except Exception as e:
# unknown error
print(f"There was an unknown error. Ensure you have a secret {TEMP_COLAB_API_KEY} stored in Colab and it's a valid key from https://makersuite.google.com/app/apikey")
raise e
_
반응형