diff --git a/modules/tool/packages/minmax/children/tts/config.ts b/modules/tool/packages/minimax/children/tts/config.ts similarity index 98% rename from modules/tool/packages/minmax/children/tts/config.ts rename to modules/tool/packages/minimax/children/tts/config.ts index 739509f0..1e281c1e 100644 --- a/modules/tool/packages/minmax/children/tts/config.ts +++ b/modules/tool/packages/minimax/children/tts/config.ts @@ -110,7 +110,9 @@ export default defineTool({ renderTypeList: [FlowNodeInputTypeEnum.select, FlowNodeInputTypeEnum.reference], valueType: WorkflowIOValueTypeEnum.string, required: false, + defaultValue: '', list: [ + { label: '自动', value: '' }, { label: '高兴', value: 'happy' }, { label: '悲伤', value: 'sad' }, { label: '愤怒', value: 'angry' }, diff --git a/modules/tool/packages/minmax/children/tts/index.ts b/modules/tool/packages/minimax/children/tts/index.ts similarity index 100% rename from modules/tool/packages/minmax/children/tts/index.ts rename to modules/tool/packages/minimax/children/tts/index.ts diff --git a/modules/tool/packages/minmax/children/tts/src/index.ts b/modules/tool/packages/minimax/children/tts/src/index.ts similarity index 82% rename from modules/tool/packages/minmax/children/tts/src/index.ts rename to modules/tool/packages/minimax/children/tts/src/index.ts index d66c2fc5..5e1c0c8d 100644 --- a/modules/tool/packages/minmax/children/tts/src/index.ts +++ b/modules/tool/packages/minimax/children/tts/src/index.ts @@ -1,17 +1,17 @@ import { z } from 'zod'; import { POST } from '@tool/utils/request'; import { uploadFile } from '@tool/utils/uploadFile'; -import { ErrorCodeMap } from '@tool/packages/minmax/constants'; +import { ErrorCodeMap } from '@tool/packages/minimax/constants'; export const InputType = z.object({ - apiKey: z.string(), + apiKey: z.string().nonempty(), text: z.string().nonempty(), model: z.string().nonempty(), voice_id: z.string(), - speed: z.number(), - vol: z.number(), - pitch: z.number(), - emotion: z.string(), + speed: z.number().min(0.5).max(2), + vol: z.number().min(0.1).max(10), + pitch: z.number().min(-12).max(12), + emotion: z.enum(['', 'happy', 'sad', 'angry', 'fearful', 'disgusted', 'surprised', 'calm']), english_normalization: z.boolean() }); @@ -49,7 +49,7 @@ export async function tool({ speed, vol, pitch, - emotion, + ...(emotion && { emotion }), english_normalization } }, @@ -57,7 +57,7 @@ export async function tool({ headers } ); - console.log(syncData, 223232); + if (syncData.base_resp.status_code !== 0) { return Promise.reject( ErrorCodeMap[syncData.base_resp.status_code as keyof typeof ErrorCodeMap] diff --git a/modules/tool/packages/minmax/children/tts/test/index.test.ts b/modules/tool/packages/minimax/children/tts/test/index.test.ts similarity index 100% rename from modules/tool/packages/minmax/children/tts/test/index.test.ts rename to modules/tool/packages/minimax/children/tts/test/index.test.ts diff --git a/modules/tool/packages/minimax/config.ts b/modules/tool/packages/minimax/config.ts new file mode 100644 index 00000000..77e2889f --- /dev/null +++ b/modules/tool/packages/minimax/config.ts @@ -0,0 +1,26 @@ +import { defineToolSet } from '@tool/type'; +import { ToolTypeEnum } from '@tool/type/tool'; + +export default defineToolSet({ + name: { + 'zh-CN': 'minimax 工具集', + en: 'minimax Tool Set' + }, + courseUrl: 'https://platform.minimaxi.com/document/quick_start', + type: ToolTypeEnum.tools, + description: { + 'zh-CN': 'minimax 工具集, 包含文本转语音、语音转文本、语音合成、语音识别等功能', + en: 'minimax tool set, including text-to-speech, speech-to-text, speech synthesis, speech recognition等功能' + }, + toolDescription: + 'minimax tool set, including text-to-speech, speech-to-text, speech synthesis, speech recognition等功能', + secretInputConfig: [ + { + key: 'apiKey', + label: 'API Key', + description: '可以在 minimax 官网获取', + required: true, + inputType: 'secret' + } + ] +}); diff --git a/modules/tool/packages/minmax/constants.ts b/modules/tool/packages/minimax/constants.ts similarity index 100% rename from modules/tool/packages/minmax/constants.ts rename to modules/tool/packages/minimax/constants.ts diff --git a/modules/tool/packages/minmax/index.ts b/modules/tool/packages/minimax/index.ts similarity index 100% rename from modules/tool/packages/minmax/index.ts rename to modules/tool/packages/minimax/index.ts diff --git a/modules/tool/packages/minmax/logo.png b/modules/tool/packages/minimax/logo.png similarity index 100% rename from modules/tool/packages/minmax/logo.png rename to modules/tool/packages/minimax/logo.png diff --git a/modules/tool/packages/minmax/package.json b/modules/tool/packages/minimax/package.json similarity index 100% rename from modules/tool/packages/minmax/package.json rename to modules/tool/packages/minimax/package.json diff --git a/modules/tool/packages/minmax/config.ts b/modules/tool/packages/minmax/config.ts deleted file mode 100644 index 373b03a4..00000000 --- a/modules/tool/packages/minmax/config.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { defineToolSet } from '@tool/type'; -import { ToolTypeEnum } from '@tool/type/tool'; - -export default defineToolSet({ - name: { - 'zh-CN': 'minmax 工具集', - en: 'minmax Tool Set' - }, - courseUrl: 'https://platform.minimaxi.com/document/quick_start', - type: ToolTypeEnum.tools, - description: { - 'zh-CN': 'minmax 工具集, 包含文本转语音、语音转文本、语音合成、语音识别等功能', - en: 'minmax tool set, including text-to-speech, speech-to-text, speech synthesis, speech recognition等功能' - }, - toolDescription: - 'minmax tool set, including text-to-speech, speech-to-text, speech synthesis, speech recognition等功能', - secretInputConfig: [ - { - key: 'apiKey', - label: 'API Key', - description: '可以在 minmax 官网获取', - required: true, - inputType: 'secret' - } - ] -}); diff --git a/modules/tool/utils/uploadFile.ts b/modules/tool/utils/uploadFile.ts index 2d509929..0daa63d6 100644 --- a/modules/tool/utils/uploadFile.ts +++ b/modules/tool/utils/uploadFile.ts @@ -1,21 +1,37 @@ +import { fileUploadS3Server } from '@/s3'; import type { FileMetadata } from '@/s3/config'; import type { FileInput } from '@/s3/type'; import { parentPort } from 'worker_threads'; export const uploadFile = async (data: FileInput) => { - return new Promise((resolve, reject) => { - global.uploadFileResponseFn = ({ data, error }) => { - if (error) { - reject(error); - } else if (data) { - resolve(data); - } else { - reject('Unknow error'); - } - }; - parentPort?.postMessage({ - type: 'uploadFile', - data + // 判断是否在 worker 线程中 + const isWorkerThread = typeof parentPort !== 'undefined' && parentPort !== null; + + if (isWorkerThread) { + // 在 worker 线程中,通过 parentPort 发送消息 + return new Promise((resolve, reject) => { + const timer = setTimeout(() => { + reject('Upload file timeout'); + }, 120000); + global.uploadFileResponseFn = ({ data, error }) => { + clearTimeout(timer); + if (error) { + reject(error); + } else if (data) { + resolve(data); + } else { + reject('Unknow error'); + } + }; + parentPort?.postMessage({ + type: 'uploadFile', + data + }); + }); + } else { + return await fileUploadS3Server.uploadFileAdvanced({ + ...data, + ...(data.buffer ? { buffer: Buffer.from(data.buffer) } : {}) }); - }); + } };