Cran-May commited on
Commit
4e9cd26
·
verified ·
1 Parent(s): df1be55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -32,11 +32,14 @@ def chat_fn(message, history, model, system_message, max_tokens, temperature, to
32
  response_generator = respond(message, history_list, model, system_message, max_tokens, temperature, top_p, top_k, repeat_penalty)
33
 
34
  for messages in response_generator:
35
- # 转换 messages 为 Gradio Chatbot 接受的格式
36
  chatbot_messages = []
37
- for msg in messages: # messages 现在是 BasicChatHistory 对象,可以直接迭代
38
- chatbot_messages.append([msg["content"], msg["role"] == "assistant"])
39
- yield chatbot_messages, history
 
 
 
40
 
41
 
42
  def respond(
 
32
  response_generator = respond(message, history_list, model, system_message, max_tokens, temperature, top_p, top_k, repeat_penalty)
33
 
34
  for messages in response_generator:
35
+ # 将历史消息直接转换为 Gradio Chatbot 格式
36
  chatbot_messages = []
37
+ for user_msg, assistant_msg in messages:
38
+ if user_msg: # 添加用户消息
39
+ chatbot_messages.append([user_msg, False])
40
+ if assistant_msg: # 添加助手消息
41
+ chatbot_messages.append([assistant_msg, True])
42
+ yield chatbot_messages, messages
43
 
44
 
45
  def respond(