wybxc commited on
Commit
f019258
1 Parent(s): 3cd2d35

fix: split user and bot

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -60,9 +60,11 @@ with gr.Blocks() as demo:
60
 
61
  tokenizer, model = load_model()
62
 
63
- def on_message(
64
- user_message: str, history: list[list[str]], alpha: float, topk: int
65
- ):
 
 
66
  bot_message = generate(
67
  tokenizer,
68
  model,
@@ -70,10 +72,15 @@ with gr.Blocks() as demo:
70
  alpha=alpha,
71
  topk=topk,
72
  )
73
- return "", [*history, [user_message, bot_message]]
 
74
 
75
- msg.submit(on_message, inputs=[msg, chatbot, alpha, topk], outputs=[msg, chatbot])
76
- button.click(on_message, inputs=[msg, chatbot, alpha, topk], outputs=[msg, chatbot])
 
 
 
 
77
 
78
  clear.click(lambda: None, None, chatbot)
79
 
 
60
 
61
  tokenizer, model = load_model()
62
 
63
+ def user(user_message: str, history: list[list[str]]):
64
+ return "", [*history, [user_message, None]]
65
+
66
+ def bot(history: list[list[str]], alpha: float, topk: int):
67
+ user_message = history[-1][0]
68
  bot_message = generate(
69
  tokenizer,
70
  model,
 
72
  alpha=alpha,
73
  topk=topk,
74
  )
75
+ history[-1][1] = bot_message
76
+ return history
77
 
78
+ msg.submit(user, inputs=[msg, chatbot], outputs=[msg, chatbot]).then(
79
+ bot, inputs=[chatbot, alpha, topk], outputs=[chatbot]
80
+ )
81
+ button.click(user, inputs=[msg, chatbot], outputs=[msg, chatbot]).then(
82
+ bot, inputs=[chatbot, alpha, topk], outputs=[chatbot]
83
+ )
84
 
85
  clear.click(lambda: None, None, chatbot)
86