瀏覽代碼

fix: add hf task field (#976)

Co-authored-by: StyleZhang <jasonapring2015@outlook.com>
tags/0.3.16
takatost 2 年之前
父節點
當前提交
071e7800a0
沒有連結到貢獻者的電子郵件帳戶。

+ 53
- 0
web/app/components/header/account-setting/model-page/configs/huggingface_hub.tsx 查看文件

defaultValue: { defaultValue: {
model_type: 'text-generation', model_type: 'text-generation',
huggingfacehub_api_type: 'hosted_inference_api', huggingfacehub_api_type: 'hosted_inference_api',
task_type: 'text-generation',
}, },
validateKeys: (v?: FormValue) => { validateKeys: (v?: FormValue) => {
if (v?.huggingfacehub_api_type === 'hosted_inference_api') { if (v?.huggingfacehub_api_type === 'hosted_inference_api') {
'huggingfacehub_api_token', 'huggingfacehub_api_token',
'model_name', 'model_name',
'huggingfacehub_endpoint_url', 'huggingfacehub_endpoint_url',
'task_type',
] ]
} }
return [] return []
}, },
filterValue: (v?: FormValue) => {
let filteredKeys: string[] = []
if (v?.huggingfacehub_api_type === 'hosted_inference_api') {
filteredKeys = [
'huggingfacehub_api_type',
'huggingfacehub_api_token',
'model_name',
'model_type',
]
}
if (v?.huggingfacehub_api_type === 'inference_endpoints') {
filteredKeys = [
'huggingfacehub_api_type',
'huggingfacehub_api_token',
'model_name',
'huggingfacehub_endpoint_url',
'task_type',
'model_type',
]
}
return filteredKeys.reduce((prev: FormValue, next: string) => {
prev[next] = v?.[next] || ''
return prev
}, {})
},
fields: [ fields: [
{ {
type: 'radio', type: 'radio',
'zh-Hans': '在此输入您的端点 URL', 'zh-Hans': '在此输入您的端点 URL',
}, },
}, },
{
hidden: (value?: FormValue) => value?.huggingfacehub_api_type === 'hosted_inference_api',
type: 'radio',
key: 'task_type',
required: true,
label: {
'en': 'Task',
'zh-Hans': 'Task',
},
options: [
{
key: 'text2text-generation',
label: {
'en': 'Text-to-Text Generation',
'zh-Hans': 'Text-to-Text Generation',
},
},
{
key: 'text-generation',
label: {
'en': 'Text Generation',
'zh-Hans': 'Text Generation',
},
},
],
},
], ],
}, },
} }

+ 1
- 0
web/app/components/header/account-setting/model-page/declarations.ts 查看文件

icon: ReactElement icon: ReactElement
defaultValue?: FormValue defaultValue?: FormValue
validateKeys?: string[] | ((v?: FormValue) => string[]) validateKeys?: string[] | ((v?: FormValue) => string[])
filterValue?: (v?: FormValue) => FormValue
fields: Field[] fields: Field[]
link: { link: {
href: string href: string

+ 3
- 2
web/app/components/header/account-setting/model-page/index.tsx 查看文件

updateModelList(ModelType.embeddings) updateModelList(ModelType.embeddings)
mutateProviders() mutateProviders()
} }
const handleSave = async (v?: FormValue) => {
if (v && modelModalConfig) {
const handleSave = async (originValue?: FormValue) => {
if (originValue && modelModalConfig) {
const v = modelModalConfig.filterValue ? modelModalConfig.filterValue(originValue) : originValue
let body, url let body, url
if (ConfigurableProviders.includes(modelModalConfig.key)) { if (ConfigurableProviders.includes(modelModalConfig.key)) {
const { model_name, model_type, ...config } = v const { model_name, model_type, ...config } = v

+ 1
- 1
web/app/components/header/account-setting/model-page/model-modal/Form.tsx 查看文件

return true return true
}, },
run: () => { run: () => {
return validateModelProviderFn(modelModal!.key, v)
return validateModelProviderFn(modelModal!.key, modelModal?.filterValue ? modelModal?.filterValue(v) : v)
}, },
}) })
} }

Loading…
取消
儲存