LLM 模块
MicroPython 应用示例:
from module import LlmModule
def on_keyword_detected():
print("[Keyword] detected")
def on_asr_data_input(data: str, finish: bool, index: int):
print(f"[ASR data] {data}")
def on_llm_data_input(data: str, finish: bool, index: int):
print(f"[LLM data] {data}")
module_llm = LlmModule()
module_llm.begin_voice_assistant()
module_llm.set_voice_assistant_on_keyword_detected_callback(on_keyword_detected)
module_llm.set_voice_assistant_on_asr_data_input_callback(on_asr_data_input)
module_llm.set_voice_assistant_on_llm_data_input_callback(on_llm_data_input)
while True:
module_llm.update()
UiFlow2 应用示例:
class LlmModule
构造函数
- class LlmModule
根据板卡类型初始化 LlmModule,并设置 UART 通信。
UIFLOW2:

Methods
- LlmModule.llm_setup(prompt='', model='qwen2.5-0.5b', response_format='llm.utf-8.stream', input='llm.utf-8.stream', enoutput=True, enkws=True, max_token_len=127, request_id='llm_setup') str
设置 LLM 模块。
- 参数:
- 返回:
setup 命令的结果。
- 返回类型:
UIFLOW2:

- LlmModule.llm_inference(work_id, input_data, request_id='llm_inference') str
使用 LLM 模块执行推理。
UIFLOW2:

- LlmModule.audio_setup(capcard=0, capdevice=0, cap_volume=0.5, playcard=0, playdevice=1, play_volume=0.15, request_id='audio_setup') str
设置音频模块。
- 参数:
- 返回:
setup 命令的结果。
- 返回类型:
UIFLOW2:

- LlmModule.tts_setup(model='single_speaker_english_fast', response_format='tts.base64.wav', input='tts.utf-8.stream', enoutput=True, enkws=True, request_id='tts_setup') str
设置 TTS 模块。
- 参数:
- 返回:
setup 命令的结果。
- 返回类型:
UIFLOW2:

- LlmModule.kws_setup(kws='HELLO', model='sherpa-onnx-kws-zipformer-gigaspeech-3.3M-2024-01-01', response_format='kws.bool', input='sys.pcm', enoutput=True, request_id='kws_setup') str
设置 KWS 模块。
- 参数:
- 返回:
setup 命令的结果。
- 返回类型:
UIFLOW2:

- LlmModule.asr_setup(model='sherpa-ncnn-streaming-zipformer-20M-2023-02-17', response_format='asr.utf-8.stream', input='sys.pcm', enoutput=True, enkws=True, rule1=2.4, rule2=1.2, rule3=30.0, request_id='asr_setup') str
设置 ASR 模块。
- 参数:
- 返回:
setup 命令的结果。
- 返回类型:
UIFLOW2:

- LlmModule.get_latest_audio_work_id() str
获取最新的 Audio 模块工作 id。
- 返回:
最新的 Audio 模块工作 ID。
- 返回类型:
UIFLOW2:

- LlmModule.get_latest_kws_work_id() str
获取最新的 KWS module work id。
- 返回:
最新的 KWS 模块工作 id。
- 返回类型:
UIFLOW2:

- LlmModule.get_latest_error_code() int
获取最新的 ModuleLLM 响应错误码。
- 返回:
最新的 ModuleLLM 响应错误码。
- 返回类型:
UIFLOW2:

- LlmModule.begin_voice_assistant(wake_up_keyword='HELLO', prompt='') bool
开始语音助手。
- 参数:
- 返回:
如果语音助手启动成功则为 True,否则为 False。
- 返回类型:
UIFLOW2:

- LlmModule.set_voice_assistant_on_keyword_detected_callback(on_keyword_detected) None
设置当检测到唤醒关键词时的回调函数。
- 参数:
on_keyword_detected – 在检测到关键字时要执行的回调函数。
UIFLOW2:













