Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -386,8 +386,14 @@ def rag_chat(question, selected_speakers, history):
|
|
| 386 |
context += f"內容:{result.text}\n"
|
| 387 |
context += f"相關性分數:向量={result.vector_score:.3f}, LLM={result.llm_score:.3f}, 加權={result.weighted_score:.3f}\n\n"
|
| 388 |
|
| 389 |
-
# 保存原始內容
|
| 390 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 391 |
|
| 392 |
# 構建 GPT prompt(每次獨立,不包含歷史)
|
| 393 |
prompt = f"""基於以下訪談內容回答問題。請提供準確、完整的回答。
|
|
@@ -416,7 +422,13 @@ def rag_chat(question, selected_speakers, history):
|
|
| 416 |
# 添加原始 RAG 內容
|
| 417 |
answer_with_sources = f"{answer}\n\n---\n📚 **原始 RAG 來源:**\n"
|
| 418 |
for i, raw_context in enumerate(raw_contexts[:3], 1):
|
| 419 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 420 |
|
| 421 |
return history + [[question, answer_with_sources]]
|
| 422 |
|
|
@@ -527,7 +539,7 @@ def single_interviewee_guide_filling(file_path, selected_speakers):
|
|
| 527 |
p = output_doc.add_paragraph()
|
| 528 |
p.add_run(f"{j}. [{raw['speaker']} - Turn {raw['turn_index']}] ").bold = True
|
| 529 |
p.add_run(f"(相關性: {raw['score']:.3f})\n")
|
| 530 |
-
p.add_run(f"{raw['text'][:
|
| 531 |
else:
|
| 532 |
output_doc.add_paragraph("未找到相關內容")
|
| 533 |
|
|
|
|
| 386 |
context += f"內容:{result.text}\n"
|
| 387 |
context += f"相關性分數:向量={result.vector_score:.3f}, LLM={result.llm_score:.3f}, 加權={result.weighted_score:.3f}\n\n"
|
| 388 |
|
| 389 |
+
# 保存原始內容 - 確保文本存在
|
| 390 |
+
if result.text:
|
| 391 |
+
raw_context_text = f"[{result.speaker} - Turn {result.turn_index}]: {result.text}"
|
| 392 |
+
raw_contexts.append(raw_context_text)
|
| 393 |
+
|
| 394 |
+
# 確保有原始內容
|
| 395 |
+
if not raw_contexts:
|
| 396 |
+
raw_contexts = ["未能提取原始內容"]
|
| 397 |
|
| 398 |
# 構建 GPT prompt(每次獨立,不包含歷史)
|
| 399 |
prompt = f"""基於以下訪談內容回答問題。請提供準確、完整的回答。
|
|
|
|
| 422 |
# 添加原始 RAG 內容
|
| 423 |
answer_with_sources = f"{answer}\n\n---\n📚 **原始 RAG 來源:**\n"
|
| 424 |
for i, raw_context in enumerate(raw_contexts[:3], 1):
|
| 425 |
+
# 確保 raw_context 是字串且有內容
|
| 426 |
+
if raw_context and raw_context != "未能提取原始內容":
|
| 427 |
+
# 截取前500個字元,如果內容較短則顯示全部
|
| 428 |
+
display_text = raw_context if len(raw_context) <= 500 else f"{raw_context[:500]}..."
|
| 429 |
+
answer_with_sources += f"\n**來源 {i}:**\n{display_text}\n"
|
| 430 |
+
else:
|
| 431 |
+
answer_with_sources += f"\n**來源 {i}:** 無內容\n"
|
| 432 |
|
| 433 |
return history + [[question, answer_with_sources]]
|
| 434 |
|
|
|
|
| 539 |
p = output_doc.add_paragraph()
|
| 540 |
p.add_run(f"{j}. [{raw['speaker']} - Turn {raw['turn_index']}] ").bold = True
|
| 541 |
p.add_run(f"(相關性: {raw['score']:.3f})\n")
|
| 542 |
+
p.add_run(f"{raw['text'][:500]}...")
|
| 543 |
else:
|
| 544 |
output_doc.add_paragraph("未找到相關內容")
|
| 545 |
|