From eee779a9238d1d7f462367ab1a69d1d92291a56f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=9E=E6=B3=95=E6=93=8D=E4=BD=9C?= Date: Sat, 6 Jul 2024 09:54:30 +0800 Subject: [PATCH] fix: the input field of tool panel not worked as expected (#6003) --- api/core/tools/tool_manager.py | 12 ++++++------ web/app/components/base/select/index.tsx | 1 + .../model-provider-page/model-modal/Form.tsx | 10 ++++++++-- .../model-provider-page/model-modal/Input.tsx | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/api/core/tools/tool_manager.py b/api/core/tools/tool_manager.py index 9fcadbd391333..e30a905cbcf30 100644 --- a/api/core/tools/tool_manager.py +++ b/api/core/tools/tool_manager.py @@ -154,7 +154,7 @@ def get_tool_runtime(cls, provider_type: str, 'invoke_from': invoke_from, 'tool_invoke_from': tool_invoke_from, }) - + elif provider_type == 'api': if tenant_id is None: raise ValueError('tenant id is required for api provider') @@ -201,7 +201,7 @@ def _init_runtime_parameter(cls, parameter_rule: ToolParameter, parameters: dict init runtime parameter """ parameter_value = parameters.get(parameter_rule.name) - if not parameter_value: + if not parameter_value and parameter_value != 0: # get default value parameter_value = parameter_rule.default if not parameter_value and parameter_rule.required: @@ -321,14 +321,14 @@ def list_builtin_providers(cls) -> Generator[BuiltinToolProviderController, None if cls._builtin_providers_loaded: yield from list(cls._builtin_providers.values()) return - + with cls._builtin_provider_lock: if cls._builtin_providers_loaded: yield from list(cls._builtin_providers.values()) return - + yield from cls._list_builtin_providers() - + @classmethod def _list_builtin_providers(cls) -> Generator[BuiltinToolProviderController, None, None]: """ @@ -492,7 +492,7 @@ def get_api_provider_controller(cls, tenant_id: str, provider_id: str) -> tuple[ controller = ApiToolProviderController.from_db( provider, - ApiProviderAuthType.API_KEY if provider.credentials['auth_type'] == 'api_key' else + ApiProviderAuthType.API_KEY if provider.credentials['auth_type'] == 'api_key' else ApiProviderAuthType.NONE ) controller.load_bundled_tools(provider.tools) diff --git a/web/app/components/base/select/index.tsx b/web/app/components/base/select/index.tsx index 51e371ac09aa7..b342ef29bbb47 100644 --- a/web/app/components/base/select/index.tsx +++ b/web/app/components/base/select/index.tsx @@ -191,6 +191,7 @@ const SimpleSelect: FC = ({ onClick={(e) => { e.stopPropagation() setSelectedItem(null) + onSelect({ value: null }) }} className="h-5 w-5 text-gray-400 cursor-pointer" aria-hidden="false" diff --git a/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx b/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx index ca9f3cbd38c00..cc8aa92fec734 100644 --- a/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx +++ b/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx @@ -114,7 +114,7 @@ const Form: FC = ({ validated={validatedSuccess} placeholder={placeholder?.[language] || placeholder?.en_US} disabled={disabed} - type={formSchema.type === FormTypeEnum.textNumber ? 'number' : 'text'} + type={formSchema.type === FormTypeEnum.textNumber ? 'number' : formSchema.type === FormTypeEnum.secretInput ? 'password' : 'text'} {...(formSchema.type === FormTypeEnum.textNumber ? { min: (formSchema as CredentialFormSchemaNumberInput).min, max: (formSchema as CredentialFormSchemaNumberInput).max } : {})} /> {fieldMoreInfo?.(formSchema)} @@ -229,6 +229,7 @@ const Form: FC = ({ variable, label, show_on, + required, } = formSchema as CredentialFormSchemaRadio if (show_on.length && !show_on.every(showOnItem => value[showOnItem.variable] === showOnItem.value)) @@ -239,11 +240,16 @@ const Form: FC = ({
{label[language] || label.en_US} + { + required && ( + * + ) + } {tooltipContent}
handleFormChange(variable, val === 1)} > True diff --git a/web/app/components/header/account-setting/model-provider-page/model-modal/Input.tsx b/web/app/components/header/account-setting/model-provider-page/model-modal/Input.tsx index 12244a5cef88e..86d52619e69dd 100644 --- a/web/app/components/header/account-setting/model-provider-page/model-modal/Input.tsx +++ b/web/app/components/header/account-setting/model-provider-page/model-modal/Input.tsx @@ -53,7 +53,7 @@ const Input: FC = ({ onChange={e => onChange(e.target.value)} onBlur={e => toLimit(e.target.value)} onFocus={onFocus} - value={value || ''} + value={value} disabled={disabled} type={type} min={min}