barnit07 commited on
Commit
4708907
·
verified ·
1 Parent(s): d8c360c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -23,22 +23,19 @@ def format_chunks(chunks):
23
 
24
  # ---------- Chat handler (tuple-based, HF compatible) ----------
25
  def chat_handler(message, chat_history):
26
- """
27
- message: str
28
- chat_history: List[Tuple[user, assistant]]
29
- """
30
  chat_history = chat_history or []
31
 
32
- # Build history string for RAG backend
33
  history_text = ""
34
- for user_msg, bot_msg in chat_history:
35
- history_text += f"User: {user_msg}\nAssistant: {bot_msg}\n"
36
 
37
  # Call RAG backend
38
  answer, chunks = answer_question(message, history_text)
39
 
40
- # Append new turn (TUPLE FORMAT)
41
- chat_history.append((message, answer))
 
42
 
43
  chunk_display = format_chunks(chunks)
44
 
 
23
 
24
  # ---------- Chat handler (tuple-based, HF compatible) ----------
25
  def chat_handler(message, chat_history):
 
 
 
 
26
  chat_history = chat_history or []
27
 
28
+ # Build history text for RAG backend
29
  history_text = ""
30
+ for msg in chat_history:
31
+ history_text += f"{msg['role'].capitalize()}: {msg['content']}\n"
32
 
33
  # Call RAG backend
34
  answer, chunks = answer_question(message, history_text)
35
 
36
+ # Append messages as DICTS (REQUIRED)
37
+ chat_history.append({"role": "user", "content": message})
38
+ chat_history.append({"role": "assistant", "content": answer})
39
 
40
  chunk_display = format_chunks(chunks)
41