Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: code-based extension (#1477)

zxhlyh7b26c9e2ef0f
diff --git a/web/app/components/app/configuration/toolbox/moderation/form-generation.tsx b/web/app/components/app/configuration/toolbox/moderation/form-generation.tsx
index c072c46d740..39c7bc03478 100644
--- a/web/app/components/app/configuration/toolbox/moderation/form-generation.tsx
+++ b/web/app/components/app/configuration/toolbox/moderation/form-generation.tsx
@@ -60,8 +60,8 @@ const FormGeneration: FC<FormGenerationProps> = ({
defaultValue={value?.[form.variable]}
items={form.options.map((option) => {
return {
- value: option,
- name: option,
+ name: option.label[locale === 'zh-Hans' ? 'zh-Hans' : 'en-US'],
+ value: option.value,
}
})}
onSelect={item => handleFormChange(form.variable, item.value as string)}
diff --git a/web/app/components/app/configuration/toolbox/moderation/moderation-setting-modal.tsx b/web/app/components/app/configuration/toolbox/moderation/moderation-setting-modal.tsx
index 486d61f998d..710a0f637ed 100644
--- a/web/app/components/app/configuration/toolbox/moderation/moderation-setting-modal.tsx
+++ b/web/app/components/app/configuration/toolbox/moderation/moderation-setting-modal.tsx
@@ -91,10 +91,19 @@ const ModerationSettingModal: FC<ModerationSettingModalProps> = ({
const currentProvider = providers.find(provider => provider.key === localeData.type)
const handleDataTypeChange = (type: string) => {
+ let config: undefined | Record<string, any>
+ const currProvider = providers.find(provider => provider.key === type)
+
+ if (systemTypes.findIndex(t => t === type) < 0 && currProvider?.form_schema) {
+ config = currProvider?.form_schema.reduce((prev, next) => {
+ prev[next.variable] = next.default
+ return prev
+ }, {} as Record<string, any>)
+ }
setLocaleData({
...localeData,
type,
- config: undefined,
+ config,
})
}
@@ -198,7 +207,7 @@ const ModerationSettingModal: FC<ModerationSettingModalProps> = ({
if (systemTypes.findIndex(t => t === localeData.type) < 0 && currentProvider?.form_schema) {
for (let i = 0; i < currentProvider.form_schema.length; i++) {
- if (!localeData.config?.[currentProvider.form_schema[i].variable]) {
+ if (!localeData.config?.[currentProvider.form_schema[i].variable] && currentProvider.form_schema[i].required) {
notify({
type: 'error',
message: t('appDebug.errorMessage.valueOfVarRequired', { key: locale === 'en' ? currentProvider.form_schema[i].label['en-US'] : currentProvider.form_schema[i].label['zh-Hans'] }),
diff --git a/web/app/components/app/configuration/tools/external-data-tool-modal.tsx b/web/app/components/app/configuration/tools/external-data-tool-modal.tsx
index 7cdd6e1f7a0..56f823b8bb5 100644
--- a/web/app/components/app/configuration/tools/external-data-tool-modal.tsx
+++ b/web/app/components/app/configuration/tools/external-data-tool-modal.tsx
@@ -67,10 +67,19 @@ const ExternalDataToolModal: FC<ExternalDataToolModalProps> = ({
const currentProvider = providers.find(provider => provider.key === localeData.type)
const handleDataTypeChange = (type: string) => {
+ let config: undefined | Record<string, any>
+ const currProvider = providers.find(provider => provider.key === type)
+
+ if (systemTypes.findIndex(t => t === type) < 0 && currProvider?.form_schema) {
+ config = currProvider?.form_schema.reduce((prev, next) => {
+ prev[next.variable] = next.default
+ return prev
+ }, {} as Record<string, any>)
+ }
setLocaleData({
...localeData,
type,
- config: undefined,
+ config,
})
}
@@ -152,7 +161,7 @@ const ExternalDataToolModal: FC<ExternalDataToolModalProps> = ({
if (systemTypes.findIndex(t => t === localeData.type) < 0 && currentProvider?.form_schema) {
for (let i = 0; i < currentProvider.form_schema.length; i++) {
- if (!localeData.config?.[currentProvider.form_schema[i].variable]) {
+ if (!localeData.config?.[currentProvider.form_schema[i].variable] && currentProvider.form_schema[i].required) {
notify({
type: 'error',
message: t('appDebug.errorMessage.valueOfVarRequired', { key: locale === 'en' ? currentProvider.form_schema[i].label['en-US'] : currentProvider.form_schema[i].label['zh-Hans'] }),
diff --git a/web/i18n/lang/app-debug.en.ts b/web/i18n/lang/app-debug.en.ts
index 98c16070b48..17bf1e85f09 100644
--- a/web/i18n/lang/app-debug.en.ts
+++ b/web/i18n/lang/app-debug.en.ts
@@ -134,7 +134,7 @@ const translation = {
},
moderation: {
title: 'Content moderation',
- description: 'Content moderation',
+ description: 'Secure model output by using moderation API or maintaining a sensitive word list.',
allEnabled: 'INPUT/OUTPUT Content Enabled',
inputEnabled: 'INPUT Content Enabled',
outputEnabled: 'OUTPUT Content Enabled',
diff --git a/web/i18n/lang/app-debug.zh.ts b/web/i18n/lang/app-debug.zh.ts
index fb814d6aeb4..426eebd9f63 100644
--- a/web/i18n/lang/app-debug.zh.ts
+++ b/web/i18n/lang/app-debug.zh.ts
@@ -133,13 +133,13 @@ const translation = {
title: '工具箱',
},
moderation: {
- title: '内容审核',
- description: '内容审核',
- allEnabled: '审核输入/审核输出 内容已启用',
- inputEnabled: '审核输入内容已启用',
- outputEnabled: '审核输出内容已启用',
+ title: '内容审查',
+ description: '您可以调用审查 API 或者维护敏感词库来使模型更安全地输出。',
+ allEnabled: '审查输入/审查输出 内容已启用',
+ inputEnabled: '审查输入内容已启用',
+ outputEnabled: '审查输出内容已启用',
modal: {
- title: '内容审核设置',
+ title: '内容审查设置',
provider: {
title: '类别',
openai: 'OpenAI Moderation',
@@ -155,17 +155,17 @@ const translation = {
line: '行',
},
content: {
- input: '审核输入内容',
- output: '审核输出内容',
+ input: '审查输入内容',
+ output: '审查输出内容',
preset: '预设回复',
placeholder: '这里预设回复内容',
- condition: '审核输入内容和审核输出内容至少启用一项',
+ condition: '审查输入内容和审查输出内容至少启用一项',
fromApi: '预设回复通过 API 返回',
errorMessage: '预设回复不能为空',
supportMarkdown: '支持 Markdown',
},
openaiNotConfig: {
- before: 'OpenAI 内容审核需要在',
+ before: 'OpenAI 内容审查需要在',
after: '中配置 OpenAI API 密钥。',
},
},
diff --git a/web/models/common.ts b/web/models/common.ts
index a508682c81a..a7613ed4cf5 100644
--- a/web/models/common.ts
+++ b/web/models/common.ts
@@ -214,9 +214,10 @@ export type CodeBasedExtensionForm = {
label: I18nText
variable: string
required: boolean
- options: string[]
+ options: { label: I18nText; value: string }[]
default: string
placeholder: string
+ max_length?: number
}
export type CodeBasedExtensionItem = {