Spaces:
Sleeping
Sleeping
Update openai_client.py
Browse files- openai_client.py +13 -14
openai_client.py
CHANGED
|
@@ -1,19 +1,18 @@
|
|
| 1 |
import os
|
| 2 |
import google.generativeai as genai
|
| 3 |
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
if not api_key:
|
| 8 |
-
raise ValueError("Missing GEMINI_API_KEY environment variable")
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
return resp.text
|
|
|
|
| 1 |
import os
|
| 2 |
import google.generativeai as genai
|
| 3 |
|
| 4 |
+
# Configure Gemini client
|
| 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 |
+
response = model.generate_content(prompt)
|
| 16 |
+
return response.text.strip()
|
| 17 |
+
except Exception as e:
|
| 18 |
+
return f"⚠️ Gemini Error: {str(e)}"
|
|
|