Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,18 +22,23 @@ def respond(
|
|
| 22 |
temperature,
|
| 23 |
top_p,
|
| 24 |
):
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
messages = [{"role": "system", "content": system_message}]
|
| 38 |
|
| 39 |
for val in history:
|
|
|
|
| 22 |
temperature,
|
| 23 |
top_p,
|
| 24 |
):
|
| 25 |
+
# Attempt to find a response in the dataset
|
| 26 |
+
try:
|
| 27 |
+
closest_match = None
|
| 28 |
+
for entry in dataset:
|
| 29 |
+
if message.lower() in entry["question"].lower(): # Adjust based on actual column names
|
| 30 |
+
closest_match = entry["answer"] # Adjust based on actual column names
|
| 31 |
+
break
|
| 32 |
|
| 33 |
+
# If a match is found, return the dataset answer
|
| 34 |
+
if closest_match:
|
| 35 |
+
return closest_match
|
| 36 |
|
| 37 |
+
except Exception as e:
|
| 38 |
+
# Log errors during dataset querying
|
| 39 |
+
print(f"Dataset Query Error: {e}")
|
| 40 |
+
|
| 41 |
+
# If no match is found, or there's an error, fall back to chatbot model
|
| 42 |
messages = [{"role": "system", "content": system_message}]
|
| 43 |
|
| 44 |
for val in history:
|