Skip to content

Commit

Permalink
Merge pull request #814 from Ikaros-521/owner
Browse files Browse the repository at this point in the history
按键映射板块 文案通用也支持礼物答谢相关的变量
  • Loading branch information
Ikaros-521 authored May 12, 2024
2 parents ffa8a8b + e5fde7b commit 715e81c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 31 deletions.
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,8 @@
"感谢{gift_name}",
"感谢{username}送的{gift_name}",
"我最喜欢{gift_name}了,谢谢",
"送我{gift_name},你真是个好人"
"送我{gift_name},你真是个好人",
"感谢{username}送的{gift_num}个单价{unit_price}元,总价{total_price}元的{gift_name}喵"
],
"local_audio": []
},
Expand Down
50 changes: 31 additions & 19 deletions config.json.bak
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@
"before_filter_str": [
"#"
],
"after_filter_str": [],
"after_filter_str": [
"#"
],
"badwords": {
"enable": true,
"discard": false,
Expand Down Expand Up @@ -190,7 +192,7 @@
"gift_random": true,
"gift_copy": [
"感谢{username}送的{gift_name},爱你么么哒",
"感谢{username}送的{gift_name}喵",
"感谢{username}送的{gift_num}个单价{unit_price}元,总价{total_price}元的{gift_name}喵",
"就送个{gift_name}?看不起谁呢?"
],
"follow_enable": true,
Expand Down Expand Up @@ -262,7 +264,7 @@
"max_new_tokens": 250,
"history_enable": true,
"history_max_len": 20,
"preset": "现在你正在blibili进行直播。"
"preset": "请扮演一个AI虚拟主播。不要回答任何敏感问题!不要强调你是主播,只需要回答问题!"
},
"sparkdesk": {
"type": "api",
Expand Down Expand Up @@ -331,7 +333,7 @@
"knowledge_base": {
"knowledge_base_name": "ikaros",
"top_k": 3,
"score_threshold": 1,
"score_threshold": 1.0,
"stream": false,
"model_name": "chatglm3-6b-int4",
"temperature": 0.7,
Expand Down Expand Up @@ -445,7 +447,9 @@
"app_secret": "",
"api_ip_port": "http://127.0.0.1:8777",
"user_id": "zzp",
"kb_ids": ["KB938fb10c8a924530abf1754ea620b7cd"],
"kb_ids": [
"KB938fb10c8a924530abf1754ea620b7cd"
],
"history_enable": true,
"history_max_len": 300
},
Expand Down Expand Up @@ -669,7 +673,7 @@
"api_ip_port": "http://127.0.0.1:9988",
"voice": "cn-nan.wav",
"language": "zh-cn",
"speed": 1
"speed": 1.0
},
"azure_tts": {
"subscription_key": "",
Expand Down Expand Up @@ -723,7 +727,7 @@
"enable": false,
"similarity": 0.5,
"start_cmd": [
"点歌 ",
"点歌",
"唱首",
"唱个"
],
Expand Down Expand Up @@ -776,23 +780,23 @@
{
"file_path": "data/copywriting/",
"audio_path": "out/copywriting/",
"continuous_play_num": 2,
"max_play_time": 10.0,
"play_list": [
"test.wav",
"伊卡日语介绍.wav",
"吐槽.wav"
],
"continuous_play_num": 2,
"max_play_time": 10.0
]
},
{
"file_path": "data/copywriting2/",
"audio_path": "out/copywriting2/",
"continuous_play_num": 2,
"max_play_time": 3.0,
"play_list": [
"test.wav",
"test2.wav"
],
"continuous_play_num": 2,
"max_play_time": 3.0
]
}
],
"audio_interval": 5.0,
Expand All @@ -807,7 +811,7 @@
"key_listener_enable": false,
"device_index": "1",
"no_recording_during_playback": true,
"no_recording_during_playback_sleep_interval": 1,
"no_recording_during_playback_sleep_interval": 1.0,
"username": "主人",
"type": "google",
"continuous_talk": false,
Expand Down Expand Up @@ -886,7 +890,9 @@
"idle_time_max": 60,
"wait_play_audio_num_threshold": 10,
"idle_time_reduce_to": 0,
"trigger_type": ["comment"],
"trigger_type": [
"comment"
],
"copywriting": {
"enable": false,
"random": true,
Expand Down Expand Up @@ -997,7 +1003,8 @@
"gift_price_interval": "0-1",
"copywriting": [
"感谢{username}的{gift_name},获得{get_integral}点积分",
"感谢{username}的{gift_name}"
"感谢{username}的{gift_name}",
"感谢{username}送的{gift_num}个单价{unit_price}元,总价{total_price}元的{gift_name}喵"
]
},
{
Expand Down Expand Up @@ -1141,7 +1148,8 @@
"感谢{gift_name}",
"感谢{username}送的{gift_name}",
"我最喜欢{gift_name}了,谢谢",
"送我{gift_name},你真是个好人"
"送我{gift_name},你真是个好人",
"感谢{username}送的{gift_num}个单价{unit_price}元,总价{total_price}元的{gift_name}喵"
],
"local_audio": []
},
Expand Down Expand Up @@ -1485,13 +1493,17 @@
"enable": false,
"name": "captions_printer",
"executable": "E://GitHub_pro//captions_printer//pkg//captions_printer-v4.1//Miniconda3//python.exe",
"parameters": ["E://GitHub_pro//captions_printer//pkg//captions_printer-v4.1//app.py"]
"parameters": [
"E://GitHub_pro//captions_printer//pkg//captions_printer-v4.1//app.py"
]
},
{
"enable": false,
"name": "audio_player",
"executable": "E://GitHub_pro//audio_player//pkg//audio_player_v2-20240320//Miniconda3//python.exe",
"parameters": ["E://GitHub_pro//audio_player//pkg//audio_player_v2-20240320//app.py"]
"parameters": [
"E://GitHub_pro//audio_player//pkg//audio_player_v2-20240320//app.py"
]
}
],
"assistant_anchor": {
Expand Down
24 changes: 13 additions & 11 deletions utils/my_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1690,15 +1690,19 @@ def get_a_copywriting_and_audio_synthesis(key_mapping_config, data):
# 随机获取一个文案
tmp = random.choice(key_mapping_config["copywriting"])

# 假设有多个未知变量,用户可以在此处定义动态变量
variables = {
'username': data["username"],
'gift_name': data["gift_name"] if "gift_name" in data else ""
}

# 使用字典进行字符串替换
if any(var in tmp for var in variables):
tmp = tmp.format(**{var: value for var, value in variables.items() if var in tmp})
# 括号语法替换
tmp = My_handle.common.brackets_text_randomize(tmp)

# 动态变量替换
data_json = {
"username": data["username"],
"gift_name": data["gift_name"],
'gift_num': data["num"],
'unit_price': data["unit_price"],
'total_price': data["total_price"],
'cur_time': My_handle.common.get_bj_time(5),
}
tmp = self.common.dynamic_variable_replacement(tmp, data_json)

# 音频合成时需要用到的重要数据
message = {
Expand Down Expand Up @@ -2386,8 +2390,6 @@ def gift_handle(self, data):
}
resp_content = self.common.dynamic_variable_replacement(resp_content, data_json)

# 括号语法替换
resp_content = My_handle.common.brackets_text_randomize(resp_content)

message = {
"type": "gift",
Expand Down

0 comments on commit 715e81c

Please sign in to comment.