mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-26 00:53:54 +08:00
Merge pull request #817 from GOODDAYDAY/main
update: 增加prompt个性化配置 & 增加vad,asr个性初始化 & 优化日志若干
This commit is contained in:
@@ -285,6 +285,10 @@ class ConnectionHandler:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.bind(tag=TAG).error(f"初始化组件失败: {e}")
|
self.logger.bind(tag=TAG).error(f"初始化组件失败: {e}")
|
||||||
modules = {}
|
modules = {}
|
||||||
|
if modules.get("vad", None) is not None:
|
||||||
|
self.vad = modules["vad"]
|
||||||
|
if modules.get("asr", None) is not None:
|
||||||
|
self.asr = modules["asr"]
|
||||||
if modules.get("tts", None) is not None:
|
if modules.get("tts", None) is not None:
|
||||||
self.tts = modules["tts"]
|
self.tts = modules["tts"]
|
||||||
if modules.get("llm", None) is not None:
|
if modules.get("llm", None) is not None:
|
||||||
@@ -293,6 +297,8 @@ class ConnectionHandler:
|
|||||||
self.intent = modules["intent"]
|
self.intent = modules["intent"]
|
||||||
if modules.get("memory", None) is not None:
|
if modules.get("memory", None) is not None:
|
||||||
self.memory = modules["memory"]
|
self.memory = modules["memory"]
|
||||||
|
if modules.get("prompt", None) is not None:
|
||||||
|
self.change_system_prompt(modules["prompt"])
|
||||||
|
|
||||||
def _initialize_memory(self):
|
def _initialize_memory(self):
|
||||||
"""初始化记忆模块"""
|
"""初始化记忆模块"""
|
||||||
|
|||||||
@@ -222,80 +222,93 @@ def initialize_modules(
|
|||||||
|
|
||||||
# 初始化TTS模块
|
# 初始化TTS模块
|
||||||
if init_tts:
|
if init_tts:
|
||||||
|
select_tts_module = config["selected_module"]["TTS"]
|
||||||
tts_type = (
|
tts_type = (
|
||||||
config["selected_module"]["TTS"]
|
select_tts_module
|
||||||
if "type" not in config["TTS"][config["selected_module"]["TTS"]]
|
if "type" not in config["TTS"][select_tts_module]
|
||||||
else config["TTS"][config["selected_module"]["TTS"]]["type"]
|
else config["TTS"][select_tts_module]["type"]
|
||||||
)
|
)
|
||||||
modules["tts"] = tts.create_instance(
|
modules["tts"] = tts.create_instance(
|
||||||
tts_type,
|
tts_type,
|
||||||
config["TTS"][config["selected_module"]["TTS"]],
|
config["TTS"][select_tts_module],
|
||||||
bool(config.get("delete_audio", True)),
|
bool(config.get("delete_audio", True)),
|
||||||
)
|
)
|
||||||
logger.bind(tag=TAG).info(f"初始化组件: tts成功")
|
logger.bind(tag=TAG).info(f"初始化组件: tts成功 {select_tts_module}")
|
||||||
|
|
||||||
# 初始化LLM模块
|
# 初始化LLM模块
|
||||||
if init_llm:
|
if init_llm:
|
||||||
|
select_llm_module = config["selected_module"]["TTS"]
|
||||||
llm_type = (
|
llm_type = (
|
||||||
config["selected_module"]["LLM"]
|
select_llm_module
|
||||||
if "type" not in config["LLM"][config["selected_module"]["LLM"]]
|
if "type" not in config["LLM"][select_llm_module]
|
||||||
else config["LLM"][config["selected_module"]["LLM"]]["type"]
|
else config["LLM"][select_llm_module]["type"]
|
||||||
)
|
)
|
||||||
modules["llm"] = llm.create_instance(
|
modules["llm"] = llm.create_instance(
|
||||||
llm_type,
|
llm_type,
|
||||||
config["LLM"][config["selected_module"]["LLM"]],
|
config["LLM"][select_llm_module],
|
||||||
)
|
)
|
||||||
logger.bind(tag=TAG).info(f"初始化组件: llm成功")
|
logger.bind(tag=TAG).info(f"初始化组件: llm成功 {select_llm_module}")
|
||||||
|
|
||||||
# 初始化Intent模块
|
# 初始化Intent模块
|
||||||
if init_intent:
|
if init_intent:
|
||||||
|
select_intent_module = config["selected_module"]["Intent"]
|
||||||
intent_type = (
|
intent_type = (
|
||||||
config["selected_module"]["Intent"]
|
select_intent_module
|
||||||
if "type" not in config["Intent"][config["selected_module"]["Intent"]]
|
if "type" not in config["Intent"][select_intent_module]
|
||||||
else config["Intent"][config["selected_module"]["Intent"]]["type"]
|
else config["Intent"][select_intent_module]["type"]
|
||||||
)
|
)
|
||||||
modules["intent"] = intent.create_instance(
|
modules["intent"] = intent.create_instance(
|
||||||
intent_type,
|
intent_type,
|
||||||
config["Intent"][config["selected_module"]["Intent"]],
|
config["Intent"][select_intent_module],
|
||||||
)
|
)
|
||||||
logger.bind(tag=TAG).info(f"初始化组件: intent成功")
|
logger.bind(tag=TAG).info(f"初始化组件: intent成功 {select_intent_module}")
|
||||||
|
|
||||||
# 初始化Memory模块
|
# 初始化Memory模块
|
||||||
if init_memory:
|
if init_memory:
|
||||||
|
select_memory_module = config["selected_module"]["Memory"]
|
||||||
memory_type = (
|
memory_type = (
|
||||||
config["selected_module"]["Memory"]
|
select_memory_module
|
||||||
if "type" not in config["Memory"][config["selected_module"]["Memory"]]
|
if "type" not in config["Memory"][select_memory_module]
|
||||||
else config["Memory"][config["selected_module"]["Memory"]]["type"]
|
else config["Memory"][select_memory_module]["type"]
|
||||||
)
|
)
|
||||||
modules["memory"] = memory.create_instance(
|
modules["memory"] = memory.create_instance(
|
||||||
memory_type,
|
memory_type,
|
||||||
config["Memory"][config["selected_module"]["Memory"]],
|
config["Memory"][select_memory_module],
|
||||||
)
|
)
|
||||||
logger.bind(tag=TAG).info(f"初始化组件: memory成功")
|
logger.bind(tag=TAG).info(f"初始化组件: memory成功 {select_memory_module}")
|
||||||
|
|
||||||
# 初始化VAD模块
|
# 初始化VAD模块
|
||||||
if init_vad:
|
if init_vad:
|
||||||
|
select_vad_module = config["selected_module"]["VAD"]
|
||||||
vad_type = (
|
vad_type = (
|
||||||
config["selected_module"]["VAD"]
|
select_vad_module
|
||||||
if "type" not in config["VAD"][config["selected_module"]["VAD"]]
|
if "type" not in config["VAD"][select_vad_module]
|
||||||
else config["VAD"][config["selected_module"]["VAD"]]["type"]
|
else config["VAD"][select_vad_module]["type"]
|
||||||
)
|
)
|
||||||
modules["vad"] = vad.create_instance(
|
modules["vad"] = vad.create_instance(
|
||||||
vad_type,
|
vad_type,
|
||||||
config["VAD"][config["selected_module"]["VAD"]],
|
config["VAD"][select_vad_module],
|
||||||
)
|
)
|
||||||
logger.bind(tag=TAG).info(f"初始化组件: vad成功")
|
logger.bind(tag=TAG).info(f"初始化组件: vad成功 {select_vad_module}")
|
||||||
|
|
||||||
# 初始化ASR模块
|
# 初始化ASR模块
|
||||||
if init_asr:
|
if init_asr:
|
||||||
|
select_asr_module = config["selected_module"]["ASR"]
|
||||||
asr_type = (
|
asr_type = (
|
||||||
config["selected_module"]["ASR"]
|
select_asr_module
|
||||||
if "type" not in config["ASR"][config["selected_module"]["ASR"]]
|
if "type" not in config["ASR"][select_asr_module]
|
||||||
else config["ASR"][config["selected_module"]["ASR"]]["type"]
|
else config["ASR"][select_asr_module]["type"]
|
||||||
)
|
)
|
||||||
modules["asr"] = asr.create_instance(
|
modules["asr"] = asr.create_instance(
|
||||||
asr_type,
|
asr_type,
|
||||||
config["ASR"][config["selected_module"]["ASR"]],
|
config["ASR"][select_asr_module],
|
||||||
bool(config.get("delete_audio", True)),
|
bool(config.get("delete_audio", True)),
|
||||||
)
|
)
|
||||||
logger.bind(tag=TAG).info(f"初始化组件: asr成功")
|
logger.bind(tag=TAG).info(f"初始化组件: asr成功 {select_asr_module}")
|
||||||
|
|
||||||
|
# 初始化自定义prompt
|
||||||
|
if config["prompt"]:
|
||||||
|
modules["prompt"] = config["prompt"]
|
||||||
|
logger.bind(tag=TAG).info(f"初始化组件: prompt成功 {modules['prompt'][:30]}")
|
||||||
|
|
||||||
return modules
|
return modules
|
||||||
|
|||||||
Reference in New Issue
Block a user