Skip to content

Commit

Permalink
过滤板块新增 指定前后缀触发LLM功能,可以限制部分弹幕触发LLM,部分弹幕只进行其他功能的执行
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikaros-521 committed Jun 15, 2024
1 parent f690a75 commit c1abef2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
"after_filter_str": [
"#"
],
"before_must_str_for_llm": [],
"after_must_str_for_llm": [],
"badwords": {
"enable": true,
"discard": false,
Expand Down
2 changes: 2 additions & 0 deletions config.json.bak
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
"after_filter_str": [
"#"
],
"before_must_str_for_llm": [],
"after_must_str_for_llm": [],
"badwords": {
"enable": true,
"discard": false,
Expand Down
14 changes: 14 additions & 0 deletions utils/my_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,6 +1483,20 @@ def llm_handle(self, chat_type, data, type="chat", webui_show=True):
str: LLM返回的结果
"""
try:
# 判断弹幕是否以xx起始,如果不是则返回None 不触发LLM
if My_handle.config.get("filter", "before_must_str_for_llm") != []:
if any(data["ori_content"].startswith(prefix) for prefix in My_handle.config.get("filter", "before_must_str_for_llm")):
pass
else:
return None

# 判断弹幕是否以xx结尾,如果不是则返回None
if My_handle.config.get("filter", "after_must_str_for_llm") != []:
if any(data["ori_content"].endswith(prefix) for prefix in My_handle.config.get("filter", "after_must_str_for_llm")):
pass
else:
return None

resp_content = None

logging.debug(f"chat_type={chat_type}, data={data}")
Expand Down
16 changes: 11 additions & 5 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,9 @@ def common_textarea_handle(content):
config_data["filter"]["after_must_str"] = common_textarea_handle(textarea_filter_after_must_str.value)
config_data["filter"]["before_filter_str"] = common_textarea_handle(textarea_filter_before_filter_str.value)
config_data["filter"]["after_filter_str"] = common_textarea_handle(textarea_filter_after_filter_str.value)
config_data["filter"]["before_must_str_for_llm"] = common_textarea_handle(textarea_filter_before_must_str_for_llm.value)
config_data["filter"]["after_must_str_for_llm"] = common_textarea_handle(textarea_filter_after_must_str_for_llm.value)

config_data["filter"]["badwords"]["enable"] = switch_filter_badwords_enable.value
config_data["filter"]["badwords"]["discard"] = switch_filter_badwords_discard.value
config_data["filter"]["badwords"]["path"] = input_filter_badwords_path.value
Expand Down Expand Up @@ -3021,11 +3024,14 @@ def save_config():
if config.get("webui", "show_card", "common_config", "filter"):
with ui.card().style(card_css):
ui.label('过滤')
with ui.grid(columns=4):
textarea_filter_before_must_str = ui.textarea(label='弹幕触发前缀', placeholder='前缀必须携带其中任一字符串才能触发\n例如:配置#,那么这个会触发:#你好', value=textarea_data_change(config.get("filter", "before_must_str"))).style("width:300px;")
textarea_filter_after_must_str = ui.textarea(label='弹幕触发后缀', placeholder='后缀必须携带其中任一字符串才能触发\n例如:配置。那么这个会触发:你好。', value=textarea_data_change(config.get("filter", "before_must_str"))).style("width:300px;")
textarea_filter_before_filter_str = ui.textarea(label='弹幕过滤前缀', placeholder='当前缀为其中任一字符串时,弹幕会被过滤\n例如:配置#,那么这个会被过滤:#你好', value=textarea_data_change(config.get("filter", "before_filter_str"))).style("width:300px;")
textarea_filter_after_filter_str = ui.textarea(label='弹幕过滤后缀', placeholder='当后缀为其中任一字符串时,弹幕会被过滤\n例如:配置#,那么这个会被过滤:你好#', value=textarea_data_change(config.get("filter", "before_filter_str"))).style("width:300px;")
with ui.grid(columns=6):
textarea_filter_before_must_str = ui.textarea(label='弹幕触发前缀', placeholder='前缀必须携带其中任一字符串才能触发\n例如:配置#,那么这个会触发:#你好', value=textarea_data_change(config.get("filter", "before_must_str"))).style("width:200px;").tooltip("前缀必须携带其中任一字符串才能触发\n例如:配置#,那么这个会触发:#你好")
textarea_filter_after_must_str = ui.textarea(label='弹幕触发后缀', placeholder='后缀必须携带其中任一字符串才能触发\n例如:配置。那么这个会触发:你好。', value=textarea_data_change(config.get("filter", "before_must_str"))).style("width:200px;").tooltip("后缀必须携带其中任一字符串才能触发\n例如:配置。那么这个会触发:你好。")
textarea_filter_before_filter_str = ui.textarea(label='弹幕过滤前缀', placeholder='当前缀为其中任一字符串时,弹幕会被过滤\n例如:配置#,那么这个会被过滤:#你好', value=textarea_data_change(config.get("filter", "before_filter_str"))).style("width:200px;").tooltip("当前缀为其中任一字符串时,弹幕会被过滤\n例如:配置#,那么这个会被过滤:#你好")
textarea_filter_after_filter_str = ui.textarea(label='弹幕过滤后缀', placeholder='当后缀为其中任一字符串时,弹幕会被过滤\n例如:配置#,那么这个会被过滤:你好#', value=textarea_data_change(config.get("filter", "before_filter_str"))).style("width:200px;").tooltip("当后缀为其中任一字符串时,弹幕会被过滤\n例如:配置#,那么这个会被过滤:你好#")
textarea_filter_before_must_str_for_llm = ui.textarea(label='LLM触发前缀', placeholder='前缀必须携带其中任一字符串才能触发LLM\n例如:配置#,那么这个会触发:#你好', value=textarea_data_change(config.get("filter", "before_must_str_for_llm"))).style("width:200px;").tooltip("前缀必须携带其中任一字符串才能触发LLM\n例如:配置#,那么这个会触发:#你好")
textarea_filter_after_must_str_for_llm = ui.textarea(label='LLM触发后缀', placeholder='后缀必须携带其中任一字符串才能触发LLM\n例如:配置。那么这个会触发:你好。', value=textarea_data_change(config.get("filter", "before_must_str_for_llm"))).style("width:200px;").tooltip('后缀必须携带其中任一字符串才能触发LLM\n例如:配置。那么这个会触发:你好。')

with ui.row():
input_filter_max_len = ui.input(label='最大单词数', placeholder='最长阅读的英文单词数(空格分隔)', value=config.get("filter", "max_len")).style("width:150px;")
input_filter_max_char_len = ui.input(label='最大单词数', placeholder='最长阅读的字符数,双重过滤,避免溢出', value=config.get("filter", "max_char_len")).style("width:150px;")
Expand Down

0 comments on commit c1abef2

Please sign in to comment.