Skip to content

Instantly share code, notes, and snippets.

@feliperyan
Created January 30, 2025 05:18
Show Gist options
  • Save feliperyan/c23e1788b0e2ef19c3c8a024d658530c to your computer and use it in GitHub Desktop.
Save feliperyan/c23e1788b0e2ef19c3c8a024d658530c to your computer and use it in GitHub Desktop.
Minimal example to test service account private key and Vertex Gemini API
import os
import vertexai
from vertexai.generative_models import GenerativeModel
# This will set an environment variable just for this script
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = "<your private key path>"
vertexai.init(project='<your_proj_id>', location='us-central1')
if __name__ == '__main__':
model = GenerativeModel('gemini-1.5-flash-002')
result = model.generate_content("write a haiku about cloud computing")
print(f'GEMINI RESULT:\n{result}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment