-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathtranslate.ts
More file actions
88 lines (86 loc) · 2.84 KB
/
Copy pathtranslate.ts
File metadata and controls
88 lines (86 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { TranslateIcon } from '@/components/icons'
import { AuthMode, type BlockConfig, IntegrationType } from '@/blocks/types'
import {
getModelOptions,
getProviderCredentialSubBlocks,
PROVIDER_CREDENTIAL_INPUTS,
} from '@/blocks/utils'
const getTranslationPrompt = (targetLanguage: string) =>
`Translate the following text into ${targetLanguage || 'English'}. Output ONLY the translated text with no additional commentary, explanations, or notes.`
export const TranslateBlock: BlockConfig = {
type: 'translate',
name: 'Translate',
description: 'Translate text to any language',
authMode: AuthMode.ApiKey,
longDescription: 'Integrate Translate into the workflow. Can translate text to any language.',
docsLink: 'https://docs.sim.ai/integrations/translate',
category: 'blocks',
integrationType: IntegrationType.AI,
bgColor: '#FF4B4B',
icon: TranslateIcon,
subBlocks: [
{
id: 'context',
title: 'Text to Translate',
type: 'long-input',
placeholder: 'Enter the text you want to translate',
required: true,
},
{
id: 'targetLanguage',
title: 'Translate To',
type: 'short-input',
placeholder: 'Enter language (e.g. Spanish, French, etc.)',
required: true,
},
{
id: 'model',
title: 'Model',
type: 'combobox',
placeholder: 'Type or select a model...',
required: true,
options: getModelOptions,
},
...getProviderCredentialSubBlocks(),
{
id: 'systemPrompt',
title: 'System Prompt',
type: 'code',
hidden: true,
value: (params: Record<string, any>) => {
return getTranslationPrompt(params.targetLanguage || 'English')
},
},
],
tools: {
access: ['llm_chat'],
config: {
tool: () => 'llm_chat',
params: (params: Record<string, any>) => ({
model: params.model,
systemPrompt: getTranslationPrompt(params.targetLanguage || 'English'),
context: params.context,
apiKey: params.apiKey,
azureEndpoint: params.azureEndpoint,
azureApiVersion: params.azureApiVersion,
vertexProject: params.vertexProject,
vertexLocation: params.vertexLocation,
vertexCredential: params.vertexCredential,
bedrockAccessKeyId: params.bedrockAccessKeyId,
bedrockSecretKey: params.bedrockSecretKey,
bedrockRegion: params.bedrockRegion,
}),
},
},
inputs: {
context: { type: 'string', description: 'Text to translate' },
targetLanguage: { type: 'string', description: 'Target language' },
...PROVIDER_CREDENTIAL_INPUTS,
systemPrompt: { type: 'string', description: 'Translation instructions' },
},
outputs: {
content: { type: 'string', description: 'Translated text' },
model: { type: 'string', description: 'Model used' },
tokens: { type: 'json', description: 'Token usage' },
},
}