diff --git a/app.py b/app.py
index 49e9904..e161eb3 100644
--- a/app.py
+++ b/app.py
@@ -6,6 +6,7 @@ from chats.streamlit_tools import import_file, clear_cache
from streamlit_extras.add_vertical_space import add_vertical_space
from langchain_tools.pdf_tools import PdfLangChain
from langchain_tools.lc_tools import LangChainTools
+from chats.chat_tools import MessageManager
# App title
@@ -121,12 +122,21 @@ if pdf_name:
input = "\n".join([msg["content"]
for msg in st.session_state.messages])
- query = qa.invoke({"question": f"{input}"},
+ query = qa.invoke({"question": f"{prompt}"},
return_only_outputs=True)
- response = query["answer"]
+ response_text = query["answer"]
+ documents_source = query["source_documents"]
+
+ messageManager = MessageManager()
+
+ citation: str = messageManager.generate_citations(
+ documents_source)
+ # st.markdown(citation)
with st.chat_message("assistant"):
- st.write(response)
+ st.write(response_text)
st.session_state.messages.append(
- {"role": "assistant", "content": response})
+ {"role": "assistant", "content": response_text})
+ expander = st.expander("Fuentes")
+ expander.markdown(citation)
diff --git a/chats/__pycache__/chat_tools.cpython-311.pyc b/chats/__pycache__/chat_tools.cpython-311.pyc
index 896669b..82c7cc3 100644
Binary files a/chats/__pycache__/chat_tools.cpython-311.pyc and b/chats/__pycache__/chat_tools.cpython-311.pyc differ
diff --git a/chats/chat_tools.py b/chats/chat_tools.py
index f1ad8c7..5008f21 100644
--- a/chats/chat_tools.py
+++ b/chats/chat_tools.py
@@ -24,5 +24,17 @@ class MessageManager:
print(f'{ia_emoticon} ' + Style.BRIGHT + Fore.YELLOW +
'IA:' + Style.RESET_ALL + f'{bot_response["answer"]}')
- def generate_citations(self):
- pass
+ def generate_citations(self, documents_source: list) -> str:
+
+ text_source: str = ""
+
+ for index, document in enumerate(documents_source):
+ quote: str = document.page_content
+ source: str = document.metadata['source'].replace(
+ 'documents/pdfs/', '')
+ page: str = document.metadata['page'] + 1
+ fuente: str = f"**Fuente #{index + 1}:** \n '{quote}'\n(*{source}, P.{page})*"
+
+ text_source += fuente + "\n\n\n"
+
+ return text_source
diff --git a/documents/pdfs/1.TC_Malamud, Se está muriendo la democracia.pdf b/documents/pdfs/1.TC_Malamud, Se está muriendo la democracia.pdf
new file mode 100644
index 0000000..6053e3e
--- /dev/null
+++ b/documents/pdfs/1.TC_Malamud, Se está muriendo la democracia.pdf
@@ -0,0 +1,8531 @@
+%PDF-1.7
%
+1 0 obj
<>>>
endobj
2 0 obj
<>stream
+
+
+
+
+ uuid:65972b06-9a32-7b47-96bd-30d13de9fe42
+ adobe:docid:indd:7c45f236-c39b-11de-aeff-914aa68a996b
+ xmp.id:057306da-0aed-4e99-80db-2e38a755ae24
+ proof:pdf
+
+ xmp.iid:1f53c4c0-7644-4b3c-aa09-bce7b7ba62dc
+ adobe:docid:indd:7c45f236-c39b-11de-aeff-914aa68a996b
+ adobe:docid:indd:7c45f236-c39b-11de-aeff-914aa68a996b
+ default
+
+
+
+
+ converted
+ from application/x-indesign to application/pdf
+ Adobe InDesign CC 2017 (Macintosh)
+ /
+ 2019-07-22T12:52:48-03:00
+
+
+
+ 2019-07-22T12:52:48-03:00
+ 2019-07-22T12:52:48-03:00
+ 2019-07-22T12:52:48-03:00
+ Adobe InDesign CC 2017 (Macintosh)
+ application/pdf
+ Adobe PDF Library 15.0
+ False
+
+
+
+ Palatino
+ 11.0
+ 0
+ 0
+ Apple Computer
+ TrueType Collection
+ 1249692586
+ Palatino-Roman
+ 1249692586
+
+
+ Palatino
+ 11.0
+ 0
+ 0
+ Apple Computer
+ TrueType Collection
+ 2953539469
+ Palatino-Bold
+ 2953539469
+
+
+ Palatino
+ 11.0
+ 0
+ 0
+ Apple Computer
+ TrueType Collection
+ 2246150940
+ Palatino-Italic
+ 2246150940
+
+
+ Zapf Dingbats
+ 6.1
+ 0
+ 0
+ Galapagos Design Group
+ TrueType
+ 3734765074
+ ZapfDingbatsITC
+ 3734765074
+
+
+ Helvetica
+ 12.0
+ 0
+ 55796
+ Apple Computer
+ TrueType
+ 1087816235
+ Helvetica-Bold
+ 1087816235
+
+
+ Helvetica Neue
+ 12.0
+ 0
+ 54195
+ Linotype AG
+ TrueType
+ 4122342109
+ HelveticaNeue-Light
+ 4122342109
+
+
+ Helvetica Neue
+ 12.0
+ 0
+ 63794
+ Linotype AG
+ TrueType
+ 1162007284
+ HelveticaNeue-CondensedBold
+ 1162007284
+
+
+ Helvetica Neue
+ 12.0
+ 0
+ 54839
+ Linotype AG
+ TrueType
+ 1815683752
+ HelveticaNeue
+ 1815683752
+
+
+
+
+
+
+
endstream
endobj
5 0 obj
<>
endobj
3 0 obj
<>
endobj
7 0 obj
<>
endobj
8 0 obj
<>
endobj
14 0 obj
<>/ExtGState<>/Font<>/ProcSet[/PDF/Text/ImageC]/XObject<>>>/TrimBox[0.0 0.0 453.543 651.969]/Type/Page>>
endobj
15 0 obj
<>/Font<>/ProcSet[/PDF/Text]/XObject<>>>/TrimBox[0.0 0.0 453.543 651.969]/Type/Page>>
endobj
16 0 obj
<>/Font<>/ProcSet[/PDF/Text]/XObject<>>>/TrimBox[0.0 0.0 453.543 651.969]/Type/Page>>
endobj
17 0 obj
<>/Font<>/ProcSet[/PDF/Text]/XObject<>>>/TrimBox[0.0 0.0 453.543 651.969]/Type/Page>>
endobj
18 0 obj
<>/Font<>/ProcSet[/PDF/Text]/XObject<>>>/TrimBox[0.0 0.0 453.543 651.969]/Type/Page>>
endobj
19 0 obj
<>/Font<>/ProcSet[/PDF/Text]/XObject<>>>/TrimBox[0.0 0.0 453.543 651.969]/Type/Page>>
endobj
20 0 obj
<>/Font<>/ProcSet[/PDF/Text]/XObject<>>>/TrimBox[0.0 0.0 453.543 651.969]/Type/Page>>
endobj
21 0 obj
<>/Font<>/ProcSet[/PDF/Text]/XObject<>>>/TrimBox[0.0 0.0 453.543 651.969]/Type/Page>>
endobj
44 0 obj
<>stream
+HW]oݸ}U݈%JE!`IZYp'H6{_$mu%r8l1p״?zwr6jt{xEqrtLpx|닦
lW0iNmLjFíc[w
ȃ״]73<-mή7:qFgϛog1/fp%7d;w G4=Փ#pqf^4<Z**s'wzAy֏;KIw<ػ] {7B_;!U@uk##x