Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/global/core/workflow/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,17 @@ export enum NodeInputKeyEnum {

// Tool
toolData = 'system_toolData',
toolSetData = 'system_toolSetData'
toolSetData = 'system_toolSetData',

// CAMB AI
cambSourceText = 'cambSourceText',
cambSourceLanguage = 'cambSourceLanguage',
cambTargetLanguage = 'cambTargetLanguage',
cambVoiceName = 'cambVoiceName',
cambAudioUrl = 'cambAudioUrl',
cambGender = 'cambGender',
cambVoiceId = 'cambVoiceId',
cambSpeed = 'cambSpeed'
}

export enum NodeOutputKeyEnum {
Expand Down Expand Up @@ -316,6 +326,11 @@ export enum NodeOutputKeyEnum {
// File
fileTitle = 'fileTitle',

// CAMB AI
cambTranslatedText = 'cambTranslatedText',
cambVoiceId = 'cambVoiceId',
cambAudioUrl = 'cambAudioUrl',

// @deprecated
error = 'error'
}
Expand Down
5 changes: 5 additions & 0 deletions packages/global/core/workflow/node/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ export enum FlowNodeTypeEnum {
tool = 'tool',
toolSet = 'toolSet',

// CAMB AI nodes
cambTranslation = 'cambTranslation',
cambVoiceClone = 'cambVoiceClone',
cambTranslatedTTS = 'cambTranslatedTTS',

// child:
appModule = 'appModule',
pluginModule = 'pluginModule',
Expand Down
8 changes: 7 additions & 1 deletion packages/global/core/workflow/template/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ import { CodeNode } from './system/sandbox';
import { TextEditorNode } from './system/textEditor';
import { ToolParamsNode } from './system/toolParams';
import { VariableUpdateNode } from './system/variableUpdate';
import { CambTranslationNode } from './system/cambTranslation';
import { CambVoiceCloneNode } from './system/cambVoiceClone';
import { CambTranslatedTTSNode } from './system/cambTranslatedTTS';

const systemNodes: FlowNodeTemplateType[] = [
AiChatModule,
Expand All @@ -55,7 +58,10 @@ const systemNodes: FlowNodeTemplateType[] = [
IfElseNode,
VariableUpdateNode,
CodeNode,
LoopNode
LoopNode,
CambTranslationNode,
CambVoiceCloneNode,
CambTranslatedTTSNode
];
/* app flow module templates */
export const appSystemModuleTemplates: FlowNodeTemplateType[] = [
Expand Down
87 changes: 87 additions & 0 deletions packages/global/core/workflow/template/system/cambTranslatedTTS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {
FlowNodeInputTypeEnum,
FlowNodeOutputTypeEnum,
FlowNodeTypeEnum
} from '../../node/constant';
import { type FlowNodeTemplateType } from '../../type/node';
import {
WorkflowIOValueTypeEnum,
NodeOutputKeyEnum,
NodeInputKeyEnum,
FlowNodeTemplateTypeEnum
} from '../../constants';
import { i18nT } from '../../../../../web/i18n/utils';

export const CambTranslatedTTSNode: FlowNodeTemplateType = {
id: FlowNodeTypeEnum.cambTranslatedTTS,
templateType: FlowNodeTemplateTypeEnum.tools,
flowNodeType: FlowNodeTypeEnum.cambTranslatedTTS,
showSourceHandle: true,
showTargetHandle: true,
avatar: 'core/workflow/template/httpRequest',
colorSchema: 'teal',
name: i18nT('workflow:camb_translated_tts'),
intro: i18nT('workflow:camb_translated_tts_intro'),
inputs: [
{
key: NodeInputKeyEnum.cambSourceText,
renderTypeList: [FlowNodeInputTypeEnum.textarea, FlowNodeInputTypeEnum.reference],
valueType: WorkflowIOValueTypeEnum.string,
required: true,
label: i18nT('workflow:camb_source_text'),
placeholder: i18nT('workflow:camb_source_text_placeholder')
},
{
key: NodeInputKeyEnum.cambSourceLanguage,
renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
valueType: WorkflowIOValueTypeEnum.string,
required: true,
label: i18nT('workflow:camb_source_language'),
placeholder: 'e.g. 1 (English US)',
description: i18nT('workflow:camb_language_code_desc')
},
{
key: NodeInputKeyEnum.cambTargetLanguage,
renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
valueType: WorkflowIOValueTypeEnum.string,
required: true,
label: i18nT('workflow:camb_target_language'),
placeholder: 'e.g. 139 (Chinese Simplified)',
description: i18nT('workflow:camb_language_code_desc')
},
{
key: NodeInputKeyEnum.cambVoiceId,
renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
valueType: WorkflowIOValueTypeEnum.string,
required: true,
label: i18nT('workflow:camb_voice_id'),
placeholder: i18nT('workflow:camb_voice_id_placeholder')
},
{
key: NodeInputKeyEnum.cambSpeed,
renderTypeList: [FlowNodeInputTypeEnum.numberInput],
valueType: WorkflowIOValueTypeEnum.number,
label: i18nT('workflow:camb_speed'),
defaultValue: 1.0,
min: 0.5,
max: 2.0,
step: 0.1
}
],
outputs: [
{
id: NodeOutputKeyEnum.cambAudioUrl,
key: NodeOutputKeyEnum.cambAudioUrl,
label: i18nT('workflow:camb_audio_url_output'),
type: FlowNodeOutputTypeEnum.static,
valueType: WorkflowIOValueTypeEnum.string
},
{
id: NodeOutputKeyEnum.cambTranslatedText,
key: NodeOutputKeyEnum.cambTranslatedText,
label: i18nT('workflow:camb_translated_text'),
type: FlowNodeOutputTypeEnum.static,
valueType: WorkflowIOValueTypeEnum.string
}
]
};
62 changes: 62 additions & 0 deletions packages/global/core/workflow/template/system/cambTranslation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {
FlowNodeInputTypeEnum,
FlowNodeOutputTypeEnum,
FlowNodeTypeEnum
} from '../../node/constant';
import { type FlowNodeTemplateType } from '../../type/node';
import {
WorkflowIOValueTypeEnum,
NodeOutputKeyEnum,
NodeInputKeyEnum,
FlowNodeTemplateTypeEnum
} from '../../constants';
import { i18nT } from '../../../../../web/i18n/utils';

export const CambTranslationNode: FlowNodeTemplateType = {
id: FlowNodeTypeEnum.cambTranslation,
templateType: FlowNodeTemplateTypeEnum.tools,
flowNodeType: FlowNodeTypeEnum.cambTranslation,
showSourceHandle: true,
showTargetHandle: true,
avatar: 'core/workflow/template/httpRequest',
colorSchema: 'blue',
name: i18nT('workflow:camb_translation'),
intro: i18nT('workflow:camb_translation_intro'),
inputs: [
{
key: NodeInputKeyEnum.cambSourceText,
renderTypeList: [FlowNodeInputTypeEnum.textarea, FlowNodeInputTypeEnum.reference],
valueType: WorkflowIOValueTypeEnum.string,
required: true,
label: i18nT('workflow:camb_source_text'),
placeholder: i18nT('workflow:camb_source_text_placeholder')
},
{
key: NodeInputKeyEnum.cambSourceLanguage,
renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
valueType: WorkflowIOValueTypeEnum.string,
required: true,
label: i18nT('workflow:camb_source_language'),
placeholder: 'e.g. 1 (English US)',
description: i18nT('workflow:camb_language_code_desc')
},
{
key: NodeInputKeyEnum.cambTargetLanguage,
renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
valueType: WorkflowIOValueTypeEnum.string,
required: true,
label: i18nT('workflow:camb_target_language'),
placeholder: 'e.g. 139 (Chinese Simplified)',
description: i18nT('workflow:camb_language_code_desc')
}
],
outputs: [
{
id: NodeOutputKeyEnum.cambTranslatedText,
key: NodeOutputKeyEnum.cambTranslatedText,
label: i18nT('workflow:camb_translated_text'),
type: FlowNodeOutputTypeEnum.static,
valueType: WorkflowIOValueTypeEnum.string
}
]
};
62 changes: 62 additions & 0 deletions packages/global/core/workflow/template/system/cambVoiceClone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {
FlowNodeInputTypeEnum,
FlowNodeOutputTypeEnum,
FlowNodeTypeEnum
} from '../../node/constant';
import { type FlowNodeTemplateType } from '../../type/node';
import {
WorkflowIOValueTypeEnum,
NodeOutputKeyEnum,
NodeInputKeyEnum,
FlowNodeTemplateTypeEnum
} from '../../constants';
import { i18nT } from '../../../../../web/i18n/utils';

export const CambVoiceCloneNode: FlowNodeTemplateType = {
id: FlowNodeTypeEnum.cambVoiceClone,
templateType: FlowNodeTemplateTypeEnum.tools,
flowNodeType: FlowNodeTypeEnum.cambVoiceClone,
showSourceHandle: true,
showTargetHandle: true,
avatar: 'core/workflow/template/httpRequest',
colorSchema: 'purple',
name: i18nT('workflow:camb_voice_clone'),
intro: i18nT('workflow:camb_voice_clone_intro'),
inputs: [
{
key: NodeInputKeyEnum.cambVoiceName,
renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
valueType: WorkflowIOValueTypeEnum.string,
required: true,
label: i18nT('workflow:camb_voice_name'),
placeholder: i18nT('workflow:camb_voice_name_placeholder')
},
{
key: NodeInputKeyEnum.cambAudioUrl,
renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
valueType: WorkflowIOValueTypeEnum.string,
required: true,
label: i18nT('workflow:camb_audio_url'),
placeholder: 'https://example.com/audio.wav'
},
{
key: NodeInputKeyEnum.cambGender,
renderTypeList: [FlowNodeInputTypeEnum.select],
valueType: WorkflowIOValueTypeEnum.string,
label: i18nT('workflow:camb_gender'),
list: [
{ label: 'Male', value: 'male' },
{ label: 'Female', value: 'female' }
]
}
],
outputs: [
{
id: NodeOutputKeyEnum.cambVoiceId,
key: NodeOutputKeyEnum.cambVoiceId,
label: i18nT('workflow:camb_voice_id'),
type: FlowNodeOutputTypeEnum.static,
valueType: WorkflowIOValueTypeEnum.string
}
]
};
8 changes: 8 additions & 0 deletions packages/service/core/workflow/dispatch/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import { dispatchLafRequest } from './tools/runLaf';
import { dispatchUpdateVariable } from './tools/runUpdateVar';
import { dispatchTextEditor } from './tools/textEditor';
import { dispatchRunAgent } from './ai/agent';
import { dispatchCambTranslation } from './tools/cambTranslation';
import { dispatchCambVoiceClone } from './tools/cambVoiceClone';
import { dispatchCambTranslatedTTS } from './tools/cambTranslatedTTS';

export const callbackMap: Record<FlowNodeTypeEnum, Function> = {
[FlowNodeTypeEnum.workflowStart]: dispatchWorkflowStart,
Expand Down Expand Up @@ -78,6 +81,11 @@ export const callbackMap: Record<FlowNodeTypeEnum, Function> = {
[FlowNodeTypeEnum.comment]: () => Promise.resolve(),
[FlowNodeTypeEnum.toolSet]: () => Promise.resolve(),

// CAMB AI nodes
[FlowNodeTypeEnum.cambTranslation]: dispatchCambTranslation,
[FlowNodeTypeEnum.cambVoiceClone]: dispatchCambVoiceClone,
[FlowNodeTypeEnum.cambTranslatedTTS]: dispatchCambTranslatedTTS,

// @deprecated
[FlowNodeTypeEnum.runApp]: dispatchAppRequest
};
66 changes: 66 additions & 0 deletions packages/service/core/workflow/dispatch/tools/cambTranslatedTTS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runtime/constants';
import type { ModuleDispatchProps } from '@fastgpt/global/core/workflow/runtime/type';
import type { NodeInputKeyEnum} from '@fastgpt/global/core/workflow/constants';
import { NodeOutputKeyEnum } from '@fastgpt/global/core/workflow/constants';
import { type DispatchNodeResultType } from '@fastgpt/global/core/workflow/runtime/type';
import { useCambAiServer } from '../../../../thirdProvider/cambAi/index';

type Props = ModuleDispatchProps<{
[NodeInputKeyEnum.cambSourceText]: string;
[NodeInputKeyEnum.cambSourceLanguage]: string;
[NodeInputKeyEnum.cambTargetLanguage]: string;
[NodeInputKeyEnum.cambVoiceId]: string;
[NodeInputKeyEnum.cambSpeed]?: number;
}>;
type Response = DispatchNodeResultType<{
[NodeOutputKeyEnum.cambAudioUrl]: string;
[NodeOutputKeyEnum.cambTranslatedText]: string;
}>;

export const dispatchCambTranslatedTTS = async (
props: Record<string, any>
): Promise<Response> => {
const {
params: {
cambSourceText: sourceText = '',
cambSourceLanguage: sourceLanguage = '1',
cambTargetLanguage: targetLanguage = '139',
cambVoiceId: voiceId = '',
cambSpeed: speed = 1.0
}
} = props as Props;

if (!sourceText || !voiceId) {
return Promise.reject({ message: '[CAMB AI] Source text and voice ID are required' });
}

const apiKey = process.env.CAMB_API_KEY;
if (!apiKey) {
return Promise.reject({ message: '[CAMB AI] CAMB_API_KEY environment variable is required' });
}

const cambServer = useCambAiServer({ apiKey });

const result = await cambServer.translatedTTS({
text: sourceText,
source_language: Number(sourceLanguage),
target_language: Number(targetLanguage),
voice_id: Number(voiceId),
speed
});

return {
data: {
[NodeOutputKeyEnum.cambAudioUrl]: result.audio_url || '',
[NodeOutputKeyEnum.cambTranslatedText]: result.translated_text || ''
},
[DispatchNodeResponseKeyEnum.nodeResponse]: {
sourceText,
translatedText: result.translated_text || '',
audioUrl: result.audio_url || '',
sourceLanguage,
targetLanguage,
voiceId
}
};
};
Loading
Loading