Unverified Commit 7b26c9e2 authored by zxhlyh's avatar zxhlyh Committed by GitHub

fix: code-based extension (#1477)

parent 6bcafdbc
...@@ -60,8 +60,8 @@ const FormGeneration: FC<FormGenerationProps> = ({ ...@@ -60,8 +60,8 @@ const FormGeneration: FC<FormGenerationProps> = ({
defaultValue={value?.[form.variable]} defaultValue={value?.[form.variable]}
items={form.options.map((option) => { items={form.options.map((option) => {
return { return {
value: option, name: option.label[locale === 'zh-Hans' ? 'zh-Hans' : 'en-US'],
name: option, value: option.value,
} }
})} })}
onSelect={item => handleFormChange(form.variable, item.value as string)} onSelect={item => handleFormChange(form.variable, item.value as string)}
......
...@@ -91,10 +91,19 @@ const ModerationSettingModal: FC<ModerationSettingModalProps> = ({ ...@@ -91,10 +91,19 @@ const ModerationSettingModal: FC<ModerationSettingModalProps> = ({
const currentProvider = providers.find(provider => provider.key === localeData.type) const currentProvider = providers.find(provider => provider.key === localeData.type)
const handleDataTypeChange = (type: string) => { 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({ setLocaleData({
...localeData, ...localeData,
type, type,
config: undefined, config,
}) })
} }
...@@ -198,7 +207,7 @@ const ModerationSettingModal: FC<ModerationSettingModalProps> = ({ ...@@ -198,7 +207,7 @@ const ModerationSettingModal: FC<ModerationSettingModalProps> = ({
if (systemTypes.findIndex(t => t === localeData.type) < 0 && currentProvider?.form_schema) { if (systemTypes.findIndex(t => t === localeData.type) < 0 && currentProvider?.form_schema) {
for (let i = 0; i < currentProvider.form_schema.length; i++) { 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({ notify({
type: 'error', type: 'error',
message: t('appDebug.errorMessage.valueOfVarRequired', { key: locale === 'en' ? currentProvider.form_schema[i].label['en-US'] : currentProvider.form_schema[i].label['zh-Hans'] }), message: t('appDebug.errorMessage.valueOfVarRequired', { key: locale === 'en' ? currentProvider.form_schema[i].label['en-US'] : currentProvider.form_schema[i].label['zh-Hans'] }),
......
...@@ -67,10 +67,19 @@ const ExternalDataToolModal: FC<ExternalDataToolModalProps> = ({ ...@@ -67,10 +67,19 @@ const ExternalDataToolModal: FC<ExternalDataToolModalProps> = ({
const currentProvider = providers.find(provider => provider.key === localeData.type) const currentProvider = providers.find(provider => provider.key === localeData.type)
const handleDataTypeChange = (type: string) => { 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({ setLocaleData({
...localeData, ...localeData,
type, type,
config: undefined, config,
}) })
} }
...@@ -152,7 +161,7 @@ const ExternalDataToolModal: FC<ExternalDataToolModalProps> = ({ ...@@ -152,7 +161,7 @@ const ExternalDataToolModal: FC<ExternalDataToolModalProps> = ({
if (systemTypes.findIndex(t => t === localeData.type) < 0 && currentProvider?.form_schema) { if (systemTypes.findIndex(t => t === localeData.type) < 0 && currentProvider?.form_schema) {
for (let i = 0; i < currentProvider.form_schema.length; i++) { 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({ notify({
type: 'error', type: 'error',
message: t('appDebug.errorMessage.valueOfVarRequired', { key: locale === 'en' ? currentProvider.form_schema[i].label['en-US'] : currentProvider.form_schema[i].label['zh-Hans'] }), message: t('appDebug.errorMessage.valueOfVarRequired', { key: locale === 'en' ? currentProvider.form_schema[i].label['en-US'] : currentProvider.form_schema[i].label['zh-Hans'] }),
......
...@@ -134,7 +134,7 @@ const translation = { ...@@ -134,7 +134,7 @@ const translation = {
}, },
moderation: { moderation: {
title: 'Content 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', allEnabled: 'INPUT/OUTPUT Content Enabled',
inputEnabled: 'INPUT Content Enabled', inputEnabled: 'INPUT Content Enabled',
outputEnabled: 'OUTPUT Content Enabled', outputEnabled: 'OUTPUT Content Enabled',
......
...@@ -133,13 +133,13 @@ const translation = { ...@@ -133,13 +133,13 @@ const translation = {
title: '工具箱', title: '工具箱',
}, },
moderation: { moderation: {
title: '内容审', title: '内容审',
description: '内容审核', description: '您可以调用审查 API 或者维护敏感词库来使模型更安全地输出。',
allEnabled: '审核输入/审核输出 内容已启用', allEnabled: '审查输入/审查输出 内容已启用',
inputEnabled: '审输入内容已启用', inputEnabled: '审输入内容已启用',
outputEnabled: '审输出内容已启用', outputEnabled: '审输出内容已启用',
modal: { modal: {
title: '内容审设置', title: '内容审设置',
provider: { provider: {
title: '类别', title: '类别',
openai: 'OpenAI Moderation', openai: 'OpenAI Moderation',
...@@ -155,17 +155,17 @@ const translation = { ...@@ -155,17 +155,17 @@ const translation = {
line: '行', line: '行',
}, },
content: { content: {
input: '审输入内容', input: '审输入内容',
output: '审输出内容', output: '审输出内容',
preset: '预设回复', preset: '预设回复',
placeholder: '这里预设回复内容', placeholder: '这里预设回复内容',
condition: '审核输入内容和审核输出内容至少启用一项', condition: '审查输入内容和审查输出内容至少启用一项',
fromApi: '预设回复通过 API 返回', fromApi: '预设回复通过 API 返回',
errorMessage: '预设回复不能为空', errorMessage: '预设回复不能为空',
supportMarkdown: '支持 Markdown', supportMarkdown: '支持 Markdown',
}, },
openaiNotConfig: { openaiNotConfig: {
before: 'OpenAI 内容审需要在', before: 'OpenAI 内容审需要在',
after: '中配置 OpenAI API 密钥。', after: '中配置 OpenAI API 密钥。',
}, },
}, },
......
...@@ -214,9 +214,10 @@ export type CodeBasedExtensionForm = { ...@@ -214,9 +214,10 @@ export type CodeBasedExtensionForm = {
label: I18nText label: I18nText
variable: string variable: string
required: boolean required: boolean
options: string[] options: { label: I18nText; value: string }[]
default: string default: string
placeholder: string placeholder: string
max_length?: number
} }
export type CodeBasedExtensionItem = { export type CodeBasedExtensionItem = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment