pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

Module LLM

Example

Text-to-voice playback is realized by TTS unit

from m5stack import *
from m5ui import *
from uiflow import *
import module

import time

setScreenColor(0x222222)

adding_number = None
tts_text = None

llm_1 = module.get(module.LLM)
llm_1.init(2, tx=17, rx=16)

label0 = M5TextBox(34, 12, "State:", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label1 = M5TextBox(28, 85, "TTS text:", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label2 = M5TextBox(34, 45, "~", lcd.FONT_DejaVu24, 0x16db23, rotate=0)
label3 = M5TextBox(34, 116, "~", lcd.FONT_DejaVu24, 0xfe0101, rotate=0)

# Describe this function...
def make_tts_text():
  global adding_number, tts_text
  adding_number = adding_number + 1
  tts_text = 'x plus x equals to y.'.replace('x', str(adding_number))
  tts_text = tts_text.replace('y', str((adding_number + adding_number)))
  label3.setText(str(tts_text))
  llm_1.tts_inference(llm_1.get_latest_tts_work_id(), tts_text, 10000, 'tts_inference')

label1.setText('Wait ModuleLLM connection..')
while not (llm_1.check_connection()):
  wait(1)
label1.setText('Reset ModuleLLM..')
llm_1.sys_reset(True)
label1.setText('Setup Audio module..')
llm_1.audio_setup(cap_volume=0.5, play_volume=0.15, request_id='audio_setup')
label1.setText('Setup TTS module..')
llm_1.tts_setup(model='single_speaker_english_fast', input='tts.utf-8.stream', enoutput=True, enkws=True, request_id='tts_setup')
adding_number = 0
label1.setText('OK')
while True:
  make_tts_text()
  wait(0.5)
  wait_ms(2)

API

llm_1 = module.get(module.LLM)
llm_1.init(2, tx=17, rx=16)
  • Initialize the Llm module and set up UART communication based on the board type
def llm_1_asr_data_input_event(data, finish, index):
  global asr_data, asr_is_finish, asr_index
  asr_data = data
  asr_is_finish = finish
  asr_index = index
  print('data input')
  • Set up a callback for ASR data input
llm_1.asr_setup(model='2', enoutput=False, enkws=False, rule1=2.4, rule2=1.2, rule3=30, request_id='asr_setup')
  • Set up the ASR module
llm_1.tts_inference(llm_1.get_latest_tts_work_id(), '', 0, 'tts_inference')
  • Use the TTS module to perform inference
llm_1.tts_setup(model='single_speaker_english_fast', input='tts.utf-8.stream', enoutput=True, enkws=True, request_id='tts_setup')
  • Set up the TTS module
llm_1.audio_setup(cap_volume=0.5, play_volume=0.15, request_id='audio_setup')
  • Set up the audio module
print((str('begin voice assistant:') + str((llm_1.begin_voice_assistant('HI JIMMY', 'You are a helpful assistant.')))))
  • Start the voice assistant
def llm_1_llm_data_input_event(data, finish, index):
  global llm_data, llm_is_finish, llm_index
  llm_data = data
  llm_is_finish = finish
  llm_index = index
  print('llm data')
  • Set up a callback for inputting LLM data
llm_1.llm_inference(llm_1.get_latest_llm_work_id(), 'Can I ask you a question?', 'llm_inference')
  • Use the LLM module to perform inference
llm_1.update()
print((str('begin voice assistant:') + str((llm_1.begin_voice_assistant('HI JIMMY', 'You are a helpful assistant.')))))
  • Set up a callback when the wake-up keyword is detected
llm_1.kws_setup(kws='HI JIMMY', model='', enoutput=True, request_id='kws_setup')
  • Set up the KWS module
llm_1.llm_setup(prompt='You are a helpful assistant.', model='2', enoutput=True, enkws=True, max_token_len=127, request_id='llm_setup')
  • Set up the LLM module
    • prompt (str):提示文本
    • model (str):模型名称
    • response_format (str):响应格式
    • input (str):输入格式
    • enoutput (bool):启用输出
    • enkws (bool):启用关键字识别
    • max_token_len (int):最大令牌长度
    • request_id (str):请求 ID
print((str('connection:') + str((llm_1.check_connection()))))
  • Check if the module connections are working properly
print((str('latest asr work id:') + str((llm_1.get_latest_asr_work_id()))))
  • Get the latest ASR module job ID
print((str('latest audio work id:') + str((llm_1.get_latest_audio_work_id()))))
  • Get the latest audio module job ID
print((str('err code:') + str((llm_1.get_latest_error_code()))))
  • Get the latest LLM module response error code
print((str('latest kws work id:') + str((llm_1.get_latest_kws_work_id()))))
  • Get the latest KWS module job ID
print((str('latest llm work id:') + str((llm_1.get_latest_llm_work_id()))))
  • Get the latest LLM module job ID
print((str('latest tts work id:') + str((llm_1.get_latest_tts_work_id()))))
  • Get the latest TTS module job ID
llm_1.clear_response_msg_list()
  • Get the corresponding data list
llm_1.sys_ping()
  • Send a ping to the system and get the response code
llm_1.update()
  • Update the LLM module's received response message
llm_1.sys_reboot()
  • Restart the system
llm_1.sys_reset(True)
  • Reset the system
print((str('response:') + str((llm_1.get_response_msg_list()))))
  • Get the module's response message list
On This Page