seansullivan commited on
Commit
7430d16
·
verified ·
1 Parent(s): f09daf4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -112,12 +112,13 @@ def generate_response(prompt):
112
  st.session_state['generated'].append(start)
113
  yield start
114
 
 
115
  for chunk in rag_chain_with_source.stream(prompt):
116
-
117
  if list(chunk.keys())[0] == 'answer':
118
  st.session_state['generated'][-1] += chunk['answer']
119
  yield chunk['answer']
120
-
121
  elif list(chunk.keys())[0] == 'context':
122
  pass
123
  # Sources DO NOT work the same with this code... removing for now.
@@ -126,11 +127,9 @@ def generate_response(prompt):
126
  print()
127
  print(thing.metadata)
128
  sources = [doc.metadata['source'] for doc in chunk['context']]
129
-
130
- response = rag_chain_with_source.invoke(prompt)
131
- answer = response["answer"]
132
- formatted_response = f"Answer: {answer}\n\nSources:\n" + "\n".join(sources)
133
- yield formatted_response
134
 
135
  # question = "How can I do hybrid search with a pinecone database?"
136
  # answer = generate_response(question)
 
112
  st.session_state['generated'].append(start)
113
  yield start
114
 
115
+ all_sources = []
116
  for chunk in rag_chain_with_source.stream(prompt):
117
+
118
  if list(chunk.keys())[0] == 'answer':
119
  st.session_state['generated'][-1] += chunk['answer']
120
  yield chunk['answer']
121
+
122
  elif list(chunk.keys())[0] == 'context':
123
  pass
124
  # Sources DO NOT work the same with this code... removing for now.
 
127
  print()
128
  print(thing.metadata)
129
  sources = [doc.metadata['source'] for doc in chunk['context']]
130
+ all_sources.extend(sources)
131
+
132
+ formatted_response = f"Sources:\n" + "\n".join(all_sources)
 
 
133
 
134
  # question = "How can I do hybrid search with a pinecone database?"
135
  # answer = generate_response(question)