Limour commited on
Commit
91dc74f
1 Parent(s): bce2a0f

Upload 2 files

Browse files
Files changed (2) hide show
  1. mods/btn_com.py +3 -2
  2. mods/btn_retry.py +57 -0
mods/btn_com.py CHANGED
@@ -77,11 +77,12 @@ def init(cfg):
77
  if cfg['session_active'] != finish:
78
  raise RuntimeError
79
  cfg['session_active'] = not cfg['session_active']
80
- return tmp, tmp, tmp
81
 
82
  return _inner
83
 
84
- btn_start_or_finish_outputs = [cfg['btn_submit'], cfg['btn_vo'], cfg['btn_suggest']]
 
85
 
86
  cfg['btn_start'] = {
87
  'fn': btn_start_or_finish(False),
 
77
  if cfg['session_active'] != finish:
78
  raise RuntimeError
79
  cfg['session_active'] = not cfg['session_active']
80
+ return tmp, tmp, tmp, tmp
81
 
82
  return _inner
83
 
84
+ btn_start_or_finish_outputs = [cfg['btn_submit'], cfg['btn_vo'],
85
+ cfg['btn_suggest'], cfg['btn_retry']]
86
 
87
  cfg['btn_start'] = {
88
  'fn': btn_start_or_finish(False),
mods/btn_retry.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def init(cfg):
2
+ # ========== 共同 ==========
3
+ model = cfg['model']
4
+ btn_com = cfg['btn_com']
5
+ s_info = cfg['s_info']
6
+ lock = cfg['session_lock']
7
+ # ========== 特殊 ==========
8
+ chat_template = cfg['chat_template']
9
+ chatbot = cfg['chatbot']
10
+ chat_display_format = cfg['chat_display_format']
11
+
12
+ # ========== 重新生成一份回答 ==========
13
+ def btn_retry(history, _n_keep, _n_discard,
14
+ _temperature, _repeat_penalty, _frequency_penalty,
15
+ _presence_penalty, _repeat_last_n, _top_k,
16
+ _top_p, _min_p, _typical_p,
17
+ _tfs_z, _mirostat_mode, _mirostat_eta,
18
+ _mirostat_tau, _usr, _char,
19
+ _rag, _max_tokens):
20
+ with lock:
21
+ if not cfg['session_active']:
22
+ raise RuntimeError
23
+ # ========== 回滚到上一次用户输入 ==========
24
+ if not model.venv_revision('usr'):
25
+ return history, model.venv_info
26
+ # ========== 需要临时注入的内容 ==========
27
+ if len(_rag) > 0:
28
+ model.venv_create('rag') # 记录 venv_idx
29
+ t_rag = chat_template('system', _rag)
30
+ model.eval_t(t_rag, _n_keep, _n_discard)
31
+ # ========== 模型输出 ==========
32
+ model.venv_create('char')
33
+ _tmp = btn_com(_n_keep, _n_discard,
34
+ _temperature, _repeat_penalty, _frequency_penalty,
35
+ _presence_penalty, _repeat_last_n, _top_k,
36
+ _top_p, _min_p, _typical_p,
37
+ _tfs_z, _mirostat_mode, _mirostat_eta,
38
+ _mirostat_tau, _char, _max_tokens)
39
+ for _h in _tmp:
40
+ history[-1][1] = _h
41
+ yield history, model.venv_info
42
+ # ========== 输出完毕后格式化输出 ==========
43
+ history[-1][1] = chat_display_format(history[-1][1])
44
+ yield history, model.venv_info
45
+ # ========== 响应完毕后清除注入的内容 ==========
46
+ model.venv_remove('rag') # 销毁对应的 venv
47
+ yield history, model.venv_info
48
+
49
+ cfg['btn_retry'].click(
50
+ **cfg['btn_start']
51
+ ).success(
52
+ fn=btn_retry,
53
+ inputs=[chatbot]+cfg['setting'],
54
+ outputs=[chatbot, s_info]
55
+ ).success(
56
+ **cfg['btn_finish']
57
+ )