SaviAnna commited on
Commit
ec5bf47
·
verified ·
1 Parent(s): e2612e1

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +12 -12
src/streamlit_app.py CHANGED
@@ -87,26 +87,25 @@ async def main():
87
 
88
  if user_input:
89
  st.session_state.messages.append({"role": "user", "content": user_input})
90
-
91
  with st.chat_message("user"):
92
  st.markdown(user_input)
93
-
94
- with st.chat_message("assistant"):
95
 
 
96
  AVAILABLE_SOURCES = list(set(
97
  chunk["file_path"] for chunk in FULL_CHUNKS_DICT.values() if "file_path" in chunk
98
  ))
99
-
100
  explicit_source = None
101
  is_specific = await is_query_about_specific_file(user_input)
102
  if is_specific:
103
  guessed_file = await guess_relevant_file(user_input, AVAILABLE_SOURCES)
104
  if guessed_file and guessed_file != "None":
105
  explicit_source = guessed_file
106
-
107
  matched_sources = []
108
  answer = ""
109
-
110
  if explicit_source:
111
  filtered_chunk_ids = [
112
  chunk_id for chunk_id, chunk in FULL_CHUNKS_DICT.items()
@@ -114,8 +113,9 @@ async def main():
114
  ]
115
  ans_param = QueryParam(mode="mix", top_k=1)
116
  answer = await rag.aquery(user_input, param=ans_param)
117
-
118
  st.markdown(f"🔍 **Focused on:** **{os.path.basename(explicit_source)}**")
 
119
  matched_sources = [
120
  {
121
  "timestamp": chunk.get("timestamp"),
@@ -124,17 +124,17 @@ async def main():
124
  for chunk_id, chunk in FULL_CHUNKS_DICT.items()
125
  if chunk_id in filtered_chunk_ids and "timestamp" in chunk
126
  ]
127
-
128
  else:
129
  ctx_param = QueryParam(mode="mix", only_need_context=True, top_k=3)
130
  context_chunks = await rag.aquery(f"{user_input}\n<!--ctx-->", param=ctx_param)
131
-
132
  ans_param = QueryParam(mode="mix", top_k=3)
133
  answer = await rag.aquery(user_input, param=ans_param)
134
-
135
  dc_chunks = extract_dc_chunks(context_chunks)[:3]
136
  matched_sources = find_matches(dc_chunks, FULL_CHUNKS_DICT)
137
-
138
  # Показываем источники перед ответом
139
  if matched_sources:
140
  sources_md = "#### 📚 Sources:\n" + "\n".join(
@@ -143,7 +143,7 @@ async def main():
143
  )
144
  st.markdown(sources_md)
145
  st.session_state.messages.append({"role": "assistant", "content": sources_md})
146
-
147
  # Показываем ответ
148
  st.markdown(answer)
149
  st.session_state.messages.append({"role": "assistant", "content": answer})
 
87
 
88
  if user_input:
89
  st.session_state.messages.append({"role": "user", "content": user_input})
90
+
91
  with st.chat_message("user"):
92
  st.markdown(user_input)
 
 
93
 
94
+ with st.chat_message("assistant"):
95
  AVAILABLE_SOURCES = list(set(
96
  chunk["file_path"] for chunk in FULL_CHUNKS_DICT.values() if "file_path" in chunk
97
  ))
98
+
99
  explicit_source = None
100
  is_specific = await is_query_about_specific_file(user_input)
101
  if is_specific:
102
  guessed_file = await guess_relevant_file(user_input, AVAILABLE_SOURCES)
103
  if guessed_file and guessed_file != "None":
104
  explicit_source = guessed_file
105
+
106
  matched_sources = []
107
  answer = ""
108
+
109
  if explicit_source:
110
  filtered_chunk_ids = [
111
  chunk_id for chunk_id, chunk in FULL_CHUNKS_DICT.items()
 
113
  ]
114
  ans_param = QueryParam(mode="mix", top_k=1)
115
  answer = await rag.aquery(user_input, param=ans_param)
116
+
117
  st.markdown(f"🔍 **Focused on:** **{os.path.basename(explicit_source)}**")
118
+
119
  matched_sources = [
120
  {
121
  "timestamp": chunk.get("timestamp"),
 
124
  for chunk_id, chunk in FULL_CHUNKS_DICT.items()
125
  if chunk_id in filtered_chunk_ids and "timestamp" in chunk
126
  ]
127
+
128
  else:
129
  ctx_param = QueryParam(mode="mix", only_need_context=True, top_k=3)
130
  context_chunks = await rag.aquery(f"{user_input}\n<!--ctx-->", param=ctx_param)
131
+
132
  ans_param = QueryParam(mode="mix", top_k=3)
133
  answer = await rag.aquery(user_input, param=ans_param)
134
+
135
  dc_chunks = extract_dc_chunks(context_chunks)[:3]
136
  matched_sources = find_matches(dc_chunks, FULL_CHUNKS_DICT)
137
+
138
  # Показываем источники перед ответом
139
  if matched_sources:
140
  sources_md = "#### 📚 Sources:\n" + "\n".join(
 
143
  )
144
  st.markdown(sources_md)
145
  st.session_state.messages.append({"role": "assistant", "content": sources_md})
146
+
147
  # Показываем ответ
148
  st.markdown(answer)
149
  st.session_state.messages.append({"role": "assistant", "content": answer})