Procházet zdrojové kódy

fix: code-based extension (#1477)

tags/0.3.30
zxhlyh před 2 roky
rodič
revize
7b26c9e2ef
Žádný účet není propojen s e-mailovou adresou tvůrce revize

+ 2
- 2
web/app/components/app/configuration/toolbox/moderation/form-generation.tsx Zobrazit soubor

defaultValue={value?.[form.variable]} defaultValue={value?.[form.variable]}
items={form.options.map((option) => { items={form.options.map((option) => {
return { 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)} onSelect={item => handleFormChange(form.variable, item.value as string)}

+ 11
- 2
web/app/components/app/configuration/toolbox/moderation/moderation-setting-modal.tsx Zobrazit soubor

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,
}) })
} }




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'] }),

+ 11
- 2
web/app/components/app/configuration/tools/external-data-tool-modal.tsx Zobrazit soubor

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,
}) })
} }




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'] }),

+ 1
- 1
web/i18n/lang/app-debug.en.ts Zobrazit soubor

}, },
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',

+ 10
- 10
web/i18n/lang/app-debug.zh.ts Zobrazit soubor

title: '工具箱', title: '工具箱',
}, },
moderation: { moderation: {
title: '内容审',
description: '内容审核',
allEnabled: '审核输入/审核输出 内容已启用',
inputEnabled: '审输入内容已启用',
outputEnabled: '审输出内容已启用',
title: '内容审',
description: '您可以调用审查 API 或者维护敏感词库来使模型更安全地输出。',
allEnabled: '审查输入/审查输出 内容已启用',
inputEnabled: '审输入内容已启用',
outputEnabled: '审输出内容已启用',
modal: { modal: {
title: '内容审设置',
title: '内容审设置',
provider: { provider: {
title: '类别', title: '类别',
openai: 'OpenAI Moderation', openai: 'OpenAI Moderation',
line: '行', line: '行',
}, },
content: { content: {
input: '审输入内容',
output: '审输出内容',
input: '审输入内容',
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 密钥。',
}, },
}, },

+ 2
- 1
web/models/common.ts Zobrazit soubor

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 = {

Načítá se…
Zrušit
Uložit