Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -162,30 +162,41 @@ def delete_record(container, name, id):
|
|
162 |
except Exception as e:
|
163 |
return False, f"An unexpected error occurred: {traceback.format_exc()} 😱"
|
164 |
|
|
|
|
|
|
|
|
|
|
|
165 |
def save_to_cosmos_db(container, query, response1, response2):
|
166 |
try:
|
167 |
if container:
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
else:
|
183 |
st.error("Cosmos DB container is not initialized.")
|
|
|
|
|
184 |
except Exception as e:
|
185 |
st.error(f"An unexpected error occurred: {str(e)}")
|
186 |
|
187 |
-
|
188 |
-
|
189 |
# Add dropdowns for model and database choices
|
190 |
def search_glossary(query):
|
191 |
st.markdown(f"### 🔍 Search Glossary for: `{query}`")
|
|
|
162 |
except Exception as e:
|
163 |
return False, f"An unexpected error occurred: {traceback.format_exc()} 😱"
|
164 |
|
165 |
+
import uuid
|
166 |
+
|
167 |
+
def generate_unique_id():
|
168 |
+
return str(uuid.uuid4())
|
169 |
+
|
170 |
def save_to_cosmos_db(container, query, response1, response2):
|
171 |
try:
|
172 |
if container:
|
173 |
+
max_retries = 3
|
174 |
+
for attempt in range(max_retries):
|
175 |
+
try:
|
176 |
+
record = {
|
177 |
+
"id": generate_unique_id(),
|
178 |
+
"query": query,
|
179 |
+
"response1": response1,
|
180 |
+
"response2": response2,
|
181 |
+
"timestamp": datetime.utcnow().isoformat()
|
182 |
+
}
|
183 |
+
container.upsert_item(body=record)
|
184 |
+
st.success(f"Record saved successfully with ID: {record['id']}")
|
185 |
+
st.session_state.documents = get_documents(container)
|
186 |
+
break
|
187 |
+
except exceptions.CosmosHttpResponseError as e:
|
188 |
+
if e.status_code == 409 and attempt < max_retries - 1: # Conflict error
|
189 |
+
st.warning(f"ID conflict occurred. Retrying... (Attempt {attempt + 1})")
|
190 |
+
continue
|
191 |
+
else:
|
192 |
+
raise
|
193 |
else:
|
194 |
st.error("Cosmos DB container is not initialized.")
|
195 |
+
except exceptions.CosmosHttpResponseError as e:
|
196 |
+
st.error(f"Error saving record to Cosmos DB: {e}")
|
197 |
except Exception as e:
|
198 |
st.error(f"An unexpected error occurred: {str(e)}")
|
199 |
|
|
|
|
|
200 |
# Add dropdowns for model and database choices
|
201 |
def search_glossary(query):
|
202 |
st.markdown(f"### 🔍 Search Glossary for: `{query}`")
|