setup-gemini.sh•1.67 kB
#!/bin/bash
# Setup script for Gemini CLI wrapper
# This creates a simple gemini command that uses the Google Generative AI Python SDK
echo "Setting up Gemini CLI wrapper..."
# Check if Python is installed
if ! command -v python3 &> /dev/null; then
echo "Error: Python 3 is not installed"
exit 1
fi
# Install Google Generative AI SDK
echo "Installing google-generativeai package..."
pip3 install google-generativeai
# Create the gemini wrapper script
GEMINI_SCRIPT="/usr/local/bin/gemini"
echo "Creating gemini command wrapper..."
sudo tee "$GEMINI_SCRIPT" > /dev/null <<'EOF'
#!/usr/bin/env python3
import sys
import os
try:
import google.generativeai as genai
except ImportError:
print("Error: google-generativeai package not installed", file=sys.stderr)
print("Install it with: pip3 install google-generativeai", file=sys.stderr)
sys.exit(1)
api_key = os.getenv('GOOGLE_API_KEY')
if not api_key:
print("Error: GOOGLE_API_KEY environment variable not set", file=sys.stderr)
sys.exit(1)
genai.configure(api_key=api_key)
model = genai.GenerativeModel('gemini-pro')
if len(sys.argv) < 2:
print("Usage: gemini 'your prompt here'", file=sys.stderr)
sys.exit(1)
prompt = ' '.join(sys.argv[1:])
try:
response = model.generate_content(prompt)
print(response.text)
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
sys.exit(1)
EOF
# Make it executable
sudo chmod +x "$GEMINI_SCRIPT"
echo "Gemini CLI wrapper installed successfully!"
echo ""
echo "To use it, set your API key:"
echo " export GOOGLE_API_KEY='your-api-key-here'"
echo ""
echo "Test it with:"
echo " gemini 'Hello, how are you?'"