Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -192,10 +192,9 @@ def get_documents(container, limit=None):
|
|
192 |
items = list(container.query_items(query=query, enable_cross_partition_query=True, max_item_count=limit))
|
193 |
return items
|
194 |
|
195 |
-
def save_to_cosmos_db(query, response1, response2):
|
196 |
try:
|
197 |
-
|
198 |
-
if cosmos_container:
|
199 |
record = {
|
200 |
"id": generate_unique_id(),
|
201 |
"query": query,
|
@@ -203,20 +202,17 @@ def save_to_cosmos_db(query, response1, response2):
|
|
203 |
"response2": response2
|
204 |
}
|
205 |
try:
|
206 |
-
|
207 |
st.success(f"Record saved successfully with ID: {record['id']}")
|
208 |
# Refresh the documents display
|
209 |
-
st.session_state.documents = get_documents(
|
210 |
except exceptions.CosmosHttpResponseError as e:
|
211 |
st.error(f"Error saving record to Cosmos DB: {e}")
|
212 |
else:
|
213 |
-
st.error("Cosmos DB is not initialized.")
|
214 |
except Exception as e:
|
215 |
st.error(f"An unexpected error occurred: {str(e)}")
|
216 |
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
# Add dropdowns for model and database choices
|
221 |
def search_glossary(query):
|
222 |
st.markdown(f"### π Search Glossary for: `{query}`")
|
@@ -253,7 +249,6 @@ def search_glossary(query):
|
|
253 |
)
|
254 |
st.markdown(result)
|
255 |
st.code(result, language="python", line_numbers=True)
|
256 |
-
save_to_cosmos_db(query, result, result) # Save both responses to Cosmos DB
|
257 |
|
258 |
# π ArXiv RAG researcher expert ~-<>-~ Paper Summary & Ask LLM - api_name: /ask_llm
|
259 |
result2 = client.predict(
|
@@ -264,7 +259,6 @@ def search_glossary(query):
|
|
264 |
)
|
265 |
st.markdown(result2)
|
266 |
st.code(result2, language="python", line_numbers=True)
|
267 |
-
save_to_cosmos_db(query, result2, result2) # Save both responses to Cosmos DB
|
268 |
|
269 |
# π ArXiv RAG researcher expert ~-<>-~ Paper Summary & Ask LLM - api_name: /ask_llm
|
270 |
result3 = client.predict(
|
@@ -275,7 +269,6 @@ def search_glossary(query):
|
|
275 |
)
|
276 |
st.markdown(result3)
|
277 |
st.code(result3, language="python", line_numbers=True)
|
278 |
-
save_to_cosmos_db(query, result3, result3) # Save both responses to Cosmos DB
|
279 |
|
280 |
|
281 |
# π ArXiv RAG researcher expert ~-<>-~ Paper Summary & Ask LLM - api_name: /update_with_rag_md
|
@@ -289,12 +282,16 @@ def search_glossary(query):
|
|
289 |
|
290 |
st.markdown(response2[0])
|
291 |
st.code(response2[0], language="python", line_numbers=True, wrap_lines=True)
|
292 |
-
save_to_cosmos_db(query, response2[0], response2[0]) # Save both responses to Cosmos DB
|
293 |
|
294 |
st.markdown(response2[1])
|
295 |
st.code(response2[1], language="python", line_numbers=True, wrap_lines=True)
|
296 |
-
|
297 |
-
|
|
|
|
|
|
|
|
|
|
|
298 |
|
299 |
# Aggregate hyperlinks and show with emojis
|
300 |
hyperlinks = extract_hyperlinks([response1, response2])
|
|
|
192 |
items = list(container.query_items(query=query, enable_cross_partition_query=True, max_item_count=limit))
|
193 |
return items
|
194 |
|
195 |
+
def save_to_cosmos_db(container, query, response1, response2):
|
196 |
try:
|
197 |
+
if container:
|
|
|
198 |
record = {
|
199 |
"id": generate_unique_id(),
|
200 |
"query": query,
|
|
|
202 |
"response2": response2
|
203 |
}
|
204 |
try:
|
205 |
+
container.create_item(body=record)
|
206 |
st.success(f"Record saved successfully with ID: {record['id']}")
|
207 |
# Refresh the documents display
|
208 |
+
st.session_state.documents = get_documents(container)
|
209 |
except exceptions.CosmosHttpResponseError as e:
|
210 |
st.error(f"Error saving record to Cosmos DB: {e}")
|
211 |
else:
|
212 |
+
st.error("Cosmos DB container is not initialized.")
|
213 |
except Exception as e:
|
214 |
st.error(f"An unexpected error occurred: {str(e)}")
|
215 |
|
|
|
|
|
|
|
216 |
# Add dropdowns for model and database choices
|
217 |
def search_glossary(query):
|
218 |
st.markdown(f"### π Search Glossary for: `{query}`")
|
|
|
249 |
)
|
250 |
st.markdown(result)
|
251 |
st.code(result, language="python", line_numbers=True)
|
|
|
252 |
|
253 |
# π ArXiv RAG researcher expert ~-<>-~ Paper Summary & Ask LLM - api_name: /ask_llm
|
254 |
result2 = client.predict(
|
|
|
259 |
)
|
260 |
st.markdown(result2)
|
261 |
st.code(result2, language="python", line_numbers=True)
|
|
|
262 |
|
263 |
# π ArXiv RAG researcher expert ~-<>-~ Paper Summary & Ask LLM - api_name: /ask_llm
|
264 |
result3 = client.predict(
|
|
|
269 |
)
|
270 |
st.markdown(result3)
|
271 |
st.code(result3, language="python", line_numbers=True)
|
|
|
272 |
|
273 |
|
274 |
# π ArXiv RAG researcher expert ~-<>-~ Paper Summary & Ask LLM - api_name: /update_with_rag_md
|
|
|
282 |
|
283 |
st.markdown(response2[0])
|
284 |
st.code(response2[0], language="python", line_numbers=True, wrap_lines=True)
|
|
|
285 |
|
286 |
st.markdown(response2[1])
|
287 |
st.code(response2[1], language="python", line_numbers=True, wrap_lines=True)
|
288 |
+
|
289 |
+
# When saving results, pass the container
|
290 |
+
save_to_cosmos_db(st.session_state.cosmos_container, query, result, result)
|
291 |
+
save_to_cosmos_db(st.session_state.cosmos_container, query, result2, result2)
|
292 |
+
save_to_cosmos_db(st.session_state.cosmos_container, query, result3, result3)
|
293 |
+
save_to_cosmos_db(st.session_state.cosmos_container, query, response2[0], response2[0])
|
294 |
+
save_to_cosmos_db(st.session_state.cosmos_container, query, response2[1], response2[1])
|
295 |
|
296 |
# Aggregate hyperlinks and show with emojis
|
297 |
hyperlinks = extract_hyperlinks([response1, response2])
|