From 4b06368583910ca9d404d84f24f48ceb6871b066 Mon Sep 17 00:00:00 2001 From: StyleZhang Date: Wed, 20 Sep 2023 10:42:48 +0800 Subject: [PATCH 1/2] fix: frontend huggingface embedding addtask type --- .../model-page/configs/huggingface_hub.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/web/app/components/header/account-setting/model-page/configs/huggingface_hub.tsx b/web/app/components/header/account-setting/model-page/configs/huggingface_hub.tsx index 6c21a7cd73e8ae..3b7aa0e327b476 100644 --- a/web/app/components/header/account-setting/model-page/configs/huggingface_hub.tsx +++ b/web/app/components/header/account-setting/model-page/configs/huggingface_hub.tsx @@ -209,6 +209,25 @@ const config: ProviderConfig = { }, ], }, + { + hidden: (value?: FormValue) => !(value?.huggingfacehub_api_type === 'inference_endpoints' && value?.model_type === 'embeddings'), + type: 'radio', + key: 'task_type', + required: true, + label: { + 'en': 'Task', + 'zh-Hans': 'Task', + }, + options: [ + { + key: 'feature-extraction', + label: { + 'en': 'Feature Extraction', + 'zh-Hans': 'Feature Extraction', + }, + }, + ], + }, ], }, } From 7296444aad8bbd00a786050b4321c07958f863b4 Mon Sep 17 00:00:00 2001 From: StyleZhang Date: Wed, 20 Sep 2023 11:45:38 +0800 Subject: [PATCH 2/2] fix: frontend huggingface embedding addtask type --- .../model-page/configs/huggingface_hub.tsx | 27 +++++------------ .../model-page/model-modal/Form.tsx | 29 ++++++++++++++++--- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/web/app/components/header/account-setting/model-page/configs/huggingface_hub.tsx b/web/app/components/header/account-setting/model-page/configs/huggingface_hub.tsx index 3b7aa0e327b476..69006a7a77315a 100644 --- a/web/app/components/header/account-setting/model-page/configs/huggingface_hub.tsx +++ b/web/app/components/header/account-setting/model-page/configs/huggingface_hub.tsx @@ -68,25 +68,14 @@ const config: ProviderConfig = { ] } if (v?.huggingfacehub_api_type === 'inference_endpoints') { - if (v?.model_type === 'embeddings') { - filteredKeys = [ - 'huggingfacehub_api_type', - 'huggingfacehub_api_token', - 'model_name', - 'huggingfacehub_endpoint_url', - 'model_type', - ] - } - else { - filteredKeys = [ - 'huggingfacehub_api_type', - 'huggingfacehub_api_token', - 'model_name', - 'huggingfacehub_endpoint_url', - 'task_type', - 'model_type', - ] - } + 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] || '' diff --git a/web/app/components/header/account-setting/model-page/model-modal/Form.tsx b/web/app/components/header/account-setting/model-page/model-modal/Form.tsx index 6f3838c8604d6c..da0f91e838ca7a 100644 --- a/web/app/components/header/account-setting/model-page/model-modal/Form.tsx +++ b/web/app/components/header/account-setting/model-page/model-modal/Form.tsx @@ -1,7 +1,7 @@ import { useEffect, useState } from 'react' import type { Dispatch, FC, SetStateAction } from 'react' import { useContext } from 'use-context-selector' -import type { Field, FormValue, ProviderConfigModal } from '../declarations' +import { type Field, type FormValue, type ProviderConfigModal, ProviderEnum } from '../declarations' import { useValidate } from '../../key-validator/hooks' import { ValidatingTip } from '../../key-validator/ValidateStatus' import { validateModelProviderFn } from '../utils' @@ -85,10 +85,31 @@ const Form: FC = ({ } const handleFormChange = (k: string, v: string) => { - if (mode === 'edit' && !cleared) + if (mode === 'edit' && !cleared) { handleClear({ [k]: v }) - else - handleMultiFormChange({ ...value, [k]: v }, k) + } + else { + const extraValue: Record = {} + if ( + ( + (k === 'model_type' && v === 'embeddings' && value.huggingfacehub_api_type === 'inference_endpoints') + || (k === 'huggingfacehub_api_type' && v === 'inference_endpoints' && value.model_type === 'embeddings') + ) + && modelModal?.key === ProviderEnum.huggingface_hub + ) + extraValue.task_type = 'feature-extraction' + + if ( + ( + (k === 'model_type' && v === 'text-generation' && value.huggingfacehub_api_type === 'inference_endpoints') + || (k === 'huggingfacehub_api_type' && v === 'inference_endpoints' && value.model_type === 'text-generation') + ) + && modelModal?.key === ProviderEnum.huggingface_hub + ) + extraValue.task_type = 'text-generation' + + handleMultiFormChange({ ...value, [k]: v, ...extraValue }, k) + } } const handleFocus = () => {