Spaces:
Sleeping
Sleeping
fix negative feedback
Browse files- __pycache__/app.cpython-313.pyc +0 -0
- __pycache__/config.cpython-313.pyc +0 -0
- app.py +26 -47
__pycache__/app.cpython-313.pyc
ADDED
|
Binary file (14.5 kB). View file
|
|
|
__pycache__/config.cpython-313.pyc
ADDED
|
Binary file (3.3 kB). View file
|
|
|
app.py
CHANGED
|
@@ -214,8 +214,8 @@ async def on_message(message: cl.Message):
|
|
| 214 |
res = await cl.AskActionMessage(
|
| 215 |
content=f"The query returned {num_rows} rows and {num_cols} columns.\n\nWas this result helpful?",
|
| 216 |
actions=[
|
| 217 |
-
cl.Action(name="
|
| 218 |
-
cl.Action(name="
|
| 219 |
],
|
| 220 |
).send()
|
| 221 |
|
|
@@ -275,71 +275,50 @@ async def on_message(message: cl.Message):
|
|
| 275 |
).send()
|
| 276 |
|
| 277 |
# Callback handlers for actions
|
| 278 |
-
@cl.action_callback("
|
| 279 |
-
async def
|
| 280 |
-
"""Handle feedback
|
| 281 |
-
feedback_value = action.payload.get("value")
|
| 282 |
-
|
| 283 |
client = cl.user_session.get("client")
|
| 284 |
original_query = cl.user_session.get("original_query")
|
| 285 |
generated_sql = cl.user_session.get("generated_sql")
|
| 286 |
optimized_sql = cl.user_session.get("optimized_sql")
|
| 287 |
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
await cl.Message(content="Thanks for your feedback! (Note: There was an issue saving it to the database)", author="SQL Assistant").send()
|
| 302 |
|
| 303 |
-
@cl.action_callback("
|
| 304 |
-
async def
|
| 305 |
"""Handle negative feedback."""
|
| 306 |
# Ask for more detailed feedback
|
| 307 |
-
|
| 308 |
-
content="I'm sorry the results weren't what you expected. Could you please provide more details about what was wrong?",
|
| 309 |
-
author="SQL Assistant",
|
| 310 |
-
timeout=300,
|
| 311 |
-
elements=[
|
| 312 |
-
cl.Textarea(
|
| 313 |
-
id="feedback_details",
|
| 314 |
-
label="Your feedback",
|
| 315 |
-
initial_value="",
|
| 316 |
-
rows=3
|
| 317 |
-
)
|
| 318 |
-
]
|
| 319 |
-
).send()
|
| 320 |
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
feedback_details = f"negative: {res['feedback_details']}"
|
| 324 |
|
| 325 |
client = cl.user_session.get("client")
|
| 326 |
original_query = cl.user_session.get("original_query")
|
| 327 |
generated_sql = cl.user_session.get("generated_sql")
|
| 328 |
optimized_sql = cl.user_session.get("optimized_sql")
|
| 329 |
|
| 330 |
-
# Save
|
| 331 |
-
|
| 332 |
client,
|
| 333 |
original_query,
|
| 334 |
generated_sql,
|
| 335 |
optimized_sql,
|
| 336 |
-
|
| 337 |
)
|
| 338 |
-
|
| 339 |
-
if success:
|
| 340 |
-
await cl.Message(content="Thanks for your detailed feedback! I've saved it to improve future responses.", author="SQL Assistant").send()
|
| 341 |
-
else:
|
| 342 |
-
await cl.Message(content="Thanks for your feedback! (Note: There was an issue saving it to the database)", author="SQL Assistant").send()
|
| 343 |
|
| 344 |
# This is needed for Chainlit to run properly
|
| 345 |
if __name__ == "__main__":
|
|
|
|
| 214 |
res = await cl.AskActionMessage(
|
| 215 |
content=f"The query returned {num_rows} rows and {num_cols} columns.\n\nWas this result helpful?",
|
| 216 |
actions=[
|
| 217 |
+
cl.Action(name="feedback_positive", payload={"value": "positive"}, label="👍 Good results"),
|
| 218 |
+
cl.Action(name="feedback_negative", payload={"value": "negative"}, label="👎 Not what I wanted")
|
| 219 |
],
|
| 220 |
).send()
|
| 221 |
|
|
|
|
| 275 |
).send()
|
| 276 |
|
| 277 |
# Callback handlers for actions
|
| 278 |
+
@cl.action_callback("feedback_positive")
|
| 279 |
+
async def on_feedback_positive(action):
|
| 280 |
+
"""Handle positive feedback."""
|
|
|
|
|
|
|
| 281 |
client = cl.user_session.get("client")
|
| 282 |
original_query = cl.user_session.get("original_query")
|
| 283 |
generated_sql = cl.user_session.get("generated_sql")
|
| 284 |
optimized_sql = cl.user_session.get("optimized_sql")
|
| 285 |
|
| 286 |
+
# Handle positive feedback
|
| 287 |
+
success = save_feedback_to_bigquery(
|
| 288 |
+
client,
|
| 289 |
+
original_query,
|
| 290 |
+
generated_sql,
|
| 291 |
+
optimized_sql,
|
| 292 |
+
"positive"
|
| 293 |
+
)
|
| 294 |
+
|
| 295 |
+
if success:
|
| 296 |
+
await cl.Message(content="Thanks for your positive feedback! I've saved it to improve future responses.", author="SQL Assistant").send()
|
| 297 |
+
else:
|
| 298 |
+
await cl.Message(content="Thanks for your feedback! (Note: There was an issue saving it to the database)", author="SQL Assistant").send()
|
|
|
|
| 299 |
|
| 300 |
+
@cl.action_callback("feedback_negative")
|
| 301 |
+
async def on_feedback_negative(action):
|
| 302 |
"""Handle negative feedback."""
|
| 303 |
# Ask for more detailed feedback
|
| 304 |
+
await cl.Message(content="I'm sorry the results weren't what you expected. Please type your feedback about what was wrong.", author="SQL Assistant").send()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
|
| 306 |
+
# Set flag to indicate we're awaiting detailed feedback
|
| 307 |
+
cl.user_session.set("awaiting_feedback", True)
|
|
|
|
| 308 |
|
| 309 |
client = cl.user_session.get("client")
|
| 310 |
original_query = cl.user_session.get("original_query")
|
| 311 |
generated_sql = cl.user_session.get("generated_sql")
|
| 312 |
optimized_sql = cl.user_session.get("optimized_sql")
|
| 313 |
|
| 314 |
+
# Save initial negative feedback
|
| 315 |
+
save_feedback_to_bigquery(
|
| 316 |
client,
|
| 317 |
original_query,
|
| 318 |
generated_sql,
|
| 319 |
optimized_sql,
|
| 320 |
+
"negative"
|
| 321 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
|
| 323 |
# This is needed for Chainlit to run properly
|
| 324 |
if __name__ == "__main__":
|