Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,7 +23,9 @@ def _get_worksheet():
|
|
| 23 |
return gc.open_by_key(SHEET_ID).sheet1 # First worksheet
|
| 24 |
|
| 25 |
# Cache the worksheet object so we don't re-auth every call
|
|
|
|
| 26 |
worksheet = _get_worksheet()
|
|
|
|
| 27 |
|
| 28 |
def log_interaction(question: str, response: str, routing: str, aura: str, latency: float):
|
| 29 |
"""
|
|
@@ -61,11 +63,18 @@ def respond(message: str, history: list | None):
|
|
| 61 |
history=history or [],
|
| 62 |
api_name="/chat",
|
| 63 |
)
|
|
|
|
| 64 |
md1 = md1 or ""
|
| 65 |
md2 = md2 or ""
|
| 66 |
latency = time.perf_counter() - t0
|
| 67 |
# ✅ Log cleanly
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
return chat, md1, md2
|
| 70 |
except Exception as e:
|
| 71 |
chat = (history or []) + [(message, f"⚠️ Backend error: {e}")]
|
|
|
|
| 23 |
return gc.open_by_key(SHEET_ID).sheet1 # First worksheet
|
| 24 |
|
| 25 |
# Cache the worksheet object so we don't re-auth every call
|
| 26 |
+
print("Loading worksheet")
|
| 27 |
worksheet = _get_worksheet()
|
| 28 |
+
print("worksheet loaded")
|
| 29 |
|
| 30 |
def log_interaction(question: str, response: str, routing: str, aura: str, latency: float):
|
| 31 |
"""
|
|
|
|
| 63 |
history=history or [],
|
| 64 |
api_name="/chat",
|
| 65 |
)
|
| 66 |
+
bot_response = chat[-1][1] if chat else ""
|
| 67 |
md1 = md1 or ""
|
| 68 |
md2 = md2 or ""
|
| 69 |
latency = time.perf_counter() - t0
|
| 70 |
# ✅ Log cleanly
|
| 71 |
+
try:
|
| 72 |
+
print("attempting log")
|
| 73 |
+
log_interaction(message, bot_response, md1, md2, latency)
|
| 74 |
+
print("success")
|
| 75 |
+
|
| 76 |
+
except:
|
| 77 |
+
print("Failed to log")
|
| 78 |
return chat, md1, md2
|
| 79 |
except Exception as e:
|
| 80 |
chat = (history or []) + [(message, f"⚠️ Backend error: {e}")]
|