-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenable_gemini_models.py
More file actions
84 lines (68 loc) · 2.64 KB
/
Copy pathenable_gemini_models.py
File metadata and controls
84 lines (68 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""Enable and test Gemini models for the project."""
import subprocess
import json
import sys
print("Checking Vertex AI Gemini model access...")
print("=" * 60)
project_id = "semgrep-472018"
# Check if Generative AI API is enabled
print("\n1. Checking Generative AI APIs...")
apis_to_check = [
"aiplatform.googleapis.com",
"generativelanguage.googleapis.com",
"ml.googleapis.com"
]
for api in apis_to_check:
try:
result = subprocess.run(
["gcloud", "services", "list", "--enabled", f"--filter=name:{api}",
f"--project={project_id}", "--format=value(name)"],
capture_output=True,
text=True
)
if api in result.stdout:
print(f" ✅ {api} is enabled")
else:
print(f" ❌ {api} is NOT enabled")
except Exception as e:
print(f" ❌ Error checking {api}: {e}")
# Check Vertex AI model endpoints
print("\n2. Checking Vertex AI endpoints...")
print(" Note: Gemini models are accessed as foundation models, not custom models")
# Check if we can access Gemini through the generativelanguage API
print("\n3. Testing Gemini access through Google AI...")
try:
import google.generativeai as genai
# Try to configure with an API key (if available)
# Note: This requires a Generative Language API key
print(" ⚠️ Google AI Studio access requires an API key")
print(" Visit: https://makersuite.google.com/app/apikey")
except ImportError:
print(" ⚠️ google-generativeai package not installed")
# Solution for BigQuery ML.GENERATE_TEXT
print("\n" + "=" * 60)
print("📌 SOLUTION: ML.GENERATE_TEXT in BigQuery")
print("=" * 60)
print("""
Current Status:
- Gemini models cannot be directly created as BigQuery remote models
- This is a known limitation in the current BigQuery ML implementation
Workarounds:
1. Use Vertex AI Python SDK directly (recommended):
```python
import vertexai
from vertexai.generative_models import GenerativeModel
vertexai.init(project='semgrep-472018', location='us-central1')
model = GenerativeModel('gemini-1.5-flash')
response = model.generate_content('Your prompt here')
```
2. For BigQuery integration, use embedding models (already working):
- text_embedding_model is configured and functional
- Use for semantic search and similarity matching
3. Alternative: Set up Cloud Functions as a bridge:
- Create a Cloud Function that calls Vertex AI
- Create a BigQuery remote function that calls the Cloud Function
- This allows SQL-based text generation
The embedding functionality is fully operational and sufficient for
semantic search use cases in grepctl.
""")