Spaces:
Sleeping
Sleeping
Create gapi_client.py
Browse files- gapi_client.py +16 -0
gapi_client.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from google import genai
|
3 |
+
|
4 |
+
def get_genai_client():
|
5 |
+
"""
|
6 |
+
Initialize and return a Google GenAI client using an API key from the environment.
|
7 |
+
"""
|
8 |
+
api_key = os.getenv("GOOGLE_GENAI_API_KEY")
|
9 |
+
if not api_key:
|
10 |
+
raise ValueError("API key not found. Please set the 'GOOGLE_GENAI_API_KEY' environment variable.")
|
11 |
+
|
12 |
+
try:
|
13 |
+
client = genai.Client(api_key=api_key)
|
14 |
+
return client
|
15 |
+
except Exception as e:
|
16 |
+
raise RuntimeError(f"Failed to initialize Google GenAI client: {e}")
|