Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,15 +15,14 @@ class BasicAgent:
|
|
| 15 |
self.api_key = os.getenv("GEMINI_API_KEY")
|
| 16 |
if not self.api_key:
|
| 17 |
raise ValueError("❌ GEMINI_API_KEY не найден в переменных окружения.")
|
| 18 |
-
self.api_url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent"
|
| 19 |
print("✅ BasicAgent with Gemini API initialized.")
|
| 20 |
|
| 21 |
def __call__(self, question: str) -> str:
|
| 22 |
print(f"🔍 Обрабатывается вопрос: {question[:50]}...")
|
| 23 |
|
| 24 |
headers = {
|
| 25 |
-
"Content-Type": "application/json"
|
| 26 |
-
"Authorization": f"Bearer {self.api_key}",
|
| 27 |
}
|
| 28 |
|
| 29 |
payload = {
|
|
@@ -41,11 +40,13 @@ class BasicAgent:
|
|
| 41 |
response.raise_for_status()
|
| 42 |
result = response.json()
|
| 43 |
reply = result["candidates"][0]["content"]["parts"][0]["text"]
|
| 44 |
-
print(f"✅ Ответ: {reply[:
|
| 45 |
return reply
|
| 46 |
except Exception as e:
|
| 47 |
print(f"⚠️ Ошибка при вызове Gemini API: {e}")
|
|
|
|
| 48 |
return "Ошибка при получении ответа от Gemini."
|
|
|
|
| 49 |
|
| 50 |
|
| 51 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
|
|
| 15 |
self.api_key = os.getenv("GEMINI_API_KEY")
|
| 16 |
if not self.api_key:
|
| 17 |
raise ValueError("❌ GEMINI_API_KEY не найден в переменных окружения.")
|
| 18 |
+
self.api_url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key={self.api_key}"
|
| 19 |
print("✅ BasicAgent with Gemini API initialized.")
|
| 20 |
|
| 21 |
def __call__(self, question: str) -> str:
|
| 22 |
print(f"🔍 Обрабатывается вопрос: {question[:50]}...")
|
| 23 |
|
| 24 |
headers = {
|
| 25 |
+
"Content-Type": "application/json"
|
|
|
|
| 26 |
}
|
| 27 |
|
| 28 |
payload = {
|
|
|
|
| 40 |
response.raise_for_status()
|
| 41 |
result = response.json()
|
| 42 |
reply = result["candidates"][0]["content"]["parts"][0]["text"]
|
| 43 |
+
print(f"✅ Ответ: {reply[:80]}...")
|
| 44 |
return reply
|
| 45 |
except Exception as e:
|
| 46 |
print(f"⚠️ Ошибка при вызове Gemini API: {e}")
|
| 47 |
+
print("Ответ сервера:", response.text if 'response' in locals() else 'нет ответа')
|
| 48 |
return "Ошибка при получении ответа от Gemini."
|
| 49 |
+
|
| 50 |
|
| 51 |
|
| 52 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|