diff --git a/manifest.yaml b/manifest.yaml index b4f77ac..6b6d9fc 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -1,4 +1,4 @@ -version: 0.0.1 +version: 0.0.2 type: plugin author: quicksandzn name: minimax_kit diff --git a/provider/minimax.yaml b/provider/minimax.yaml index f92d241..047be99 100644 --- a/provider/minimax.yaml +++ b/provider/minimax.yaml @@ -40,6 +40,7 @@ tools: - tools/music_generation.yaml - tools/voice_clone.yaml - tools/video_generation.yaml + - tools/list_voicers.yaml extra: python: source: provider/minimax.py \ No newline at end of file diff --git a/tools/base.py b/tools/base.py index 27af2e2..64c7605 100644 --- a/tools/base.py +++ b/tools/base.py @@ -163,3 +163,10 @@ class MiniMaxBaseTool: params={"GroupId": self.group_id, "purpose": purpose}, ) return response + def get_voice(self, voice_type: str) -> requests.Response: + response = self._request( + "POST", + f"{API_ENDPOINT}/get_voice", + data={"voice_type": voice_type}, + ) + return response \ No newline at end of file diff --git a/tools/list_voicers.py b/tools/list_voicers.py new file mode 100644 index 0000000..ff67009 --- /dev/null +++ b/tools/list_voicers.py @@ -0,0 +1,57 @@ +import json +from typing import Generator, Any +from dify_plugin import Tool +from dify_plugin.entities.tool import ToolInvokeMessage +import datetime + +from tools.base import MiniMaxBaseTool + + +class ListVoicers(Tool): + def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessage, None, None]: + """ + List available models from Fish Audio + """ + api_key = self.runtime.credentials.get("api_key") + group_id = self.runtime.credentials.get("group_id") + minimax = MiniMaxBaseTool(api_key=api_key, group_id=group_id) + voice_type = tool_parameters.get("voice_type") + response = minimax.get_voice( + voice_type=voice_type + ) + if response.status_code != 200: + yield self.create_text_message( + f"Get voice failed {response.status_code} {response.text}" + ) + return + status_code = response.json().get("base_resp", {}).get("status_code", -1) + if status_code != 0: + yield self.create_text_message(f"Get voice failed {response.text}") + return + lines = [] + i = 1 + + # 遍历三个类别 + for category in ["system_voice", "voice_cloning", "voice_generation"]: + items = response.json().get(category, []) + if not isinstance(items, list): + continue + lines.append(f"=== Category: {category} ===") + for item in items: + voice_id = item.get("voice_id", "") + voice_name = item.get("voice_name", "无") + desc_list = item.get("description", []) + desc = ";".join(desc_list) if desc_list else "无" + created_time = item.get("created_time", "") + + lines.append( + f"{i}.ID: {voice_id}\n" + f" Voice Name: {voice_name}\n" + f" Description: {desc}\n" + f" Created_time: {created_time}\n" + ) + i += 1 + + yield self.create_text_message("\n\n".join(lines)) + yield self.create_json_message(response.json()) + diff --git a/tools/list_voicers.yaml b/tools/list_voicers.yaml new file mode 100644 index 0000000..ee58f4b --- /dev/null +++ b/tools/list_voicers.yaml @@ -0,0 +1,46 @@ +identity: + name: list_voicers + author: langgenius + label: + en_US: List all voicers + zh_Hans: 列出发音人 +description: + human: + en_US: List all voicers + zh_Hans: 列出发音人 + llm: A tool to list all voicers + +parameters: + - name: voice_type + type: select + required: true + default: all + options: + - value: all + label: + en_US: All + zh_Hans: 所有 + - value: system + label: + en_US: System + zh_Hans: 系统音色 + - value: voice_cloning + label: + en_US: Voice cloning voicers + zh_Hans: 快速复刻的音色 + - value: voice_generation + label: + en_US: Text generation voicers + zh_Hans: 文生音色接口生成的音色 + label: + en_US: Voicer type + zh_Hans: 音色类型 + human_description: + en_US: Voicer type + zh_Hans: 音色类型 + llm_description: Voicer type to list. + form: form + +extra: + python: + source: tools/list_voicers.py