diff --git a/library.json b/library.json index 31f7d6f..564cfb1 100644 --- a/library.json +++ b/library.json @@ -14,7 +14,7 @@ "M5GFX": "*", "ArduinoJson": "*" }, - "version": "1.6.0", + "version": "1.7.0", "frameworks": "arduino", "platforms": "espressif32" } diff --git a/library.properties b/library.properties index 047986e..47c7a41 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=M5ModuleLLM -version=1.6.0 +version=1.7.0 author=M5Stack maintainer=M5Stack sentence=M5ModuleLLM is a library for M5ModuleLLM diff --git a/src/api/api_asr.cpp b/src/api/api_asr.cpp index 2b3d328..e8cac16 100644 --- a/src/api/api_asr.cpp +++ b/src/api/api_asr.cpp @@ -38,6 +38,23 @@ String ApiAsr::setup(ApiAsrSetupConfig_t config, String request_id, String langu } } if (language == "zh_CN") doc["data"]["model"] = "sherpa-ncnn-streaming-zipformer-zh-14M-2023-02-23"; + + for (const auto& pair : config.extra_params) { + const String& key = pair.first; + const String& value = pair.second; + + if (value == "bool_true") { + doc["data"][key] = true; + } else if (value == "bool_false") { + doc["data"][key] = false; + } else if (value.indexOf('.') != -1) { + doc["data"][key] = value.toFloat(); + } else if (value.length() > 0 && (isDigit(value.charAt(0)) || value.charAt(0) == '-')) { + doc["data"][key] = value.toInt(); + } else { + doc["data"][key] = value; + } + } serializeJson(doc, cmd); } diff --git a/src/api/api_asr.h b/src/api/api_asr.h index 0cd34a0..63d01e5 100644 --- a/src/api/api_asr.h +++ b/src/api/api_asr.h @@ -18,6 +18,26 @@ struct ApiAsrSetupConfig_t { float rule1 = 2.4; float rule2 = 1.2; float rule3 = 30.0; + + std::map extra_params; + + template + void setParam(const String& key, T value) + { + extra_params[key] = String(value); + } + + void setParam(const String& key, bool value) + { + extra_params[key] = value ? "bool_true" : "bool_false"; + } + + void setParam(const String& key, float value) + { + char buffer[16]; + dtostrf(value, 1, 6, buffer); + extra_params[key] = String(buffer); + } }; class ApiAsr { diff --git a/src/api/api_audio.cpp b/src/api/api_audio.cpp index caae9ae..5a76872 100644 --- a/src/api/api_audio.cpp +++ b/src/api/api_audio.cpp @@ -27,6 +27,23 @@ String ApiAudio::setup(ApiAudioSetupConfig_t config, String request_id) doc["data"]["playcard"] = config.playcard; doc["data"]["playdevice"] = config.playdevice; doc["data"]["playVolume"] = config.playVolume; + + for (const auto& pair : config.extra_params) { + const String& key = pair.first; + const String& value = pair.second; + + if (value == "bool_true") { + doc["data"][key] = true; + } else if (value == "bool_false") { + doc["data"][key] = false; + } else if (value.indexOf('.') != -1) { + doc["data"][key] = value.toFloat(); + } else if (value.length() > 0 && (isDigit(value.charAt(0)) || value.charAt(0) == '-')) { + doc["data"][key] = value.toInt(); + } else { + doc["data"][key] = value; + } + } serializeJson(doc, cmd); } diff --git a/src/api/api_audio.h b/src/api/api_audio.h index 2bf9eff..9d0c681 100644 --- a/src/api/api_audio.h +++ b/src/api/api_audio.h @@ -16,6 +16,26 @@ struct ApiAudioSetupConfig_t { int playcard = 0; int playdevice = 1; float playVolume = 0.15; + + std::map extra_params; + + template + void setParam(const String& key, T value) + { + extra_params[key] = String(value); + } + + void setParam(const String& key, bool value) + { + extra_params[key] = value ? "bool_true" : "bool_false"; + } + + void setParam(const String& key, float value) + { + char buffer[16]; + dtostrf(value, 1, 6, buffer); + extra_params[key] = String(buffer); + } }; class ApiAudio { diff --git a/src/api/api_camera.cpp b/src/api/api_camera.cpp index 395dc8b..fe2d5af 100644 --- a/src/api/api_camera.cpp +++ b/src/api/api_camera.cpp @@ -26,6 +26,23 @@ String ApiCamera::setup(ApiCameraSetupConfig_t config, String request_id) doc["data"]["enoutput"] = config.enoutput; doc["data"]["frame_width"] = config.frame_width; doc["data"]["frame_height"] = config.frame_height; + + for (const auto& pair : config.extra_params) { + const String& key = pair.first; + const String& value = pair.second; + + if (value == "bool_true") { + doc["data"][key] = true; + } else if (value == "bool_false") { + doc["data"][key] = false; + } else if (value.indexOf('.') != -1) { + doc["data"][key] = value.toFloat(); + } else if (value.length() > 0 && (isDigit(value.charAt(0)) || value.charAt(0) == '-')) { + doc["data"][key] = value.toInt(); + } else { + doc["data"][key] = value; + } + } serializeJson(doc, cmd); } diff --git a/src/api/api_camera.h b/src/api/api_camera.h index 973de50..36d684e 100644 --- a/src/api/api_camera.h +++ b/src/api/api_camera.h @@ -15,6 +15,25 @@ struct ApiCameraSetupConfig_t { bool enoutput = false; int frame_width = 320; int frame_height = 320; + std::map extra_params; + + template + void setParam(const String& key, T value) + { + extra_params[key] = String(value); + } + + void setParam(const String& key, bool value) + { + extra_params[key] = value ? "bool_true" : "bool_false"; + } + + void setParam(const String& key, float value) + { + char buffer[16]; + dtostrf(value, 1, 6, buffer); + extra_params[key] = String(buffer); + } }; class ApiCamera { diff --git a/src/api/api_depth_anything.cpp b/src/api/api_depth_anything.cpp index 85d0a97..68a111c 100644 --- a/src/api/api_depth_anything.cpp +++ b/src/api/api_depth_anything.cpp @@ -28,6 +28,23 @@ String ApiDepthAnything::setup(ApiDepthAnythingSetupConfig_t config, String requ inputArray.add(str); } doc["data"]["enoutput"] = config.enoutput; + + for (const auto& pair : config.extra_params) { + const String& key = pair.first; + const String& value = pair.second; + + if (value == "bool_true") { + doc["data"][key] = true; + } else if (value == "bool_false") { + doc["data"][key] = false; + } else if (value.indexOf('.') != -1) { + doc["data"][key] = value.toFloat(); + } else if (value.length() > 0 && (isDigit(value.charAt(0)) || value.charAt(0) == '-')) { + doc["data"][key] = value.toInt(); + } else { + doc["data"][key] = value; + } + } serializeJson(doc, cmd); } diff --git a/src/api/api_depth_anything.h b/src/api/api_depth_anything.h index 06f0b99..d5315f2 100644 --- a/src/api/api_depth_anything.h +++ b/src/api/api_depth_anything.h @@ -13,6 +13,25 @@ struct ApiDepthAnythingSetupConfig_t { String response_format = "jpeg.base64.stream"; std::vector input = {"depth_anything.jpeg.raw"}; bool enoutput = true; + std::map extra_params; + + template + void setParam(const String& key, T value) + { + extra_params[key] = String(value); + } + + void setParam(const String& key, bool value) + { + extra_params[key] = value ? "bool_true" : "bool_false"; + } + + void setParam(const String& key, float value) + { + char buffer[16]; + dtostrf(value, 1, 6, buffer); + extra_params[key] = String(buffer); + } }; class ApiDepthAnything { diff --git a/src/api/api_kws.cpp b/src/api/api_kws.cpp index 1fab882..edcd2c4 100644 --- a/src/api/api_kws.cpp +++ b/src/api/api_kws.cpp @@ -35,6 +35,23 @@ String ApiKws::setup(ApiKwsSetupConfig_t config, String request_id, String langu } } if (language == "zh_CN") doc["data"]["model"] = "sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01"; + + for (const auto& pair : config.extra_params) { + const String& key = pair.first; + const String& value = pair.second; + + if (value == "bool_true") { + doc["data"][key] = true; + } else if (value == "bool_false") { + doc["data"][key] = false; + } else if (value.indexOf('.') != -1) { + doc["data"][key] = value.toFloat(); + } else if (value.length() > 0 && (isDigit(value.charAt(0)) || value.charAt(0) == '-')) { + doc["data"][key] = value.toInt(); + } else { + doc["data"][key] = value; + } + } serializeJson(doc, cmd); } diff --git a/src/api/api_kws.h b/src/api/api_kws.h index 71dc51c..e60d67e 100644 --- a/src/api/api_kws.h +++ b/src/api/api_kws.h @@ -15,6 +15,25 @@ struct ApiKwsSetupConfig_t { String response_format = "kws.bool"; std::vector input = {"sys.pcm"}; bool enoutput = true; + std::map extra_params; + + template + void setParam(const String& key, T value) + { + extra_params[key] = String(value); + } + + void setParam(const String& key, bool value) + { + extra_params[key] = value ? "bool_true" : "bool_false"; + } + + void setParam(const String& key, float value) + { + char buffer[16]; + dtostrf(value, 1, 6, buffer); + extra_params[key] = String(buffer); + } }; class ApiKws { diff --git a/src/api/api_llm.cpp b/src/api/api_llm.cpp index d88f497..261d6d4 100644 --- a/src/api/api_llm.cpp +++ b/src/api/api_llm.cpp @@ -37,6 +37,23 @@ String ApiLlm::setup(ApiLlmSetupConfig_t config, String request_id) inputArray.add(str); } } + + for (const auto& pair : config.extra_params) { + const String& key = pair.first; + const String& value = pair.second; + + if (value == "bool_true") { + doc["data"][key] = true; + } else if (value == "bool_false") { + doc["data"][key] = false; + } else if (value.indexOf('.') != -1) { + doc["data"][key] = value.toFloat(); + } else if (value.length() > 0 && (isDigit(value.charAt(0)) || value.charAt(0) == '-')) { + doc["data"][key] = value.toInt(); + } else { + doc["data"][key] = value; + } + } serializeJson(doc, cmd); } diff --git a/src/api/api_llm.h b/src/api/api_llm.h index 45a3455..ba36cfa 100644 --- a/src/api/api_llm.h +++ b/src/api/api_llm.h @@ -18,6 +18,26 @@ struct ApiLlmSetupConfig_t { bool enkws = true; int max_token_len = 127; // int max_token_len = 512; + + std::map extra_params; + + template + void setParam(const String& key, T value) + { + extra_params[key] = String(value); + } + + void setParam(const String& key, bool value) + { + extra_params[key] = value ? "bool_true" : "bool_false"; + } + + void setParam(const String& key, float value) + { + char buffer[16]; + dtostrf(value, 1, 6, buffer); + extra_params[key] = String(buffer); + } }; class ApiLlm { diff --git a/src/api/api_melotts.cpp b/src/api/api_melotts.cpp index 17601c8..5d5efad 100644 --- a/src/api/api_melotts.cpp +++ b/src/api/api_melotts.cpp @@ -44,6 +44,23 @@ String ApiMelotts::setup(ApiMelottsSetupConfig_t config, String request_id, Stri } doc["data"]["enoutput"] = config.enoutput; doc["data"]["enaudio"] = config.enaudio; + + for (const auto& pair : config.extra_params) { + const String& key = pair.first; + const String& value = pair.second; + + if (value == "bool_true") { + doc["data"][key] = true; + } else if (value == "bool_false") { + doc["data"][key] = false; + } else if (value.indexOf('.') != -1) { + doc["data"][key] = value.toFloat(); + } else if (value.length() > 0 && (isDigit(value.charAt(0)) || value.charAt(0) == '-')) { + doc["data"][key] = value.toInt(); + } else { + doc["data"][key] = value; + } + } serializeJson(doc, cmd); } diff --git a/src/api/api_melotts.h b/src/api/api_melotts.h index 2708c82..70f7585 100644 --- a/src/api/api_melotts.h +++ b/src/api/api_melotts.h @@ -15,6 +15,25 @@ struct ApiMelottsSetupConfig_t { std::vector input = {"tts.utf-8.stream"}; bool enoutput = false; bool enaudio = true; + std::map extra_params; + + template + void setParam(const String& key, T value) + { + extra_params[key] = String(value); + } + + void setParam(const String& key, bool value) + { + extra_params[key] = value ? "bool_true" : "bool_false"; + } + + void setParam(const String& key, float value) + { + char buffer[16]; + dtostrf(value, 1, 6, buffer); + extra_params[key] = String(buffer); + } }; class ApiMelotts { diff --git a/src/api/api_tts.cpp b/src/api/api_tts.cpp index 84823da..fde7dc6 100644 --- a/src/api/api_tts.cpp +++ b/src/api/api_tts.cpp @@ -49,6 +49,23 @@ String ApiTts::setup(ApiTtsSetupConfig_t config, String request_id, String langu doc["data"]["model"] = "single_speaker_fast"; } } + + for (const auto& pair : config.extra_params) { + const String& key = pair.first; + const String& value = pair.second; + + if (value == "bool_true") { + doc["data"][key] = true; + } else if (value == "bool_false") { + doc["data"][key] = false; + } else if (value.indexOf('.') != -1) { + doc["data"][key] = value.toFloat(); + } else if (value.length() > 0 && (isDigit(value.charAt(0)) || value.charAt(0) == '-')) { + doc["data"][key] = value.toInt(); + } else { + doc["data"][key] = value; + } + } serializeJson(doc, cmd); } diff --git a/src/api/api_tts.h b/src/api/api_tts.h index 80aea4e..681450f 100644 --- a/src/api/api_tts.h +++ b/src/api/api_tts.h @@ -16,6 +16,26 @@ struct ApiTtsSetupConfig_t { bool enoutput = false; bool enaudio = true; bool enkws = true; + + std::map extra_params; + + template + void setParam(const String& key, T value) + { + extra_params[key] = String(value); + } + + void setParam(const String& key, bool value) + { + extra_params[key] = value ? "bool_true" : "bool_false"; + } + + void setParam(const String& key, float value) + { + char buffer[16]; + dtostrf(value, 1, 6, buffer); + extra_params[key] = String(buffer); + } }; class ApiTts { diff --git a/src/api/api_vad.cpp b/src/api/api_vad.cpp index 9b646af..7536898 100644 --- a/src/api/api_vad.cpp +++ b/src/api/api_vad.cpp @@ -28,6 +28,23 @@ String ApiVad::setup(ApiVadSetupConfig_t config, String request_id) for (const String& str : config.input) { inputArray.add(str); } + + for (const auto& pair : config.extra_params) { + const String& key = pair.first; + const String& value = pair.second; + + if (value == "bool_true") { + doc["data"][key] = true; + } else if (value == "bool_false") { + doc["data"][key] = false; + } else if (value.indexOf('.') != -1) { + doc["data"][key] = value.toFloat(); + } else if (value.length() > 0 && (isDigit(value.charAt(0)) || value.charAt(0) == '-')) { + doc["data"][key] = value.toInt(); + } else { + doc["data"][key] = value; + } + } serializeJson(doc, cmd); } diff --git a/src/api/api_vad.h b/src/api/api_vad.h index 15f2e11..5c57105 100644 --- a/src/api/api_vad.h +++ b/src/api/api_vad.h @@ -14,6 +14,25 @@ struct ApiVadSetupConfig_t { String response_format = "vad.bool"; std::vector input = {"sys.pcm"}; bool enoutput = true; + std::map extra_params; + + template + void setParam(const String& key, T value) + { + extra_params[key] = String(value); + } + + void setParam(const String& key, bool value) + { + extra_params[key] = value ? "bool_true" : "bool_false"; + } + + void setParam(const String& key, float value) + { + char buffer[16]; + dtostrf(value, 1, 6, buffer); + extra_params[key] = String(buffer); + } }; class ApiVad { diff --git a/src/api/api_vlm.cpp b/src/api/api_vlm.cpp index c021150..b43453f 100644 --- a/src/api/api_vlm.cpp +++ b/src/api/api_vlm.cpp @@ -39,6 +39,23 @@ String ApiVlm::setup(ApiVlmSetupConfig_t config, String request_id) } float version = llm_version.substring(1).toFloat(); if (version >= 1.6) doc["data"]["model"] = "internvl2.5-1B-364-ax630c"; + + for (const auto& pair : config.extra_params) { + const String& key = pair.first; + const String& value = pair.second; + + if (value == "bool_true") { + doc["data"][key] = true; + } else if (value == "bool_false") { + doc["data"][key] = false; + } else if (value.indexOf('.') != -1) { + doc["data"][key] = value.toFloat(); + } else if (value.length() > 0 && (isDigit(value.charAt(0)) || value.charAt(0) == '-')) { + doc["data"][key] = value.toInt(); + } else { + doc["data"][key] = value; + } + } serializeJson(doc, cmd); } diff --git a/src/api/api_vlm.h b/src/api/api_vlm.h index 95d8932..d75886d 100644 --- a/src/api/api_vlm.h +++ b/src/api/api_vlm.h @@ -18,6 +18,26 @@ struct ApiVlmSetupConfig_t { bool enkws = true; // int max_token_len = 127; int max_token_len = 255; + + std::map extra_params; + + template + void setParam(const String& key, T value) + { + extra_params[key] = String(value); + } + + void setParam(const String& key, bool value) + { + extra_params[key] = value ? "bool_true" : "bool_false"; + } + + void setParam(const String& key, float value) + { + char buffer[16]; + dtostrf(value, 1, 6, buffer); + extra_params[key] = String(buffer); + } }; class ApiVlm { diff --git a/src/api/api_whisper.cpp b/src/api/api_whisper.cpp index 3b8f2f9..efc0cf1 100644 --- a/src/api/api_whisper.cpp +++ b/src/api/api_whisper.cpp @@ -29,6 +29,23 @@ String ApiWhisper::setup(ApiWhisperSetupConfig_t config, String request_id, Stri for (const String& str : config.input) { inputArray.add(str); } + + for (const auto& pair : config.extra_params) { + const String& key = pair.first; + const String& value = pair.second; + + if (value == "bool_true") { + doc["data"][key] = true; + } else if (value == "bool_false") { + doc["data"][key] = false; + } else if (value.indexOf('.') != -1) { + doc["data"][key] = value.toFloat(); + } else if (value.length() > 0 && (isDigit(value.charAt(0)) || value.charAt(0) == '-')) { + doc["data"][key] = value.toInt(); + } else { + doc["data"][key] = value; + } + } serializeJson(doc, cmd); } diff --git a/src/api/api_whisper.h b/src/api/api_whisper.h index 40a5c2d..ee178f9 100644 --- a/src/api/api_whisper.h +++ b/src/api/api_whisper.h @@ -15,6 +15,26 @@ struct ApiWhisperSetupConfig_t { String language = "en"; std::vector input = {"sys.pcm"}; bool enoutput = true; + + std::map extra_params; + + template + void setParam(const String& key, T value) + { + extra_params[key] = String(value); + } + + void setParam(const String& key, bool value) + { + extra_params[key] = value ? "bool_true" : "bool_false"; + } + + void setParam(const String& key, float value) + { + char buffer[16]; + dtostrf(value, 1, 6, buffer); + extra_params[key] = String(buffer); + } }; class ApiWhisper { diff --git a/src/api/api_yolo.cpp b/src/api/api_yolo.cpp index e7bdbe9..c61d023 100644 --- a/src/api/api_yolo.cpp +++ b/src/api/api_yolo.cpp @@ -28,6 +28,23 @@ String ApiYolo::setup(ApiYoloSetupConfig_t config, String request_id) inputArray.add(str); } doc["data"]["enoutput"] = config.enoutput; + + for (const auto& pair : config.extra_params) { + const String& key = pair.first; + const String& value = pair.second; + + if (value == "bool_true") { + doc["data"][key] = true; + } else if (value == "bool_false") { + doc["data"][key] = false; + } else if (value.indexOf('.') != -1) { + doc["data"][key] = value.toFloat(); + } else if (value.length() > 0 && (isDigit(value.charAt(0)) || value.charAt(0) == '-')) { + doc["data"][key] = value.toInt(); + } else { + doc["data"][key] = value; + } + } serializeJson(doc, cmd); } diff --git a/src/api/api_yolo.h b/src/api/api_yolo.h index ebccc1a..fe23c3a 100644 --- a/src/api/api_yolo.h +++ b/src/api/api_yolo.h @@ -13,6 +13,26 @@ struct ApiYoloSetupConfig_t { String response_format = "yolo.box.stream"; std::vector input = {"yolo.jpeg.base64"}; bool enoutput = true; + + std::map extra_params; + + template + void setParam(const String& key, T value) + { + extra_params[key] = String(value); + } + + void setParam(const String& key, bool value) + { + extra_params[key] = value ? "bool_true" : "bool_false"; + } + + void setParam(const String& key, float value) + { + char buffer[16]; + dtostrf(value, 1, 6, buffer); + extra_params[key] = String(buffer); + } }; class ApiYolo { diff --git a/src/utils/comm.h b/src/utils/comm.h index 99c0344..669d300 100644 --- a/src/utils/comm.h +++ b/src/utils/comm.h @@ -6,6 +6,7 @@ #pragma once #include #include +#include namespace m5_module_llm {