Skip to content

Commit 4f6c9e7

Browse files
LittleMouselbuque
authored andcommitted
libs/module/llm.py: Add dynamic parameter list.
Signed-off-by: LittleMouse <[email protected]>
1 parent adb7bc5 commit 4f6c9e7

File tree

1 file changed

+59
-19
lines changed

1 file changed

+59
-19
lines changed

m5stack/libs/module/llm.py

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ def setup(
230230
enkws=True,
231231
max_token_len=127,
232232
request_id="llm_setup",
233+
**kwargs,
233234
) -> str:
234235
cmd = {
235236
"request_id": request_id,
@@ -246,6 +247,7 @@ def setup(
246247
"prompt": prompt,
247248
},
248249
}
250+
cmd["data"].update(kwargs)
249251
success = self._module_msg.send_cmd_and_wait_to_take_msg(
250252
ujson.dumps(cmd), request_id, self._set_llm_work_id, 30000
251253
)
@@ -321,6 +323,7 @@ def setup(
321323
enoutput=True,
322324
max_token_len=256,
323325
request_id="vlm_setup",
326+
**kwargs,
324327
) -> str:
325328
cmd = {
326329
"request_id": request_id,
@@ -336,6 +339,7 @@ def setup(
336339
"prompt": prompt,
337340
},
338341
}
342+
cmd["data"].update(kwargs)
339343
success = self._module_msg.send_cmd_and_wait_to_take_msg(
340344
ujson.dumps(cmd), request_id, self._set_llm_work_id, 30000
341345
)
@@ -420,6 +424,7 @@ def setup(
420424
playdevice=1,
421425
play_volume=0.15,
422426
request_id="audio_setup",
427+
**kwargs,
423428
) -> str:
424429
cmd = {
425430
"request_id": request_id,
@@ -435,7 +440,7 @@ def setup(
435440
"playVolume": play_volume,
436441
},
437442
}
438-
443+
cmd["data"].update(kwargs)
439444
success = self._module_msg.send_cmd_and_wait_to_take_msg(
440445
ujson.dumps(cmd), request_id, self._set_audio_work_id, 5000
441446
)
@@ -468,6 +473,7 @@ def setup(
468473
enoutput=False,
469474
response_format="camera.raw",
470475
request_id="camera_setup",
476+
**kwargs,
471477
) -> str:
472478
cmd = {
473479
"request_id": request_id,
@@ -482,7 +488,7 @@ def setup(
482488
"enoutput": enoutput,
483489
},
484490
}
485-
491+
cmd["data"].update(kwargs)
486492
success = self._module_msg.send_cmd_and_wait_to_take_msg(
487493
ujson.dumps(cmd), request_id, self._set_camera_work_id, 10000
488494
)
@@ -517,6 +523,7 @@ def setup(
517523
enoutput=False,
518524
enkws=False,
519525
request_id="tts_setup",
526+
**kwargs,
520527
) -> str:
521528
cmd = {
522529
"request_id": request_id,
@@ -531,7 +538,7 @@ def setup(
531538
"enkws": enkws,
532539
},
533540
}
534-
541+
cmd["data"].update(kwargs)
535542
success = self._module_msg.send_cmd_and_wait_to_take_msg(
536543
ujson.dumps(cmd), request_id, self._set_llm_work_id, 10000
537544
)
@@ -588,6 +595,7 @@ def setup(
588595
input="tts.utf-8.stream",
589596
enoutput=False,
590597
request_id="melotts_setup",
598+
**kwargs,
591599
) -> str:
592600
cmd = {
593601
"request_id": request_id,
@@ -601,7 +609,7 @@ def setup(
601609
"enoutput": enoutput,
602610
},
603611
}
604-
612+
cmd["data"].update(kwargs)
605613
success = self._module_msg.send_cmd_and_wait_to_take_msg(
606614
ujson.dumps(cmd), request_id, self._set_llm_work_id, 30000
607615
)
@@ -658,6 +666,7 @@ def setup(
658666
enoutput=True,
659667
enaudio=True,
660668
request_id="kws_setup",
669+
**kwargs,
661670
) -> str:
662671
cmd = {
663672
"request_id": request_id,
@@ -673,7 +682,7 @@ def setup(
673682
"kws": kws,
674683
},
675684
}
676-
685+
cmd["data"].update(kwargs)
677686
success = self._module_msg.send_cmd_and_wait_to_take_msg(
678687
ujson.dumps(cmd), request_id, self._set_llm_work_id, 30000
679688
)
@@ -708,6 +717,7 @@ def setup(
708717
rule2=1.2,
709718
rule3=30.0,
710719
request_id="asr_setup",
720+
**kwargs,
711721
) -> str:
712722
cmd = {
713723
"request_id": request_id,
@@ -725,7 +735,7 @@ def setup(
725735
"rule3": rule3,
726736
},
727737
}
728-
738+
cmd["data"].update(kwargs)
729739
success = self._module_msg.send_cmd_and_wait_to_take_msg(
730740
ujson.dumps(cmd), request_id, self._set_llm_work_id, 10000
731741
)
@@ -756,6 +766,7 @@ def setup(
756766
input="sys.pcm",
757767
enoutput=True,
758768
request_id="vad_setup",
769+
**kwargs,
759770
) -> str:
760771
cmd = {
761772
"request_id": request_id,
@@ -769,7 +780,7 @@ def setup(
769780
"enoutput": enoutput,
770781
},
771782
}
772-
783+
cmd["data"].update(kwargs)
773784
success = self._module_msg.send_cmd_and_wait_to_take_msg(
774785
ujson.dumps(cmd), request_id, self._set_llm_work_id, 30000
775786
)
@@ -801,6 +812,7 @@ def setup(
801812
enoutput=True,
802813
language="en",
803814
request_id="whisper_setup",
815+
**kwargs,
804816
) -> str:
805817
cmd = {
806818
"request_id": request_id,
@@ -815,7 +827,7 @@ def setup(
815827
"enoutput": enoutput,
816828
},
817829
}
818-
830+
cmd["data"].update(kwargs)
819831
success = self._module_msg.send_cmd_and_wait_to_take_msg(
820832
ujson.dumps(cmd), request_id, self._set_llm_work_id, 30000
821833
)
@@ -847,6 +859,7 @@ def setup(
847859
input="yolo.jpg.base64",
848860
enoutput=True,
849861
request_id="yolo_setup",
862+
**kwargs,
850863
) -> str:
851864
cmd = {
852865
"request_id": request_id,
@@ -860,7 +873,7 @@ def setup(
860873
"enoutput": enoutput,
861874
},
862875
}
863-
876+
cmd["data"].update(kwargs)
864877
success = self._module_msg.send_cmd_and_wait_to_take_msg(
865878
ujson.dumps(cmd), request_id, self._set_yolo_work_id, 10000
866879
)
@@ -1030,6 +1043,7 @@ def llm_setup(
10301043
enkws=None,
10311044
max_token_len=127,
10321045
request_id="llm_setup",
1046+
**kwargs,
10331047
) -> str:
10341048
if self.version == "v1.0":
10351049
model = "qwen2.5-0.5b"
@@ -1048,7 +1062,15 @@ def llm_setup(
10481062
enkws = bool(enkws)
10491063

10501064
self.latest_llm_work_id = self.llm.setup(
1051-
prompt, model, response_format, input, enoutput, enkws, max_token_len, request_id
1065+
prompt,
1066+
model,
1067+
response_format,
1068+
input,
1069+
enoutput,
1070+
enkws,
1071+
max_token_len,
1072+
request_id,
1073+
**kwargs,
10521074
)
10531075
return self.latest_llm_work_id
10541076

@@ -1066,6 +1088,7 @@ def vlm_setup(
10661088
enkws=None,
10671089
max_token_len=256,
10681090
request_id="vlm_setup",
1091+
**kwargs,
10691092
) -> str:
10701093
if input is None:
10711094
input = ["vlm.utf-8"]
@@ -1076,7 +1099,7 @@ def vlm_setup(
10761099
input.append(enkws)
10771100

10781101
self.latest_vlm_work_id = self.vlm.setup(
1079-
prompt, model, response_format, input, enoutput, max_token_len, request_id
1102+
prompt, model, response_format, input, enoutput, max_token_len, request_id, **kwargs
10801103
)
10811104
return self.latest_vlm_work_id
10821105

@@ -1098,9 +1121,10 @@ def audio_setup(
10981121
playdevice=1,
10991122
play_volume=0.15,
11001123
request_id="audio_setup",
1124+
**kwargs,
11011125
) -> str:
11021126
self.latest_audio_work_id = self.audio.setup(
1103-
capcard, capdevice, cap_volume, playcard, playdevice, play_volume, request_id
1127+
capcard, capdevice, cap_volume, playcard, playdevice, play_volume, request_id, **kwargs
11041128
)
11051129
return self.latest_audio_work_id
11061130

@@ -1112,9 +1136,10 @@ def camera_setup(
11121136
frame_height=320,
11131137
enoutput=False,
11141138
response_format="camera.raw",
1139+
**kwargs,
11151140
) -> str:
11161141
self.latest_camera_work_id = self.camera.setup(
1117-
input, frame_width, frame_height, enoutput, response_format, request_id
1142+
input, frame_width, frame_height, enoutput, response_format, request_id, **kwargs
11181143
)
11191144
return self.latest_camera_work_id
11201145

@@ -1145,6 +1170,7 @@ def tts_setup(
11451170
enoutput=False,
11461171
enkws=None,
11471172
request_id="tts_setup",
1173+
**kwargs,
11481174
) -> str:
11491175
if self.version == "v1.0":
11501176
response_format = "tts.base64.wav"
@@ -1165,7 +1191,7 @@ def tts_setup(
11651191
enkws = bool(enkws)
11661192

11671193
self.latest_tts_work_id = self.tts.setup(
1168-
model, response_format, input, enoutput, enkws, request_id
1194+
model, response_format, input, enoutput, enkws, request_id, **kwargs
11691195
)
11701196
return self.latest_tts_work_id
11711197

@@ -1182,6 +1208,7 @@ def melotts_setup(
11821208
enoutput=False,
11831209
enkws=None,
11841210
request_id="melotts_setup",
1211+
**kwargs,
11851212
) -> str:
11861213
if float(self.version.lstrip("v")) >= 1.6 and model == "melotts_zh-cn":
11871214
model = "melotts-zh-cn"
@@ -1201,7 +1228,7 @@ def melotts_setup(
12011228
input.append(enkws)
12021229

12031230
self.latest_melotts_work_id = self.melotts.setup(
1204-
model, response_format, input, enoutput, request_id
1231+
model, response_format, input, enoutput, request_id, **kwargs
12051232
)
12061233
return self.latest_melotts_work_id
12071234

@@ -1219,11 +1246,12 @@ def kws_setup(
12191246
enoutput=True,
12201247
enaudio=True,
12211248
request_id="kws_setup",
1249+
**kwargs,
12221250
) -> str:
12231251
if language == "zh_CN":
12241252
model = "sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01"
12251253
self.latest_kws_work_id = self.kws.setup(
1226-
kws, model, response_format, input, enoutput, enaudio, request_id
1254+
kws, model, response_format, input, enoutput, enaudio, request_id, **kwargs
12271255
)
12281256
return self.latest_kws_work_id
12291257

@@ -1239,6 +1267,7 @@ def asr_setup(
12391267
rule2=1.2,
12401268
rule3=30.0,
12411269
request_id="asr_setup",
1270+
**kwargs,
12421271
) -> str:
12431272
if input is None:
12441273
input = "sys.pcm" if self.version == "v1.0" else ["sys.pcm"]
@@ -1255,7 +1284,16 @@ def asr_setup(
12551284
enkws = bool(enkws)
12561285

12571286
self.latest_asr_work_id = self.asr.setup(
1258-
model, response_format, input, enoutput, enkws, rule1, rule2, rule3, request_id
1287+
model,
1288+
response_format,
1289+
input,
1290+
enoutput,
1291+
enkws,
1292+
rule1,
1293+
rule2,
1294+
rule3,
1295+
request_id,
1296+
**kwargs,
12591297
)
12601298
return self.latest_asr_work_id
12611299

@@ -1267,6 +1305,7 @@ def vad_setup(
12671305
enoutput=True,
12681306
enkws=None,
12691307
request_id="kws_setup",
1308+
**kwargs,
12701309
) -> str:
12711310
if input is None:
12721311
input = ["sys.pcm"]
@@ -1275,7 +1314,7 @@ def vad_setup(
12751314
input = [input]
12761315
input.append(enkws)
12771316
self.latest_vad_work_id = self.vad.setup(
1278-
model, response_format, input, enoutput, request_id
1317+
model, response_format, input, enoutput, request_id, **kwargs
12791318
)
12801319
return self.latest_vad_work_id
12811320

@@ -1289,6 +1328,7 @@ def whisper_setup(
12891328
enkws=None,
12901329
envad=None,
12911330
request_id="asr_setup",
1331+
**kwargs,
12921332
) -> str:
12931333
if input is None:
12941334
input = ["sys.pcm"]
@@ -1301,7 +1341,7 @@ def whisper_setup(
13011341
input = [input]
13021342
input.append(envad)
13031343
self.latest_whisper_work_id = self.whisper.setup(
1304-
model, response_format, input, enoutput, language, request_id
1344+
model, response_format, input, enoutput, language, request_id, **kwargs
13051345
)
13061346
return self.latest_whisper_work_id
13071347

0 commit comments

Comments
 (0)