Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -108,101 +108,39 @@ Just type your question or start a conversation, and I'll do my best to help you
|
|
| 108 |
return random.choice(responses)
|
| 109 |
|
| 110 |
def save_unanswered_question(self, question: str) -> bool:
|
| 111 |
-
"""Save unanswered question to the database
|
| 112 |
print(f"Attempting to save unanswered question: '{question}'")
|
| 113 |
|
| 114 |
try:
|
| 115 |
-
#
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
f"{self.database_url}/api/unanswered_questions",
|
| 119 |
-
f"{self.database_url}/save_question",
|
| 120 |
-
f"{self.database_url}/api/save_question",
|
| 121 |
-
f"{self.database_url}/questions",
|
| 122 |
-
f"{self.database_url}/api/questions",
|
| 123 |
-
f"{self.database_url}/faq/unanswered",
|
| 124 |
-
f"{self.database_url}/api/faq/unanswered"
|
| 125 |
-
]
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
}
|
| 139 |
-
print(f"POST data: {post_data}")
|
| 140 |
-
|
| 141 |
-
response = requests.post(
|
| 142 |
-
endpoint,
|
| 143 |
-
json=post_data,
|
| 144 |
-
headers={"Content-Type": "application/json"},
|
| 145 |
-
timeout=10
|
| 146 |
-
)
|
| 147 |
-
print(f"POST response status: {response.status_code}")
|
| 148 |
-
print(f"POST response text: {response.text[:200]}")
|
| 149 |
-
|
| 150 |
-
if response.status_code in [200, 201]:
|
| 151 |
-
print(f"Successfully saved question via POST to {endpoint}")
|
| 152 |
-
return True
|
| 153 |
-
|
| 154 |
-
except requests.exceptions.RequestException as e:
|
| 155 |
-
print(f"POST request failed for {endpoint}: {e}")
|
| 156 |
-
|
| 157 |
-
# Try GET request with query parameters
|
| 158 |
-
try:
|
| 159 |
-
get_params = {
|
| 160 |
-
"question": question,
|
| 161 |
-
"created_at": timestamp
|
| 162 |
-
}
|
| 163 |
-
print(f"GET params: {get_params}")
|
| 164 |
-
|
| 165 |
-
response = requests.get(
|
| 166 |
-
endpoint,
|
| 167 |
-
params=get_params,
|
| 168 |
-
timeout=10
|
| 169 |
-
)
|
| 170 |
-
print(f"GET response status: {response.status_code}")
|
| 171 |
-
print(f"GET response text: {response.text[:200]}")
|
| 172 |
-
|
| 173 |
-
if response.status_code in [200, 201]:
|
| 174 |
-
print(f"Successfully saved question via GET to {endpoint}")
|
| 175 |
-
return True
|
| 176 |
-
|
| 177 |
-
except requests.exceptions.RequestException as e:
|
| 178 |
-
print(f"GET request failed for {endpoint}: {e}")
|
| 179 |
-
|
| 180 |
-
# Try POST with form data
|
| 181 |
-
try:
|
| 182 |
-
form_data = {
|
| 183 |
-
"question": question,
|
| 184 |
-
"created_at": timestamp
|
| 185 |
-
}
|
| 186 |
-
print(f"Form data: {form_data}")
|
| 187 |
-
|
| 188 |
-
response = requests.post(
|
| 189 |
-
endpoint,
|
| 190 |
-
data=form_data,
|
| 191 |
-
timeout=10
|
| 192 |
-
)
|
| 193 |
-
print(f"Form POST response status: {response.status_code}")
|
| 194 |
-
print(f"Form POST response text: {response.text[:200]}")
|
| 195 |
-
|
| 196 |
-
if response.status_code in [200, 201]:
|
| 197 |
-
print(f"Successfully saved question via form POST to {endpoint}")
|
| 198 |
-
return True
|
| 199 |
-
|
| 200 |
-
except requests.exceptions.RequestException as e:
|
| 201 |
-
print(f"Form POST request failed for {endpoint}: {e}")
|
| 202 |
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
return False
|
| 205 |
-
|
| 206 |
except Exception as e:
|
| 207 |
print(f"Unexpected error saving unanswered question: {e}")
|
| 208 |
return False
|
|
|
|
| 108 |
return random.choice(responses)
|
| 109 |
|
| 110 |
def save_unanswered_question(self, question: str) -> bool:
|
| 111 |
+
"""Save unanswered question to the database - matches your exact API"""
|
| 112 |
print(f"Attempting to save unanswered question: '{question}'")
|
| 113 |
|
| 114 |
try:
|
| 115 |
+
# Use only the correct endpoint that matches your server
|
| 116 |
+
endpoint = f"{self.database_url}/unanswered_questions"
|
| 117 |
+
print(f"Using endpoint: {endpoint}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
+
# Send POST request with only question (matching your server code)
|
| 120 |
+
post_data = {
|
| 121 |
+
"question": question
|
| 122 |
+
}
|
| 123 |
+
print(f"POST data: {post_data}")
|
| 124 |
|
| 125 |
+
response = requests.post(
|
| 126 |
+
endpoint,
|
| 127 |
+
json=post_data,
|
| 128 |
+
headers={"Content-Type": "application/json"},
|
| 129 |
+
timeout=10
|
| 130 |
+
)
|
| 131 |
+
print(f"POST response status: {response.status_code}")
|
| 132 |
+
print(f"POST response text: {response.text}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
+
if response.status_code == 200:
|
| 135 |
+
print(f"Successfully saved question to {endpoint}")
|
| 136 |
+
return True
|
| 137 |
+
else:
|
| 138 |
+
print(f"Failed to save question. Status: {response.status_code}, Response: {response.text}")
|
| 139 |
+
return False
|
| 140 |
+
|
| 141 |
+
except requests.exceptions.RequestException as e:
|
| 142 |
+
print(f"Request failed: {e}")
|
| 143 |
return False
|
|
|
|
| 144 |
except Exception as e:
|
| 145 |
print(f"Unexpected error saving unanswered question: {e}")
|
| 146 |
return False
|