gufett0 commited on
Commit
66eb39c
·
1 Parent(s): ed556da

print only assitant

Browse files
Files changed (1) hide show
  1. backend.py +7 -8
backend.py CHANGED
@@ -165,13 +165,15 @@ def handle_query(query_str: str,
165
  ),
166
  )
167
 
 
 
168
  # Let's test it out
169
- """relevant_chunks = chat_engine.retrieve("mercato")
170
  print(f"Found: {len(relevant_chunks)} relevant chunks")
171
  for idx, chunk in enumerate(relevant_chunks):
172
  info_message += f"{idx + 1}) {chunk.text[:64]}...\n"
173
  print(info_message)
174
- gr.Info(info_message)"""
175
 
176
 
177
  #prompts_dict = chat_engine.get_prompts()
@@ -187,13 +189,10 @@ def handle_query(query_str: str,
187
  #response = chat_engine.chat(query_str)
188
 
189
  for token in response.response_gen:
190
- #if not token.startswith("system:") and not token.startswith("user:"):
191
- #if token.startswith("file_path:"):
192
- #sources.append(token)
193
-
194
- outputs.append(token)
195
  print(f"Generated token: {token}")
196
-
197
  yield "".join(outputs)
198
  #yield CompletionResponse(text=''.join(outputs), delta=token)
199
 
 
165
  ),
166
  )
167
 
168
+ retriever = index.as_retriever(similarity_top_k=3)
169
+
170
  # Let's test it out
171
+ relevant_chunks = relevant_chunks = retriever.retrieve(query_str)
172
  print(f"Found: {len(relevant_chunks)} relevant chunks")
173
  for idx, chunk in enumerate(relevant_chunks):
174
  info_message += f"{idx + 1}) {chunk.text[:64]}...\n"
175
  print(info_message)
176
+ gr.Info(info_message)
177
 
178
 
179
  #prompts_dict = chat_engine.get_prompts()
 
189
  #response = chat_engine.chat(query_str)
190
 
191
  for token in response.response_gen:
192
+ if token.startswith("assistant:"):
193
+ # Remove the "assistant:" prefix
194
+ outputs.append(token[len("assistant:"):])
 
 
195
  print(f"Generated token: {token}")
 
196
  yield "".join(outputs)
197
  #yield CompletionResponse(text=''.join(outputs), delta=token)
198