paarthbhise commited on
Commit
86be940
·
verified ·
1 Parent(s): f46b169

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -59,20 +59,23 @@ demo_ephemeral_chat_history = ChatMessageHistory()
59
  def get_text_response(message, history):
60
  """
61
  Gradio passes the current 'message' and the 'history' list.
62
- We convert the history to LangChain format and invoke the chain.
63
  """
64
- # Convert Gradio history format to LangChain messages
65
  formatted_history = []
66
- for human, ai in history:
67
- formatted_history.append(("human", human))
68
- formatted_history.append(("ai", ai))
 
 
 
 
69
 
70
- # Run the chain
71
  response = chain.invoke({
72
  "chat_history": formatted_history,
73
  "user_message": message
74
  })
75
-
76
  return response
77
 
78
  # 6. Launch the Gradio Interface
 
59
  def get_text_response(message, history):
60
  """
61
  Gradio passes the current 'message' and the 'history' list.
62
+ With type='messages', history is a list of dicts.
63
  """
 
64
  formatted_history = []
65
+
66
+ # Correctly parse the new Gradio dictionary format
67
+ for msg in history:
68
+ if msg["role"] == "user":
69
+ formatted_history.append(("human", msg["content"]))
70
+ elif msg["role"] == "assistant":
71
+ formatted_history.append(("ai", msg["content"]))
72
 
73
+ # Run the LangChain invocation
74
  response = chain.invoke({
75
  "chat_history": formatted_history,
76
  "user_message": message
77
  })
78
+
79
  return response
80
 
81
  # 6. Launch the Gradio Interface