Limour commited on
Commit
d4c1f12
1 Parent(s): b1cbb3c

Upload 4 files

Browse files
mods/btn_rag.py CHANGED
@@ -1,8 +1,49 @@
1
  def init(cfg):
2
- # ========== 待实现 ==========
3
- def btn_rag_(_rag, _msg):
4
- retn = ''
5
- return retn
6
 
7
- cfg['btn_rag'].click(fn=btn_rag_, outputs=cfg['rag'],
8
- inputs=[cfg['rag'], cfg['msg']])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  def init(cfg):
2
+ # ========== 共同 ==========
3
+ model = cfg['model']
4
+ s_info = cfg['s_info']
5
+ lock = cfg['session_lock']
6
 
7
+ # ========== 特殊 ==========
8
+ chat_template = cfg['chat_template']
9
+
10
+ # ========== 注入内容 ==========
11
+ def btn_rag(_n_keep, _n_discard,
12
+ _temperature, _repeat_penalty, _frequency_penalty,
13
+ _presence_penalty, _repeat_last_n, _top_k,
14
+ _top_p, _min_p, _typical_p,
15
+ _tfs_z, _mirostat_mode, _mirostat_eta,
16
+ _mirostat_tau, _usr, _char,
17
+ _rag, _max_tokens):
18
+ with lock:
19
+ if not cfg['session_active']:
20
+ raise RuntimeError
21
+ if cfg['btn_stop_status']:
22
+ yield model.venv_info
23
+ return
24
+ # ========== 清除之前注入的内容 ==========
25
+ model.venv_remove('rag')
26
+ # ========== 没有需要注入的内容 ==========
27
+ if not _rag:
28
+ yield model.venv_info
29
+ return
30
+ # ========== 需要临时注入的内容 ==========
31
+ model.venv_create('rag')
32
+ t_rag = chat_template('system', _rag)
33
+ model.eval_t(t_rag, _n_keep, _n_discard)
34
+ yield model.venv_info
35
+
36
+ cfg['btn_rag_fn'] = {
37
+ 'fn': btn_rag,
38
+ 'inputs': cfg['setting'],
39
+ 'outputs': s_info
40
+ }
41
+ cfg['btn_rag_fn'].update(cfg['btn_concurrency'])
42
+
43
+ cfg['btn_rag'].click(
44
+ **cfg['btn_start']
45
+ ).success(
46
+ **cfg['btn_rag_fn']
47
+ ).success(
48
+ **cfg['btn_finish']
49
+ )
mods/btn_retry.py CHANGED
@@ -24,11 +24,6 @@ def init(cfg):
24
  if not model.venv_revision('usr'):
25
  yield history, model.venv_info
26
  return
27
- # ========== 需要临时注入的内容 ==========
28
- if len(_rag) > 0:
29
- model.venv_create('rag') # 记录 venv_idx
30
- t_rag = chat_template('system', _rag)
31
- model.eval_t(t_rag, _n_keep, _n_discard)
32
  # ========== 模型输出 ==========
33
  model.venv_create('char')
34
  _tmp = btn_com(_n_keep, _n_discard,
@@ -43,17 +38,18 @@ def init(cfg):
43
  # ========== 输出完毕后格式化输出 ==========
44
  history[-1][1] = chat_display_format(history[-1][1])
45
  yield history, model.venv_info
46
- # ========== 响应完毕后清除注入的内容 ==========
47
- model.venv_remove('rag') # 销毁对应的 venv
48
- yield history, model.venv_info
 
 
 
 
49
 
50
  cfg['btn_retry'].click(
51
  **cfg['btn_start']
52
  ).success(
53
- fn=btn_retry,
54
- inputs=[chatbot]+cfg['setting'],
55
- outputs=[chatbot, s_info],
56
- **cfg['btn_concurrency']
57
  ).success(
58
  **cfg['btn_finish']
59
  )
 
24
  if not model.venv_revision('usr'):
25
  yield history, model.venv_info
26
  return
 
 
 
 
 
27
  # ========== 模型输出 ==========
28
  model.venv_create('char')
29
  _tmp = btn_com(_n_keep, _n_discard,
 
38
  # ========== 输出完毕后格式化输出 ==========
39
  history[-1][1] = chat_display_format(history[-1][1])
40
  yield history, model.venv_info
41
+
42
+ cfg['btn_retry_fn'] = {
43
+ 'fn': btn_retry,
44
+ 'inputs': [chatbot]+cfg['setting'],
45
+ 'outputs': [chatbot, s_info],
46
+ }
47
+ cfg['btn_retry_fn'].update(cfg['btn_concurrency'])
48
 
49
  cfg['btn_retry'].click(
50
  **cfg['btn_start']
51
  ).success(
52
+ **cfg['btn_retry_fn']
 
 
 
53
  ).success(
54
  **cfg['btn_finish']
55
  )
mods/btn_submit.py CHANGED
@@ -29,11 +29,6 @@ def init(cfg):
29
  with lock:
30
  if not cfg['session_active']:
31
  raise RuntimeError
32
- # ========== 需要临时注入的内容 ==========
33
- if len(_rag) > 0:
34
- model.venv_create('rag') # 记录 venv_idx
35
- t_rag = chat_template('system', _rag)
36
- model.eval_t(t_rag, _n_keep, _n_discard)
37
  # ========== 释放不再需要的环境 ==========
38
  model.venv_disband({'usr', 'char'})
39
  print('venv_disband char', model.venv_info)
@@ -59,9 +54,6 @@ def init(cfg):
59
  # ========== 输出完毕后格式化输出 ==========
60
  history[-1][1] = chat_display_format(history[-1][1])
61
  yield history, model.venv_info
62
- # ========== 响应完毕后清除注入的内容 ==========
63
- model.venv_remove('rag') # 销毁对应的 venv
64
- yield history, model.venv_info
65
 
66
  cfg['btn_submit_fn_usr'] = {
67
  'fn': btn_submit_usr,
 
29
  with lock:
30
  if not cfg['session_active']:
31
  raise RuntimeError
 
 
 
 
 
32
  # ========== 释放不再需要的环境 ==========
33
  model.venv_disband({'usr', 'char'})
34
  print('venv_disband char', model.venv_info)
 
54
  # ========== 输出完毕后格式化输出 ==========
55
  history[-1][1] = chat_display_format(history[-1][1])
56
  yield history, model.venv_info
 
 
 
57
 
58
  cfg['btn_submit_fn_usr'] = {
59
  'fn': btn_submit_usr,
mods/btn_submit_vo_suggest.py CHANGED
@@ -3,6 +3,8 @@ def init(cfg):
3
  **cfg['btn_start']
4
  ).success(
5
  **cfg['btn_submit_fn_usr']
 
 
6
  ).success(
7
  **cfg['btn_submit_fn_bot']
8
  ).success(
 
3
  **cfg['btn_start']
4
  ).success(
5
  **cfg['btn_submit_fn_usr']
6
+ ).success(
7
+ **cfg['btn_rag_fn']
8
  ).success(
9
  **cfg['btn_submit_fn_bot']
10
  ).success(