Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -83,24 +83,30 @@ class GeminiModelAdapter:
|
|
| 83 |
def generate(self, *args, **kwargs):
|
| 84 |
kwargs.pop('stop_sequences', None) # Remove unsupported argument for Gemini
|
| 85 |
result = self.model.generate_content(*args, **kwargs)
|
| 86 |
-
|
|
|
|
| 87 |
if hasattr(result, "text"):
|
| 88 |
-
print(f"[DEBUG] Gemini
|
| 89 |
return result.text
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
try:
|
| 96 |
text = result.candidates[0].content.parts[0].text
|
| 97 |
-
print(f"[DEBUG] Gemini
|
| 98 |
return text
|
| 99 |
-
except Exception:
|
| 100 |
-
|
| 101 |
-
# Fallback:
|
| 102 |
-
|
| 103 |
-
return str(result)
|
| 104 |
|
| 105 |
# --- Basic Agent Definition ---
|
| 106 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
|
|
|
| 83 |
def generate(self, *args, **kwargs):
|
| 84 |
kwargs.pop('stop_sequences', None) # Remove unsupported argument for Gemini
|
| 85 |
result = self.model.generate_content(*args, **kwargs)
|
| 86 |
+
print(f"[DEBUG] Gemini raw result type: {type(result)}; value: {result}")
|
| 87 |
+
# Try all known ways to extract text
|
| 88 |
if hasattr(result, "text"):
|
| 89 |
+
print(f"[DEBUG] Gemini .text: {result.text}")
|
| 90 |
return result.text
|
| 91 |
+
if hasattr(result, "content"):
|
| 92 |
+
content = getattr(result, "content")
|
| 93 |
+
if isinstance(content, str):
|
| 94 |
+
print(f"[DEBUG] Gemini .content (str): {content}")
|
| 95 |
+
return content
|
| 96 |
+
if hasattr(content, "parts"):
|
| 97 |
+
parts = getattr(content, "parts")
|
| 98 |
+
if parts and hasattr(parts[0], "text"):
|
| 99 |
+
print(f"[DEBUG] Gemini .content.parts[0].text: {parts[0].text}")
|
| 100 |
+
return parts[0].text
|
| 101 |
+
if hasattr(result, "candidates") and result.candidates:
|
| 102 |
try:
|
| 103 |
text = result.candidates[0].content.parts[0].text
|
| 104 |
+
print(f"[DEBUG] Gemini .candidates[0].content.parts[0].text: {text}")
|
| 105 |
return text
|
| 106 |
+
except Exception as e:
|
| 107 |
+
print(f"[DEBUG] Gemini .candidates extraction failed: {e}")
|
| 108 |
+
# Fallback: raise error for debugging
|
| 109 |
+
raise TypeError(f"GeminiModelAdapter.generate() could not extract text from result of type {type(result)}: {result}")
|
|
|
|
| 110 |
|
| 111 |
# --- Basic Agent Definition ---
|
| 112 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|