Spaces:
Sleeping
Sleeping
Update openai_client.py
Browse files- openai_client.py +14 -13
openai_client.py
CHANGED
|
@@ -1,17 +1,18 @@
|
|
| 1 |
import os
|
| 2 |
-
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
model = genai.GenerativeModel("gemini-pro") # no "models/" prefix needed
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
return f"⚠️ Gemini Error: {str(e)}"
|
|
|
|
| 1 |
import os
|
| 2 |
+
from google import genai
|
| 3 |
|
| 4 |
+
# Initialize Gemini client using the correct environment variable
|
| 5 |
+
api_key = os.getenv("GEMINI_API_KEY")
|
| 6 |
+
if not api_key:
|
| 7 |
+
raise ValueError("Missing GEMINI_API_KEY environment variable")
|
| 8 |
|
| 9 |
+
client = genai.Client(api_key=api_key)
|
|
|
|
| 10 |
|
| 11 |
+
# Default model (same as used in the full system)
|
| 12 |
+
model_name = "gemini-2.0-flash-thinking-exp"
|
| 13 |
+
|
| 14 |
+
def ask_gpt(messages: list[dict]) -> str:
|
| 15 |
+
prompt_parts = "\n".join([msg["content"] for msg in messages])
|
| 16 |
+
chat = client.chats.create(model=model_name)
|
| 17 |
+
resp = chat.send_message(prompt_parts)
|
| 18 |
+
return resp.text
|
|
|