Initial commit
This commit is contained in:
commit
db896255d6
744 changed files with 56028 additions and 0 deletions
63
web/utils/model-config.ts
Normal file
63
web/utils/model-config.ts
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import { UserInputFormItem, } from '@/types/app'
|
||||
import { PromptVariable } from '@/models/debug'
|
||||
|
||||
export const userInputsFormToPromptVariables = (useInputs: UserInputFormItem[] | null) => {
|
||||
if (!useInputs) return []
|
||||
const promptVariables: PromptVariable[] = []
|
||||
useInputs.forEach((item: any) => {
|
||||
const type = item['text-input'] ? 'string' : 'select'
|
||||
const content = type === 'string' ? item['text-input'] : item['select']
|
||||
if (type === 'string') {
|
||||
promptVariables.push({
|
||||
key: content.variable,
|
||||
name: content.label,
|
||||
required: content.required,
|
||||
type: 'string',
|
||||
max_length: content.max_length,
|
||||
options: [],
|
||||
})
|
||||
} else {
|
||||
promptVariables.push({
|
||||
key: content.variable,
|
||||
name: content.label,
|
||||
required: content.required,
|
||||
type: 'select',
|
||||
options: content.options,
|
||||
})
|
||||
}
|
||||
})
|
||||
return promptVariables
|
||||
}
|
||||
|
||||
export const promptVariablesToUserInputsForm = (promptVariables: PromptVariable[]) => {
|
||||
const userInputs: UserInputFormItem[] = []
|
||||
promptVariables.filter(({ key, name }) => {
|
||||
if (key && key.trim() && name && name.trim()) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}).forEach((item: any) => {
|
||||
if (item.type === 'string') {
|
||||
userInputs.push({
|
||||
'text-input': {
|
||||
label: item.name,
|
||||
variable: item.key,
|
||||
required: item.required === false ? false : true, // default true
|
||||
max_length: item.max_length,
|
||||
default: ''
|
||||
},
|
||||
} as any)
|
||||
} else {
|
||||
userInputs.push({
|
||||
'select': {
|
||||
label: item.name,
|
||||
variable: item.key,
|
||||
required: item.required === false ? false : true, // default true
|
||||
options: item.options,
|
||||
default: ''
|
||||
},
|
||||
} as any)
|
||||
}
|
||||
})
|
||||
return userInputs
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue