Alexend commited on
Commit
52285f4
·
verified ·
1 Parent(s): 222c33a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -1,4 +1,4 @@
1
- # ✅ app.py - 自動建構向量庫版本(向量式 RAG)
2
 
3
  import json
4
  import os
@@ -61,19 +61,19 @@ def search_context_faiss(user_input, top_k=3):
61
  D, I = index.search(vec, top_k)
62
  return "\n".join([docs[i] for i in I[0] if i < len(docs)])
63
 
64
- # ✅ LLM 生成繁體中文回答
65
 
66
  def generate_answer(user_input, context):
67
  prompt = f"""
68
- 你是一位了解南臺科技大學的親切語音助理,根據下資料回答使用者的問題
69
 
70
- [相關資料]
71
  {context}
72
 
73
  [問題]
74
  {user_input}
75
 
76
- 請用繁體中文簡短自然回答,限制在 90 字內,回應應明確有資訊,不要含糊或重複問題。
77
  """
78
  inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
79
  outputs = model.generate(**inputs, max_new_tokens=150)
 
1
+ # ✅ app.py - 自動建構向量庫版本(向量式 RAG) with 強化 prompt
2
 
3
  import json
4
  import os
 
61
  D, I = index.search(vec, top_k)
62
  return "\n".join([docs[i] for i in I[0] if i < len(docs)])
63
 
64
+ # ✅ LLM 生成繁體中文回答(強化提示)
65
 
66
  def generate_answer(user_input, context):
67
  prompt = f"""
68
+ 你是一位熟悉南臺科技大學的智慧語音助理,根據下資料,用繁體中文回答問題
69
 
70
+ [資料內容]
71
  {context}
72
 
73
  [問題]
74
  {user_input}
75
 
76
+ 根據資料,一至兩句話自然回答問題。不要重複問題本身、不要說你是誰,回答務必明確,約 90 字內
77
  """
78
  inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
79
  outputs = model.generate(**inputs, max_new_tokens=150)