Spaces:
Running
Running
Update gemini_client.py
Browse files- gemini_client.py +11 -9
gemini_client.py
CHANGED
|
@@ -1,18 +1,20 @@
|
|
| 1 |
import os
|
| 2 |
-
|
| 3 |
|
| 4 |
-
|
| 5 |
-
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
|
| 6 |
-
|
| 7 |
-
# ✅ Use your custom Gemini model
|
| 8 |
-
model = genai.GenerativeModel("gemini-2.0-flash-thinking-exp")
|
| 9 |
|
| 10 |
def ask_gpt(messages):
|
| 11 |
try:
|
| 12 |
prompt = "\n".join(
|
| 13 |
[f"{m['role'].capitalize()}: {m['content']}" for m in messages]
|
| 14 |
)
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
except Exception as e:
|
| 18 |
-
return f"⚠️ Gemini Error: {str(e)}"
|
|
|
|
| 1 |
import os
|
| 2 |
+
from google import genai
|
| 3 |
|
| 4 |
+
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def ask_gpt(messages):
|
| 7 |
try:
|
| 8 |
prompt = "\n".join(
|
| 9 |
[f"{m['role'].capitalize()}: {m['content']}" for m in messages]
|
| 10 |
)
|
| 11 |
+
|
| 12 |
+
response = client.models.generate_content(
|
| 13 |
+
model="gemini-2.5-flash",
|
| 14 |
+
contents=prompt,
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
return (response.text or "").strip()
|
| 18 |
+
|
| 19 |
except Exception as e:
|
| 20 |
+
return f"⚠️ Gemini Error: {str(e)}"
|