Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: enhance model parameter handling with advanced mode support and localization updates (#25963)

Wu Tianwei87394d2512f6
diff --git a/web/app/components/app/configuration/index.tsx b/web/app/components/app/configuration/index.tsx
index 51ca1b51376..091900642ae 100644
--- a/web/app/components/app/configuration/index.tsx
+++ b/web/app/components/app/configuration/index.tsx
@@ -464,6 +464,7 @@ const Configuration: FC = () => {
provider,
modelId,
completionParams,
+ isAdvancedMode,
)
if (Object.keys(removedDetails).length)
Toast.notify({ type: 'warning', message: `${t('common.modelProvider.parametersInvalidRemoved')}: ${Object.entries(removedDetails).map(([k, reason]) => `${k} (${reason})`).join(', ')}` })
diff --git a/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/index.tsx b/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/index.tsx
index 9653c5eb693..82ba072b94e 100644
--- a/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/index.tsx
+++ b/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/index.tsx
@@ -29,7 +29,7 @@ import {
import { fetchModelParameterRules } from '@/service/common'
import Loading from '@/app/components/base/loading'
import { useProviderContext } from '@/context/provider-context'
-import { TONE_LIST } from '@/config'
+import { PROVIDER_WITH_PRESET_TONE, STOP_PARAMETER_RULE, TONE_LIST } from '@/config'
import { ArrowNarrowLeft } from '@/app/components/base/icons/src/vender/line/arrows'
export type ModelParameterModalProps = {
@@ -50,26 +50,7 @@ export type ModelParameterModalProps = {
isInWorkflow?: boolean
scope?: string
}
-const stopParameterRule: ModelParameterRule = {
- default: [],
- help: {
- en_US: 'Up to four sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.',
- zh_Hans: '最多四个序列,API 将停止生成更多的 token。返回的文本将不包含停止序列。',
- },
- label: {
- en_US: 'Stop sequences',
- zh_Hans: '停止序列',
- },
- name: 'stop',
- required: false,
- type: 'tag',
- tagPlaceholder: {
- en_US: 'Enter sequence and press Tab',
- zh_Hans: '输入序列并按 Tab 键',
- },
-}
-const PROVIDER_WITH_PRESET_TONE = ['langgenius/openai/openai', 'langgenius/azure_openai/azure_openai']
const ModelParameterModal: FC<ModelParameterModalProps> = ({
popupClassName,
portalToFollowElemContentClassName,
@@ -230,7 +211,7 @@ const ModelParameterModal: FC<ModelParameterModalProps> = ({
!isLoading && !!parameterRules.length && (
[
...parameterRules,
- ...(isAdvancedMode ? [stopParameterRule] : []),
+ ...(isAdvancedMode ? [STOP_PARAMETER_RULE] : []),
].map(parameter => (
<ParameterItem
key={`${modelId}-${parameter.name}`}
diff --git a/web/app/components/plugins/plugin-detail-panel/model-selector/index.tsx b/web/app/components/plugins/plugin-detail-panel/model-selector/index.tsx
index cf400d3c3a6..fb4c99e1e4b 100644
--- a/web/app/components/plugins/plugin-detail-panel/model-selector/index.tsx
+++ b/web/app/components/plugins/plugin-detail-panel/model-selector/index.tsx
@@ -136,6 +136,7 @@ const ModelParameterModal: FC<ModelParameterModalProps> = ({
provider,
model,
value?.completion_params,
+ isAdvancedMode,
)
nextCompletionParams = filtered
diff --git a/web/app/components/plugins/plugin-detail-panel/model-selector/llm-params-panel.tsx b/web/app/components/plugins/plugin-detail-panel/model-selector/llm-params-panel.tsx
index e44697bd96e..0c5ed98e11b 100644
--- a/web/app/components/plugins/plugin-detail-panel/model-selector/llm-params-panel.tsx
+++ b/web/app/components/plugins/plugin-detail-panel/model-selector/llm-params-panel.tsx
@@ -10,29 +10,9 @@ import type {
} from '@/app/components/header/account-setting/model-provider-page/declarations'
import type { ParameterValue } from '@/app/components/header/account-setting/model-provider-page/model-parameter-modal/parameter-item'
import { fetchModelParameterRules } from '@/service/common'
-import { TONE_LIST } from '@/config'
+import { PROVIDER_WITH_PRESET_TONE, STOP_PARAMETER_RULE, TONE_LIST } from '@/config'
import cn from '@/utils/classnames'
-const PROVIDER_WITH_PRESET_TONE = ['langgenius/openai/openai', 'langgenius/azure_openai/azure_openai']
-const stopParameterRule: ModelParameterRule = {
- default: [],
- help: {
- en_US: 'Up to four sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.',
- zh_Hans: '最多四个序列,API 将停止生成更多的 token。返回的文本将不包含停止序列。',
- },
- label: {
- en_US: 'Stop sequences',
- zh_Hans: '停止序列',
- },
- name: 'stop',
- required: false,
- type: 'tag',
- tagPlaceholder: {
- en_US: 'Enter sequence and press Tab',
- zh_Hans: '输入序列并按 Tab 键',
- },
-}
-
type Props = {
isAdvancedMode: boolean
provider: string
@@ -108,7 +88,7 @@ const LLMParamsPanel = ({
{!!parameterRules.length && (
[
...parameterRules,
- ...(isAdvancedMode ? [stopParameterRule] : []),
+ ...(isAdvancedMode ? [STOP_PARAMETER_RULE] : []),
].map(parameter => (
<ParameterItem
key={`${modelId}-${parameter.name}`}
diff --git a/web/app/components/workflow/nodes/llm/panel.tsx b/web/app/components/workflow/nodes/llm/panel.tsx
index f5f5997aced..03569f6f7a1 100644
--- a/web/app/components/workflow/nodes/llm/panel.tsx
+++ b/web/app/components/workflow/nodes/llm/panel.tsx
@@ -78,6 +78,7 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
model.provider,
model.modelId,
inputs.model.completion_params,
+ true,
)
const keys = Object.keys(removedDetails)
if (keys.length)
diff --git a/web/config/index.ts b/web/config/index.ts
index 66e490f09e0..f818a1c0afe 100644
--- a/web/config/index.ts
+++ b/web/config/index.ts
@@ -4,6 +4,7 @@ import { PromptRole } from '@/models/debug'
import { PipelineInputVarType } from '@/models/pipeline'
import { DatasetAttr } from '@/types/feature'
import pkg from '../package.json'
+import type { ModelParameterRule } from '@/app/components/header/account-setting/model-provider-page/declarations'
const getBooleanConfig = (
envVar: string | undefined,
@@ -403,3 +404,24 @@ export const ZENDESK_FIELD_IDS = {
export const APP_VERSION = pkg.version
export const RAG_PIPELINE_PREVIEW_CHUNK_NUM = 20
+
+export const PROVIDER_WITH_PRESET_TONE = ['langgenius/openai/openai', 'langgenius/azure_openai/azure_openai']
+
+export const STOP_PARAMETER_RULE: ModelParameterRule = {
+ default: [],
+ help: {
+ en_US: 'Up to four sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.',
+ zh_Hans: '最多四个序列,API 将停止生成更多的 token。返回的文本将不包含停止序列。',
+ },
+ label: {
+ en_US: 'Stop sequences',
+ zh_Hans: '停止序列',
+ },
+ name: 'stop',
+ required: false,
+ type: 'tag',
+ tagPlaceholder: {
+ en_US: 'Enter sequence and press Tab',
+ zh_Hans: '输入序列并按 Tab 键',
+ },
+}
diff --git a/web/i18n/en-US/common.ts b/web/i18n/en-US/common.ts
index 337a12d2382..ef6bf73ab5f 100644
--- a/web/i18n/en-US/common.ts
+++ b/web/i18n/en-US/common.ts
@@ -527,6 +527,7 @@ const translation = {
selectModelCredential: 'Select a model credential',
customModelCredentialsDeleteTip: 'Credential is in use and cannot be deleted',
},
+ parametersInvalidRemoved: 'Some parameters are invalid and have been removed',
},
dataSource: {
add: 'Add a data source',
diff --git a/web/i18n/zh-Hans/common.ts b/web/i18n/zh-Hans/common.ts
index 61da5f057b3..bcefb09e3ef 100644
--- a/web/i18n/zh-Hans/common.ts
+++ b/web/i18n/zh-Hans/common.ts
@@ -521,6 +521,7 @@ const translation = {
selectModelCredential: '选择模型凭据',
customModelCredentialsDeleteTip: '模型凭据正在使用中,无法删除',
},
+ parametersInvalidRemoved: '部分参数无效,已移除',
},
dataSource: {
add: '添加数据源',
diff --git a/web/utils/completion-params.ts b/web/utils/completion-params.ts
index fb339423c84..62eb884825d 100644
--- a/web/utils/completion-params.ts
+++ b/web/utils/completion-params.ts
@@ -3,6 +3,7 @@ import type { FormValue, ModelParameterRule } from '@/app/components/header/acco
export const mergeValidCompletionParams = (
oldParams: FormValue | undefined,
rules: ModelParameterRule[],
+ isAdvancedMode: boolean = false,
): { params: FormValue; removedDetails: Record<string, string> } => {
if (!oldParams || Object.keys(oldParams).length === 0)
return { params: {}, removedDetails: {} }
@@ -16,6 +17,11 @@ export const mergeValidCompletionParams = (
const removedDetails: Record<string, string> = {}
Object.entries(oldParams).forEach(([key, value]) => {
+ if (key === 'stop' && isAdvancedMode) {
+ // keep stop in advanced mode
+ nextParams[key] = value
+ return
+ }
const rule = ruleMap[key]
if (!rule) {
removedDetails[key] = 'unsupported'
@@ -74,9 +80,10 @@ export const fetchAndMergeValidCompletionParams = async (
provider: string,
modelId: string,
oldParams: FormValue | undefined,
+ isAdvancedMode: boolean = false,
): Promise<{ params: FormValue; removedDetails: Record<string, string> }> => {
const { fetchModelParameterRules } = await import('@/service/common')
const url = `/workspaces/current/model-providers/${provider}/models/parameter-rules?model=${modelId}`
const { data: parameterRules } = await fetchModelParameterRules(url)
- return mergeValidCompletionParams(oldParams, parameterRules ?? [])
+ return mergeValidCompletionParams(oldParams, parameterRules ?? [], isAdvancedMode)
}