MCPcopy Create free account
hub / github.com/Enfoirer/Text2GraphRAG / run_interactive

Method run_interactive

main.py:309–361  ·  view source on GitHub ↗

运行交互式问答

(self)

Source from the content-addressed store, hash-verified

307
308
309 def run_interactive(self):
310 """运行交互式问答"""
311 if not self.system_ready:
312 print("❌ 系统未就绪,请先构建知识库")
313 return
314
315 print("\n欢迎使用明眸RAG疾病助手!")
316 print("可用功能:")
317 print(" - 'stats' : 查看系统统计")
318 print(" - 'rebuild' : 重建知识库")
319 print(" - 'quit' : 退出系统")
320 print("\n" + "="*50)
321
322 while True:
323 try:
324 user_input = input("\n您的问题: ").strip()
325
326 if not user_input:
327 continue
328
329 if user_input.lower() == 'quit':
330 break
331 elif user_input.lower() == 'stats':
332 self._show_system_stats()
333 continue
334 elif user_input.lower() == 'rebuild':
335 self._rebuild_knowledge_base()
336 continue
337
338 # 普通问答 - 使用默认设置
339 use_stream = True # 默认使用流式输出
340 explain_routing = False # 默认不显示路由决策
341
342 print("\n回答:")
343
344 result, analysis = self.ask_question_with_routing(
345 user_input,
346 stream=use_stream,
347 explain_routing=explain_routing
348 )
349
350 if not use_stream and result:
351 print(f"{result}\n")
352
353 except KeyboardInterrupt:
354 break
355 except Exception as e:
356 print(f"处理问题时出错: {e}")
357 import traceback
358 traceback.print_exc()
359
360 print("\n👋 感谢使用明眸RAG疾病助手!")
361 self._cleanup()
362
363 def _show_system_stats(self):
364 """显示系统统计信息"""

Callers 1

mainFunction · 0.95

Calls 4

_show_system_statsMethod · 0.95
_cleanupMethod · 0.95

Tested by

no test coverage detected