Tuchuanhuhuhu commited on
Commit
25b27e3
·
1 Parent(s): dfcf091

为各个模型添加了个性化软上限

Browse files
Files changed (3) hide show
  1. ChuanhuChatbot.py +1 -1
  2. modules/chat_func.py +23 -23
  3. modules/presets.py +27 -2
ChuanhuChatbot.py CHANGED
@@ -331,7 +331,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
331
  token_count,
332
  top_p,
333
  temperature,
334
- gr.State(max_token_streaming//2 if use_streaming_checkbox.value else max_token_all//2),
335
  model_select_dropdown,
336
  language_select_dropdown,
337
  ],
 
331
  token_count,
332
  top_p,
333
  temperature,
334
+ gr.State(sum(token_count.value[-4:])),
335
  model_select_dropdown,
336
  language_select_dropdown,
337
  ],
modules/chat_func.py CHANGED
@@ -350,29 +350,29 @@ def predict(
350
  + colorama.Style.RESET_ALL
351
  )
352
 
353
- # if stream:
354
- # max_token = max_token_streaming
355
- # else:
356
- # max_token = max_token_all
357
-
358
- # if sum(all_token_counts) > max_token and should_check_token_count:
359
- # status_text = f"精简token中{all_token_counts}/{max_token}"
360
- # logging.info(status_text)
361
- # yield chatbot, history, status_text, all_token_counts
362
- # iter = reduce_token_size(
363
- # openai_api_key,
364
- # system_prompt,
365
- # history,
366
- # chatbot,
367
- # all_token_counts,
368
- # top_p,
369
- # temperature,
370
- # max_token//2,
371
- # selected_model=selected_model,
372
- # )
373
- # for chatbot, history, status_text, all_token_counts in iter:
374
- # status_text = f"Token 达到上限,已自动降低Token计数至 {status_text}"
375
- # yield chatbot, history, status_text, all_token_counts
376
 
377
 
378
  def retry(
 
350
  + colorama.Style.RESET_ALL
351
  )
352
 
353
+ if stream:
354
+ max_token = MODEL_SOFT_TOKEN_LIMIT[selected_model]["streaming"]
355
+ else:
356
+ max_token = MODEL_SOFT_TOKEN_LIMIT[selected_model]["all"]
357
+
358
+ if sum(all_token_counts) > max_token and should_check_token_count:
359
+ status_text = f"精简token中{all_token_counts}/{max_token}"
360
+ logging.info(status_text)
361
+ yield chatbot, history, status_text, all_token_counts
362
+ iter = reduce_token_size(
363
+ openai_api_key,
364
+ system_prompt,
365
+ history,
366
+ chatbot,
367
+ all_token_counts,
368
+ top_p,
369
+ temperature,
370
+ max_token//2,
371
+ selected_model=selected_model,
372
+ )
373
+ for chatbot, history, status_text, all_token_counts in iter:
374
+ status_text = f"Token 达到上限,已自动降低Token计数至 {status_text}"
375
+ yield chatbot, history, status_text, all_token_counts
376
 
377
 
378
  def retry(
modules/presets.py CHANGED
@@ -19,9 +19,7 @@ ssl_error_prompt = "SSL错误,无法获取对话。" # SSL 错误
19
  no_apikey_msg = "API key长度不是51位,请检查是否输入正确。" # API key 长度不足 51 位
20
  no_input_msg = "请输入对话内容。" # 未输入对话内容
21
 
22
- max_token_streaming = 3500 # 流式对话时的最大 token 数
23
  timeout_streaming = 10 # 流式对话时的超时时间
24
- max_token_all = 3500 # 非流式对话时的最大 token 数
25
  timeout_all = 200 # 非流式对话时的超时时间
26
  enable_streaming_option = True # 是否启用选择选择是否实时显示回答的勾选框
27
  HIDE_MY_KEY = False # 如果你想在UI中隐藏你的 API 密钥,将此值设置为 True
@@ -57,6 +55,33 @@ MODELS = [
57
  "gpt-4-32k-0314",
58
  ] # 可选的模型
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  REPLY_LANGUAGES = [
61
  "中文",
62
  "English",
 
19
  no_apikey_msg = "API key长度不是51位,请检查是否输入正确。" # API key 长度不足 51 位
20
  no_input_msg = "请输入对话内容。" # 未输入对话内容
21
 
 
22
  timeout_streaming = 10 # 流式对话时的超时时间
 
23
  timeout_all = 200 # 非流式对话时的超时时间
24
  enable_streaming_option = True # 是否启用选择选择是否实时显示回答的勾选框
25
  HIDE_MY_KEY = False # 如果你想在UI中隐藏你的 API 密钥,将此值设置为 True
 
55
  "gpt-4-32k-0314",
56
  ] # 可选的模型
57
 
58
+ MODEL_SOFT_TOKEN_LIMIT = {
59
+ "gpt-3.5-turbo": {
60
+ "streaming": 3500,
61
+ "all": 3500
62
+ },
63
+ "gpt-3.5-turbo-0301": {
64
+ "streaming": 3500,
65
+ "all": 3500
66
+ },
67
+ "gpt-4": {
68
+ "streaming": 7500,
69
+ "all": 7500
70
+ },
71
+ "gpt-4-0314": {
72
+ "streaming": 7500,
73
+ "all": 7500
74
+ },
75
+ "gpt-4-32k": {
76
+ "streaming": 31000,
77
+ "all": 31000
78
+ },
79
+ "gpt-4-32k-0314": {
80
+ "streaming": 31000,
81
+ "all": 31000
82
+ }
83
+ }
84
+
85
  REPLY_LANGUAGES = [
86
  "中文",
87
  "English",