camparchimedes commited on
Commit
8a72047
ยท
verified ยท
1 Parent(s): a4a183e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -18
app.py CHANGED
@@ -91,14 +91,13 @@ async def main(message):
91
  answer = res["result"]
92
  source_elements = []
93
  visited_sources = set()
94
- return
95
 
96
  # --documents, user session
97
  docs = res["source_documents"]
98
  metadatas = [doc.metadata for doc in docs]
99
  all_sources = [m["source"] for m in metadatas]
100
-
101
-
102
  """
103
  for source in all_sources:
104
  if source in visited_sources:
@@ -118,21 +117,20 @@ async def main(message):
118
  await cl.Message(content=answer, elements=source_elements).send()
119
 
120
  """
121
- for doc, metadata in zip(docs, metadatas):
122
- row_index = metadata.get("row_index", -1) # --when row_index@metadata
123
- if row_index in [2, 8, 14]: # --incl. only rows 2, 8, and 14
124
- source = metadata.get("source", "")
125
- if source and source not in visited_sources:
126
- visited_sources.add(source)
127
-
128
- source_elements.append(
129
- cl.Text(content="https://www.daysoff.no" + source, name="Info_Url")
130
- )
131
-
132
- if source_elements:
133
- answer += f"\nSources: {', '.join([e.content for e in source_elements])}"
134
- else:
135
- answer += "\nNo sources found"
136
 
137
  await cl.Message(content=answer, elements=source_elements).send()
138
 
 
91
  answer = res["result"]
92
  source_elements = []
93
  visited_sources = set()
94
+ #return
95
 
96
  # --documents, user session
97
  docs = res["source_documents"]
98
  metadatas = [doc.metadata for doc in docs]
99
  all_sources = [m["source"] for m in metadatas]
100
+
 
101
  """
102
  for source in all_sources:
103
  if source in visited_sources:
 
117
  await cl.Message(content=answer, elements=source_elements).send()
118
 
119
  """
120
+ for doc, metadata in zip(docs, metadatas):
121
+ row_index = metadata.get("row_index", -1) # --when row_index@metadata
122
+ if row_index in [2, 8, 14]: # --incl. only rows 2, 8, and 14
123
+ source = metadata.get("source", "")
124
+ if source and source not in visited_sources:
125
+ visited_sources.add(source)
126
+ source_elements.append(
127
+ cl.Text(content="https://www.daysoff.no" + source, name="Info_Url")
128
+ )
129
+
130
+ if source_elements:
131
+ answer += f"\nSources: {', '.join([e.content for e in source_elements])}"
132
+ else:
133
+ answer += "\nNo sources found"
 
134
 
135
  await cl.Message(content=answer, elements=source_elements).send()
136