From f08710f3af598ea427a54ea6554b6308ed29381e Mon Sep 17 00:00:00 2001 From: Paul Lam Date: Tue, 26 Sep 2023 11:02:43 +0900 Subject: [PATCH 1/2] fix reference section outside of chat area --- mind_palace/app.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/mind_palace/app.py b/mind_palace/app.py index d0c2a43..c84a09c 100644 --- a/mind_palace/app.py +++ b/mind_palace/app.py @@ -1,12 +1,9 @@ -import streamlit as st - -import openai - import extract import index +import openai +import streamlit as st from llama_index.query_engine import CitationQueryEngine - openai.api_key = st.secrets.openai_key xml_dir = "./resources/xmls/12-pdfs-from-steve-aug-22/" @@ -55,8 +52,8 @@ def load_index(model): message = {"role": "assistant", "content": response.response} st.session_state.messages.append(message) # Add response to message history - for i, source_node in enumerate(response.source_nodes): - st.write(f"[{i+1}]") - st.write(f"id: {source_node.node.node_id}") - st.write(f"score: {source_node.score}") - st.write(f"text: {source_node.node.get_text().split(':', 1)[1]}") + for i, source_node in enumerate(response.source_nodes): + st.write(f"[{i+1}]") + st.write(f"id: {source_node.node.node_id}") + st.write(f"score: {source_node.score}") + st.write(f"text: {source_node.node.get_text().split(':', 1)[1]}") From 22d0ba8fbf538fc5750b329538ee694a305e5485 Mon Sep 17 00:00:00 2001 From: Paul Lam Date: Tue, 26 Sep 2023 11:16:14 +0900 Subject: [PATCH 2/2] styled reference section --- mind_palace/app.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mind_palace/app.py b/mind_palace/app.py index c84a09c..ee898d1 100644 --- a/mind_palace/app.py +++ b/mind_palace/app.py @@ -52,8 +52,9 @@ def load_index(model): message = {"role": "assistant", "content": response.response} st.session_state.messages.append(message) # Add response to message history + st.markdown("### Sources") for i, source_node in enumerate(response.source_nodes): - st.write(f"[{i+1}]") - st.write(f"id: {source_node.node.node_id}") - st.write(f"score: {source_node.score}") - st.write(f"text: {source_node.node.get_text().split(':', 1)[1]}") + with st.expander(f"[{i + 1}] {source_node.node.node_id}"): + st.write(f"relevancy score: {source_node.score}") + st.write("original text:") + st.write(source_node.node.get_text().split(":", 1)[1])