You've already forked ModuleLLM-OpenAI-Plugin
mirror of
https://github.com/m5stack/ModuleLLM-OpenAI-Plugin.git
synced 2026-05-20 11:37:26 -07:00
[feat] The tts backend supports model switching.
This commit is contained in:
@@ -62,6 +62,7 @@ class ModelDispatcher:
|
||||
self.backends = {}
|
||||
self.llm_models = set()
|
||||
self.asr_models = set()
|
||||
self.tts_models = set()
|
||||
self.lock = asyncio.Lock()
|
||||
|
||||
async def get_backend(self, model_name):
|
||||
@@ -84,7 +85,14 @@ class ModelDispatcher:
|
||||
elif model_config["type"] == "vision_model":
|
||||
self.backends[model_name] = VisionModelBackend(model_config)
|
||||
elif model_config["type"] == "tts":
|
||||
if model_name not in self.tts_models:
|
||||
for old_model_name in list(self.tts_models):
|
||||
old_instance = self.backends.pop(old_model_name, None)
|
||||
if old_instance:
|
||||
await old_instance.close()
|
||||
self.asr_models.clear()
|
||||
self.backends[model_name] = TtsClientBackend(model_config)
|
||||
self.tts_models.add(model_name)
|
||||
elif model_config["type"] == "asr":
|
||||
if model_name not in self.asr_models:
|
||||
for old_model_name in list(self.asr_models):
|
||||
|
||||
@@ -82,6 +82,17 @@ class TtsClientBackend(BaseModelBackend):
|
||||
async with self._pool_lock:
|
||||
self._client_pool.append(client)
|
||||
|
||||
async def close(self):
|
||||
for task in self._active_tasks:
|
||||
task.cancel()
|
||||
if self._active_tasks:
|
||||
await asyncio.wait(self._active_tasks, timeout=2)
|
||||
for client in self._client_pool:
|
||||
client.exit()
|
||||
self._client_pool.clear()
|
||||
self._active_clients.clear()
|
||||
self._inference_executor.shutdown(wait=False)
|
||||
|
||||
def _encode_stream_chunk(self, pcm_data: bytes, format: str) -> bytes:
|
||||
if format == "pcm":
|
||||
return pcm_data
|
||||
|
||||
Reference in New Issue
Block a user