Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: model-parameter-modal slider #2135

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ const stopParameerRule: ModelParameterRule = {
zh_Hans: '输入序列并按 Tab 键',
},
}

const PROVIDER_WITH_PRESET_TONE = ['openai', 'azure_openai']
const ModelParameterModal: FC<ModelParameterModalProps> = ({
isAdvancedMode,
modelId,
Expand Down Expand Up @@ -105,10 +107,11 @@ const ModelParameterModal: FC<ModelParameterModalProps> = ({
const remvoedCustomeTone = TONE_LIST.slice(0, -1)
const CUSTOM_TONE_ID = 4
const tone = remvoedCustomeTone.find((tone) => {
return tone.config?.temperature === completionParams.temperature
&& tone.config?.top_p === completionParams.top_p
&& tone.config?.presence_penalty === completionParams.presence_penalty
&& tone.config?.frequency_penalty === completionParams.frequency_penalty
const config: Record<string, any> = tone.config || {}

return Object.keys(config).every((key) => {
return config[key] === completionParams[key]
})
})
return tone ? tone.id : CUSTOM_TONE_ID
}
Expand All @@ -122,14 +125,11 @@ const ModelParameterModal: FC<ModelParameterModalProps> = ({
})[toneId] || ''
// set completionParams by toneId
const handleToneChange = (id: number) => {
if (id === 4)
return // custom tone
const tone = TONE_LIST.find(tone => tone.id === id)
if (tone) {
setToneId(id)
onCompletionParamsChange({
...tone.config,
max_tokens: completionParams.max_tokens,
})
}
}
Expand Down Expand Up @@ -173,6 +173,7 @@ const ModelParameterModal: FC<ModelParameterModalProps> = ({

const handleInitialParams = () => {
const newCompletionParams = { ...completionParams }
const defaultParams: Record<string, any> = {}
if (parameterRules.length) {
parameterRules.forEach((parameterRule) => {
if (!newCompletionParams[parameterRule.name]) {
Expand All @@ -181,8 +182,13 @@ const ModelParameterModal: FC<ModelParameterModalProps> = ({
else
delete newCompletionParams[parameterRule.name]
}
if (!isNullOrUndefined(parameterRule.default))
defaultParams[parameterRule.name] = parameterRule.default
})

if (PROVIDER_WITH_PRESET_TONE.includes(provider))
TONE_LIST[3].config = defaultParams as any

onCompletionParamsChange(newCompletionParams)
}
}
Expand Down Expand Up @@ -305,7 +311,7 @@ const ModelParameterModal: FC<ModelParameterModalProps> = ({
<div className='mt-5'><Loading /></div>
)
}
{['openai', 'azure_openai'].includes(provider) && !isLoading && !!parameterRules.length && (
{PROVIDER_WITH_PRESET_TONE.includes(provider) && !isLoading && !!parameterRules.length && (
<div className='mt-5 mb-4'>
<div className="mb-3 text-sm text-gray-900">{t('appDebug.modelConfig.setTone')}</div>
<Radio.Group className={cn('!rounded-lg', toneTabBgClassName)} value={toneId} onChange={handleToneChange}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ const ParameterItem: FC<ParameterItemProps> = ({
}

const handleSlideChange = (num: number) => {
if (!isNullOrUndefined(parameterRule.max) && num > parameterRule.max!)
return handleInputChange(parameterRule.max)

if (!isNullOrUndefined(parameterRule.min) && num < parameterRule.min!)
return handleInputChange(parameterRule.min)

handleInputChange(num)
}

Expand Down
Loading