mirror of https://github.com/langgenius/dify.git
fix: load balancing
This commit is contained in:
parent
fe655ef89a
commit
6463b3d051
|
|
@ -153,6 +153,7 @@ export type ModelItem = {
|
|||
model_properties: Record<string, string | number>
|
||||
load_balancing_enabled: boolean
|
||||
deprecated?: boolean
|
||||
has_invalid_load_balancing_configs?: boolean
|
||||
}
|
||||
|
||||
export enum PreferredProviderTypeEnum {
|
||||
|
|
|
|||
|
|
@ -357,6 +357,7 @@ export const useModelModalHandler = () => {
|
|||
isModelCredential?: boolean,
|
||||
credential?: Credential,
|
||||
model?: CustomModel,
|
||||
onUpdate?: () => void,
|
||||
) => {
|
||||
setShowModelModal({
|
||||
payload: {
|
||||
|
|
@ -369,6 +370,7 @@ export const useModelModalHandler = () => {
|
|||
},
|
||||
onSaveCallback: () => {
|
||||
handleRefreshModel(provider, configurationMethod, CustomConfigurationModelFixedFields)
|
||||
onUpdate?.()
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,11 +58,15 @@ const AddCredentialInLoadBalancing = ({
|
|||
items={[
|
||||
{
|
||||
title: customModel ? t('common.modelProvider.auth.modelCredentials') : t('common.modelProvider.auth.apiKeys'),
|
||||
model,
|
||||
model: customModel ? model : undefined,
|
||||
credentials: available_credentials ?? [],
|
||||
},
|
||||
]}
|
||||
configurationMethod={configurationMethod}
|
||||
currentCustomConfigurationModelFixedFields={customModel ? {
|
||||
__model_name: model.model,
|
||||
__model_type: model.model_type,
|
||||
} : undefined}
|
||||
onItemClick={onSelectCredential}
|
||||
placement='bottom-start'
|
||||
onUpdate={onUpdate}
|
||||
|
|
|
|||
|
|
@ -161,7 +161,15 @@ const Authorized = ({
|
|||
{
|
||||
isModelCredential && (
|
||||
<div
|
||||
onClick={() => handleEdit()}
|
||||
onClick={() => handleEdit(
|
||||
undefined,
|
||||
currentCustomConfigurationModelFixedFields
|
||||
? {
|
||||
model: currentCustomConfigurationModelFixedFields.__model_name,
|
||||
model_type: currentCustomConfigurationModelFixedFields.__model_type,
|
||||
}
|
||||
: undefined,
|
||||
)}
|
||||
className='system-xs-medium flex h-[30px] cursor-pointer items-center px-3 text-text-accent-light-mode-only'
|
||||
>
|
||||
<RiAddLine className='mr-1 h-4 w-4' />
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
import { memo } from 'react'
|
||||
import { RiEqualizer2Line } from '@remixicon/react'
|
||||
import {
|
||||
RiEqualizer2Line,
|
||||
RiScales3Line,
|
||||
} from '@remixicon/react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import Button from '@/app/components/base/button'
|
||||
import cn from '@/utils/classnames'
|
||||
|
|
@ -7,12 +10,29 @@ import cn from '@/utils/classnames'
|
|||
type ConfigModelProps = {
|
||||
className?: string
|
||||
onClick?: () => void
|
||||
loadBalancingEnabled?: boolean
|
||||
loadBalancingInvalid?: boolean
|
||||
}
|
||||
const ConfigModel = ({
|
||||
className,
|
||||
onClick,
|
||||
loadBalancingEnabled,
|
||||
loadBalancingInvalid,
|
||||
}: ConfigModelProps) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
if (loadBalancingEnabled && loadBalancingInvalid) {
|
||||
return (
|
||||
<div
|
||||
className='system-2xs-medium-uppercase flex h-[18px] items-center rounded-[5px] border border-text-warning bg-components-badge-bg-dimm px-1.5'
|
||||
onClick={onClick}
|
||||
>
|
||||
<RiScales3Line className='mr-0.5 h-3 w-3' />
|
||||
{t('common.modelProvider.auth.authorizationError')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant='secondary'
|
||||
|
|
@ -23,8 +43,22 @@ const ConfigModel = ({
|
|||
)}
|
||||
onClick={onClick}
|
||||
>
|
||||
<RiEqualizer2Line className='mr-1 h-4 w-4' />
|
||||
{t('common.operation.config')}
|
||||
{
|
||||
!loadBalancingEnabled && (
|
||||
<>
|
||||
<RiEqualizer2Line className='mr-1 h-4 w-4' />
|
||||
{t('common.operation.config')}
|
||||
</>
|
||||
)
|
||||
}
|
||||
{
|
||||
loadBalancingEnabled && !loadBalancingInvalid && (
|
||||
<>
|
||||
<RiScales3Line className='mr-1 h-4 w-4' />
|
||||
{t('common.modelProvider.auth.configLoadBalancing')}
|
||||
</>
|
||||
)
|
||||
}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,8 +138,9 @@ export const useAuth = (
|
|||
isModelCredential,
|
||||
credential,
|
||||
model,
|
||||
onUpdate,
|
||||
)
|
||||
}, [handleOpenModelModal, provider, configurationMethod, currentCustomConfigurationModelFixedFields, isModelCredential])
|
||||
}, [handleOpenModelModal, provider, configurationMethod, currentCustomConfigurationModelFixedFields, isModelCredential, onUpdate])
|
||||
|
||||
return {
|
||||
pendingOperationCredentialId,
|
||||
|
|
|
|||
|
|
@ -66,10 +66,11 @@ export const useModelFormSchemas = (
|
|||
|
||||
const formValues = useMemo(() => {
|
||||
let result = {}
|
||||
if (credentials)
|
||||
result = { ...credentials }
|
||||
if (credential)
|
||||
if (credential) {
|
||||
result = { ...result, __authorization_name__: credential?.credential_name }
|
||||
if (credentials)
|
||||
result = { ...result, ...credentials }
|
||||
}
|
||||
if (model)
|
||||
result = { ...result, __model_name: model?.model, __model_type: model?.model_type }
|
||||
return result
|
||||
|
|
|
|||
|
|
@ -76,6 +76,8 @@ const ModelListItem = ({ model, provider, isConfigurable, onModifyLoadBalancing
|
|||
<ConfigModel
|
||||
className='hidden group-hover:flex'
|
||||
onClick={() => onModifyLoadBalancing?.(model)}
|
||||
loadBalancingEnabled={model.load_balancing_enabled}
|
||||
loadBalancingInvalid={model.has_invalid_load_balancing_configs}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -165,7 +165,15 @@ const ModelLoadBalancingConfigs = ({
|
|||
</div>
|
||||
{draftConfig.enabled && (
|
||||
<div className='flex flex-col gap-1 px-3 pb-3'>
|
||||
{draftConfig.configs.map((config, index) => {
|
||||
{draftConfig.configs.filter((config) => {
|
||||
if (config.name === '__inherit__')
|
||||
return true
|
||||
|
||||
if (config.credential_id)
|
||||
return true
|
||||
|
||||
return false
|
||||
}).map((config, index) => {
|
||||
const isProviderManaged = config.name === '__inherit__'
|
||||
return (
|
||||
<div key={config.id || index} className='group flex h-10 items-center rounded-lg border border-components-panel-border bg-components-panel-on-panel-item-bg px-3 shadow-xs'>
|
||||
|
|
|
|||
|
|
@ -498,6 +498,7 @@ const translation = {
|
|||
modelCredentials: 'Model credentials',
|
||||
configModel: 'Config model',
|
||||
configLoadBalancing: 'Config Load Balancing',
|
||||
authorizationError: 'Authorization error',
|
||||
},
|
||||
},
|
||||
dataSource: {
|
||||
|
|
|
|||
|
|
@ -498,6 +498,7 @@ const translation = {
|
|||
modelCredentials: '模型凭据',
|
||||
configModel: '配置模型',
|
||||
configLoadBalancing: '配置负载均衡',
|
||||
authorizationError: '授权错误',
|
||||
},
|
||||
},
|
||||
dataSource: {
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ export const useGetModelCredential = (
|
|||
queryKey: [NAME_SPACE, 'model-list', provider, model, modelType, credentialId],
|
||||
queryFn: () => get<ModelCredential>(`/workspaces/current/model-providers/${provider}/models/credentials?model=${model}&model_type=${modelType}&config_from=${configFrom}${credentialId ? `&credential_id=${credentialId}` : ''}`),
|
||||
staleTime: 0,
|
||||
gcTime: 0,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue