Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,8 +31,9 @@ def obtener_extractos(pregunta):
|
|
| 31 |
return [(doc.page_content, doc.metadata.get("url", "URL no disponible")) for doc in docs_relevantes]
|
| 32 |
|
| 33 |
def extract_unique_citations_paragraph(response):
|
| 34 |
-
"""Extrae todas las URL y títulos de un objeto Response."""
|
| 35 |
citations = []
|
|
|
|
| 36 |
|
| 37 |
for item in getattr(response, "output", []):
|
| 38 |
# Solo buscamos en mensajes del asistente
|
|
@@ -41,16 +42,24 @@ def extract_unique_citations_paragraph(response):
|
|
| 41 |
if getattr(block, "type", None) == "output_text":
|
| 42 |
for ann in getattr(block, "annotations", []) or []:
|
| 43 |
if getattr(ann, "type", None) == "url_citation":
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
return citations
|
| 51 |
|
| 52 |
|
| 53 |
|
|
|
|
| 54 |
def respond(message, history: list[tuple[str, str]], domain_table):
|
| 55 |
"""Genera una respuesta basada en el historial y documentos relevantes."""
|
| 56 |
|
|
|
|
| 31 |
return [(doc.page_content, doc.metadata.get("url", "URL no disponible")) for doc in docs_relevantes]
|
| 32 |
|
| 33 |
def extract_unique_citations_paragraph(response):
|
| 34 |
+
"""Extrae todas las URL y títulos únicos de un objeto Response, sin duplicados."""
|
| 35 |
citations = []
|
| 36 |
+
seen = set() # Para evitar duplicados (usaremos la URL como clave única)
|
| 37 |
|
| 38 |
for item in getattr(response, "output", []):
|
| 39 |
# Solo buscamos en mensajes del asistente
|
|
|
|
| 42 |
if getattr(block, "type", None) == "output_text":
|
| 43 |
for ann in getattr(block, "annotations", []) or []:
|
| 44 |
if getattr(ann, "type", None) == "url_citation":
|
| 45 |
+
url = getattr(ann, "url", None)
|
| 46 |
+
title = getattr(ann, "title", None)
|
| 47 |
+
|
| 48 |
+
# Evita duplicados basados en URL
|
| 49 |
+
if url and url not in seen:
|
| 50 |
+
seen.add(url)
|
| 51 |
+
citations.append({
|
| 52 |
+
"title": title,
|
| 53 |
+
"url": url,
|
| 54 |
+
"start": getattr(ann, "start_index", None),
|
| 55 |
+
"end": getattr(ann, "end_index", None)
|
| 56 |
+
})
|
| 57 |
+
|
| 58 |
return citations
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
+
|
| 63 |
def respond(message, history: list[tuple[str, str]], domain_table):
|
| 64 |
"""Genera una respuesta basada en el historial y documentos relevantes."""
|
| 65 |
|