benticha commited on
Commit
67624c1
·
verified ·
1 Parent(s): df64ccd

added consulting retrieved docs feature

Browse files
Files changed (1) hide show
  1. app.py +18 -2
app.py CHANGED
@@ -84,7 +84,7 @@ else:
84
  full_response = ""
85
  # Define the basic input structure for the chains
86
  input_dict = {"input": prompt.lower()}
87
-
88
 
89
  with collect_runs() as cb:
90
  for chunk in chain.stream(input_dict, config={"tags": ["SUP'ASSISTANT"]}):
@@ -93,6 +93,22 @@ else:
93
  memory.save_context(input_dict, {"output": full_response})
94
  st.session_state.run_id = cb.traced_runs[0].id
95
  message_placeholder.markdown(full_response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
  with st.spinner("Just a sec! Dont enter prompts while loading pelase!"):
98
  run_id = st.session_state.run_id
@@ -181,4 +197,4 @@ else:
181
  ],
182
  parallel=4,
183
  max_retries=3,
184
- )
 
84
  full_response = ""
85
  # Define the basic input structure for the chains
86
  input_dict = {"input": prompt.lower()}
87
+ used_docs = retriever.get_relevant_documents(prompt.lower())
88
 
89
  with collect_runs() as cb:
90
  for chunk in chain.stream(input_dict, config={"tags": ["SUP'ASSISTANT"]}):
 
93
  memory.save_context(input_dict, {"output": full_response})
94
  st.session_state.run_id = cb.traced_runs[0].id
95
  message_placeholder.markdown(full_response)
96
+ if used_docs :
97
+ docs_content = "\n\n".join(
98
+ [
99
+ f"Doc {i+1}:\n"
100
+ f"Source: {doc.metadata['source']}\n"
101
+ f"Title: {doc.metadata['title']}\n"
102
+ f"Content: {doc.page_content}\n"
103
+ for i, doc in enumerate(used_docs)
104
+ ]
105
+ )
106
+ st.download_button(
107
+ label="Consulted Documents",
108
+ data=docs_content,
109
+ file_name="Consulted_documents.txt",
110
+ mime="text/plain",
111
+ )
112
 
113
  with st.spinner("Just a sec! Dont enter prompts while loading pelase!"):
114
  run_id = st.session_state.run_id
 
197
  ],
198
  parallel=4,
199
  max_retries=3,
200
+ )