ThongCoding commited on
Commit
4108589
·
verified ·
1 Parent(s): e7af7ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -8
app.py CHANGED
@@ -27,9 +27,8 @@ llm = Llama(
27
 
28
  # --- Hàm chat ---
29
  def chat_fn(message, history):
30
- if history is None:
31
- history = []
32
- system_prompt = {"role": "system", "content": "Bạn là một trợ lý AI giao tiếp bằng tiếng Việt, trả lời tự nhiên và thân thiện."}
33
  messages = [system_prompt]
34
  for user_msg, bot_msg in history:
35
  messages.append({"role": "user", "content": user_msg})
@@ -43,13 +42,9 @@ def chat_fn(message, history):
43
  stop=["<|user|>", "<|assistant|>"],
44
  )
45
  reply = response["choices"][0]["message"]["content"].strip()
46
-
47
- # Nếu reply trống, trả về câu mặc định
48
- if not reply:
49
- reply = "Xin lỗi, mình chưa hiểu yêu cầu của bạn. Bạn có thể hỏi lại nhé!"
50
 
51
  history.append((message, reply))
52
- return history
53
 
54
  # --- Giao diện Gradio ---
55
  gr.ChatInterface(
 
27
 
28
  # --- Hàm chat ---
29
  def chat_fn(message, history):
30
+ history = history or []
31
+ system_prompt = {"role": "system", "content": "Bạn là trợ lý AI tiếng Việt hữu ích."}
 
32
  messages = [system_prompt]
33
  for user_msg, bot_msg in history:
34
  messages.append({"role": "user", "content": user_msg})
 
42
  stop=["<|user|>", "<|assistant|>"],
43
  )
44
  reply = response["choices"][0]["message"]["content"].strip()
 
 
 
 
45
 
46
  history.append((message, reply))
47
+ return history # <-- trả về luôn cả history, không tách riêng ra nữa
48
 
49
  # --- Giao diện Gradio ---
50
  gr.ChatInterface(