Merge branch 'feat/plugins' of github.com:langgenius/dify into feat/plugins

This commit is contained in:
Yi
2024-11-01 14:56:11 +08:00
54 changed files with 402 additions and 635 deletions

View File

@ -199,13 +199,13 @@ export default function AccountSetting({
)}
</div>
<div className='px-4 sm:px-8 pt-2'>
{activeMenu === 'provider' && <ModelProviderPage searchText={searchValue} />}
{activeMenu === 'members' && <MembersPage />}
{activeMenu === 'billing' && <BillingPage />}
{activeMenu === 'language' && <LanguagePage />}
{activeMenu === 'provider' && <ModelProviderPage />}
{activeMenu === 'data-source' && <DataSourcePage />}
{activeMenu === 'api-based-extension' && <ApiBasedExtensionPage />}
{activeMenu === 'custom' && <CustomPage />}
{activeMenu === 'language' && <LanguagePage />}
</div>
</div>
</div>

View File

@ -1,6 +1,6 @@
export type FormValue = Record<string, any>
export type TypeWithI18N<T = string> = {
export interface TypeWithI18N<T = string> {
en_US: T
zh_Hans: T
[key: string]: T
@ -17,7 +17,7 @@ export enum FormTypeEnum {
file = 'file',
}
export type FormOption = {
export interface FormOption {
label: TypeWithI18N
value: string
show_on: FormShowOnObject[]
@ -89,12 +89,12 @@ export enum CustomConfigurationStatusEnum {
noConfigure = 'no-configure',
}
export type FormShowOnObject = {
export interface FormShowOnObject {
variable: string
value: string
}
export type CredentialFormSchemaBase = {
export interface CredentialFormSchemaBase {
variable: string
label: TypeWithI18N
type: FormTypeEnum
@ -112,7 +112,7 @@ export type CredentialFormSchemaRadio = CredentialFormSchemaBase & { options: Fo
export type CredentialFormSchemaSecretInput = CredentialFormSchemaBase & { placeholder?: TypeWithI18N }
export type CredentialFormSchema = CredentialFormSchemaTextInput | CredentialFormSchemaSelect | CredentialFormSchemaRadio | CredentialFormSchemaSecretInput
export type ModelItem = {
export interface ModelItem {
model: string
label: TypeWithI18N
model_type: ModelTypeEnum
@ -141,7 +141,7 @@ export enum QuotaUnitEnum {
credits = 'credits',
}
export type QuotaConfiguration = {
export interface QuotaConfiguration {
quota_type: CurrentSystemQuotaTypeEnum
quota_unit: QuotaUnitEnum
quota_limit: number
@ -150,8 +150,7 @@ export type QuotaConfiguration = {
is_valid: boolean
}
export type ModelProvider = {
plugin_id: string
export interface ModelProvider {
provider: string
label: TypeWithI18N
description?: TypeWithI18N
@ -185,8 +184,7 @@ export type ModelProvider = {
}
}
export type Model = {
plugin_id: string
export interface Model {
provider: string
icon_large: TypeWithI18N
icon_small: TypeWithI18N
@ -195,29 +193,27 @@ export type Model = {
status: ModelStatusEnum
}
export type DefaultModelResponse = {
export interface DefaultModelResponse {
model: string
model_type: ModelTypeEnum
provider: {
plugin_id: string
provider: string
icon_large: TypeWithI18N
icon_small: TypeWithI18N
}
}
export type DefaultModel = {
plugin_id: string
export interface DefaultModel {
provider: string
model: string
}
export type CustomConfigurationModelFixedFields = {
export interface CustomConfigurationModelFixedFields {
__model_name: string
__model_type: ModelTypeEnum
}
export type ModelParameterRule = {
export interface ModelParameterRule {
default?: number | string | boolean | string[]
help?: TypeWithI18N
label: TypeWithI18N
@ -232,7 +228,7 @@ export type ModelParameterRule = {
tagPlaceholder?: TypeWithI18N
}
export type ModelLoadBalancingConfigEntry = {
export interface ModelLoadBalancingConfigEntry {
/** model balancing config entry id */
id?: string
/** is config entry enabled */
@ -247,7 +243,7 @@ export type ModelLoadBalancingConfigEntry = {
ttl?: number
}
export type ModelLoadBalancingConfig = {
export interface ModelLoadBalancingConfig {
enabled: boolean
configs: ModelLoadBalancingConfigEntry[]
}

View File

@ -11,7 +11,6 @@ import type {
DefaultModel,
DefaultModelResponse,
Model,
ModelProvider,
ModelTypeEnum,
} from './declarations'
import {
@ -37,12 +36,11 @@ export const useSystemDefaultModelAndModelList: UseDefaultModelAndModelList = (
modelList,
) => {
const currentDefaultModel = useMemo(() => {
const currentProvider = modelList.find(provider => provider.provider === defaultModel?.provider.provider && provider.plugin_id === defaultModel?.provider.plugin_id)
const currentProvider = modelList.find(provider => provider.provider === defaultModel?.provider.provider)
const currentModel = currentProvider?.models.find(model => model.model === defaultModel?.model)
const currentDefaultModel = currentProvider && currentModel && {
model: currentModel.model,
provider: currentProvider.provider,
plugin_id: currentProvider.plugin_id,
}
return currentDefaultModel
@ -64,20 +62,20 @@ export const useLanguage = () => {
}
export const useProviderCredentialsAndLoadBalancing = (
provider: ModelProvider,
provider: string,
configurationMethod: ConfigurationMethodEnum,
configured?: boolean,
currentCustomConfigurationModelFixedFields?: CustomConfigurationModelFixedFields,
) => {
const { data: predefinedFormSchemasValue, mutate: mutatePredefined } = useSWR(
(configurationMethod === ConfigurationMethodEnum.predefinedModel && configured)
? `/workspaces/current/model-providers/${provider.plugin_id}/${provider.provider}/credentials`
? `/workspaces/current/model-providers/${provider}/credentials`
: null,
fetchModelProviderCredentials,
)
const { data: customFormSchemasValue, mutate: mutateCustomized } = useSWR(
(configurationMethod === ConfigurationMethodEnum.customizableModel && currentCustomConfigurationModelFixedFields)
? `/workspaces/current/model-providers/${provider.plugin_id}/${provider.provider}/models/credentials?model=${currentCustomConfigurationModelFixedFields?.__model_name}&model_type=${currentCustomConfigurationModelFixedFields?.__model_type}`
? `/workspaces/current/model-providers/${provider}/models/credentials?model=${currentCustomConfigurationModelFixedFields?.__model_name}&model_type=${currentCustomConfigurationModelFixedFields?.__model_type}`
: null,
fetchModelProviderCredentials,
)
@ -174,11 +172,7 @@ export const useModelListAndDefaultModelAndCurrentProviderAndModel = (type: Mode
const { modelList, defaultModel } = useModelListAndDefaultModel(type)
const { currentProvider, currentModel } = useCurrentProviderAndModel(
modelList,
{
plugin_id: defaultModel?.provider.plugin_id || '',
provider: defaultModel?.provider.provider || '',
model: defaultModel?.model || '',
},
{ provider: defaultModel?.provider.provider || '', model: defaultModel?.model || '' },
)
return {
@ -199,7 +193,6 @@ export const useUpdateModelList = () => {
return updateModelList
}
// deprecated ???
export const useAnthropicBuyQuota = () => {
const [loading, setLoading] = useState(false)

View File

@ -1,16 +1,15 @@
import { useMemo, useState } from 'react'
import { useEffect, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
import Link from 'next/link'
import { useDebounce } from 'ahooks'
import {
RiAlertFill,
RiArrowDownSLine,
RiArrowRightUpLine,
RiBrainLine,
} from '@remixicon/react'
import { useContext } from 'use-context-selector'
import SystemModelSelector from './system-model-selector'
import ProviderAddedCard, { UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST } from './provider-added-card'
// import ProviderCard from './provider-card'
import type {
CustomConfigurationModelFixedFields,
ModelProvider,
@ -26,16 +25,24 @@ import {
useUpdateModelProviders,
} from './hooks'
import Divider from '@/app/components/base/divider'
import Loading from '@/app/components/base/loading'
import ProviderCard from '@/app/components/plugins/provider-card'
import I18n from '@/context/i18n'
import { useProviderContext } from '@/context/provider-context'
import { useModalContextSelector } from '@/context/modal-context'
import { useEventEmitterContextContext } from '@/context/event-emitter'
import {
useMarketplacePlugins,
} from '@/app/components/plugins/marketplace/hooks'
import { PluginType } from '@/app/components/plugins/types'
import { MARKETPLACE_URL_PREFIX } from '@/config'
import cn from '@/utils/classnames'
import { extensionDallE, modelGPT4, toolNotion } from '@/app/components/plugins/card/card-mock'
type Props = {
searchText: string
}
const ModelProviderPage = () => {
const ModelProviderPage = ({ searchText }: Props) => {
const debouncedSearchText = useDebounce(searchText, { wait: 500 })
const { t } = useTranslation()
const { eventEmitter } = useEventEmitterContextContext()
const updateModelProviders = useUpdateModelProviders()
@ -67,6 +74,18 @@ const ModelProviderPage = () => {
return [configuredProviders, notConfiguredProviders]
}, [providers])
const [filteredConfiguredProviders, filteredNotConfiguredProviders] = useMemo(() => {
const filteredConfiguredProviders = configuredProviders.filter(
provider => provider.provider.toLowerCase().includes(debouncedSearchText.toLowerCase())
|| Object.values(provider.label).some(text => text.toLowerCase().includes(debouncedSearchText.toLowerCase())),
)
const filteredNotConfiguredProviders = notConfiguredProviders.filter(
provider => provider.provider.toLowerCase().includes(debouncedSearchText.toLowerCase())
|| Object.values(provider.label).some(text => text.toLowerCase().includes(debouncedSearchText.toLowerCase())),
)
return [filteredConfiguredProviders, filteredNotConfiguredProviders]
}, [configuredProviders, debouncedSearchText, notConfiguredProviders])
const handleOpenModal = (
provider: ModelProvider,
@ -91,7 +110,7 @@ const ModelProviderPage = () => {
if (configurationMethod === ConfigurationMethodEnum.customizableModel && provider.custom_configuration.status === CustomConfigurationStatusEnum.active) {
eventEmitter?.emit({
type: UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST,
payload: provider,
payload: provider.provider,
} as any)
if (CustomConfigurationModelFixedFields?.__model_type)
@ -102,10 +121,28 @@ const ModelProviderPage = () => {
}
const [collapse, setCollapse] = useState(false)
const { locale } = useContext(I18n)
// TODO #Plugin list API#
const pluginList = [toolNotion, extensionDallE, modelGPT4]
const {
plugins,
queryPlugins,
queryPluginsWithDebounced,
isLoading: isPluginsLoading,
} = useMarketplacePlugins()
useEffect(() => {
if (searchText) {
queryPluginsWithDebounced({
query: searchText,
category: PluginType.model,
})
}
else {
queryPlugins({
query: searchText,
category: PluginType.model,
})
}
}, [queryPlugins, queryPluginsWithDebounced, searchText])
return (
<div className='relative pt-1 -mt-2'>
@ -132,7 +169,7 @@ const ModelProviderPage = () => {
/>
</div>
</div>
{!configuredProviders?.length && (
{!filteredConfiguredProviders?.length && (
<div className='mb-2 p-4 rounded-[10px]' style={{ background: 'linear-gradient(90deg, rgba(200, 206, 218, 0.20) 0%, rgba(200, 206, 218, 0.04) 100%)' }}>
<div className='w-10 h-10 flex items-center justify-center rounded-[10px] border-[0.5px] border-components-card-border bg-components-card-bg shadow-lg backdrop-blur'>
<RiBrainLine className='w-5 h-5 text-text-primary' />
@ -141,9 +178,9 @@ const ModelProviderPage = () => {
<div className='mt-1 text-text-tertiary system-xs-regular'>{t('common.modelProvider.emptyProviderTip')}</div>
</div>
)}
{!!configuredProviders?.length && (
{!!filteredConfiguredProviders?.length && (
<div className='relative'>
{configuredProviders?.map(provider => (
{filteredConfiguredProviders?.map(provider => (
<ProviderAddedCard
key={provider.provider}
provider={provider}
@ -152,11 +189,11 @@ const ModelProviderPage = () => {
))}
</div>
)}
{false && !!notConfiguredProviders?.length && (
{!!filteredNotConfiguredProviders?.length && (
<>
<div className='flex items-center mb-2 pt-2 text-text-primary system-md-semibold'>{t('common.modelProvider.configureRequired')}</div>
<div className='relative'>
{notConfiguredProviders?.map(provider => (
{filteredNotConfiguredProviders?.map(provider => (
<ProviderAddedCard
notConfigured
key={provider.provider}
@ -176,19 +213,20 @@ const ModelProviderPage = () => {
</div>
<div className='flex items-center mb-2 pt-2'>
<span className='pr-1 text-text-tertiary system-sm-regular'>{t('common.modelProvider.discoverMore')}</span>
<Link target="_blank" href="/plugins" className='inline-flex items-center system-sm-medium text-text-accent'>
<Link target="_blank" href={`${MARKETPLACE_URL_PREFIX}`} className='inline-flex items-center system-sm-medium text-text-accent'>
Dify Marketplace
<RiArrowRightUpLine className='w-4 h-4' />
</Link>
</div>
</div>
{!collapse && (
{!collapse && !isPluginsLoading && (
<div className='grid grid-cols-2 gap-2'>
{pluginList.map((plugin, index) => (
<ProviderCard key={index} installed={false} payload={plugin as any} />
{plugins.map(plugin => (
<ProviderCard key={plugin.plugin_id} payload={plugin} />
))}
</div>
)}
{!collapse && isPluginsLoading && <Loading type='area' />}
</div>
</div>
)

View File

@ -72,7 +72,7 @@ const ModelModal: FC<ModelModalProps> = ({
loadBalancing: originalConfig,
mutate,
} = useProviderCredentialsAndLoadBalancing(
provider,
provider.provider,
configurateMethod,
providerFormSchemaPredefined && provider.custom_configuration.status === CustomConfigurationStatusEnum.active,
currentCustomConfigurationModelFixedFields,
@ -229,7 +229,6 @@ const ModelModal: FC<ModelModalProps> = ({
setLoading(true)
const res = await saveCredentials(
providerFormSchemaPredefined,
provider.plugin_id,
provider.provider,
encodeSecretValues(value),
{
@ -256,7 +255,6 @@ const ModelModal: FC<ModelModalProps> = ({
const res = await removeCredentials(
providerFormSchemaPredefined,
provider.plugin_id,
provider.provider,
value,
)

View File

@ -209,7 +209,6 @@ const ModelLoadBalancingEntryModal: FC<ModelModalProps> = ({
const res = await validateLoadBalancingCredentials(
providerFormSchemaPredefined,
provider.plugin_id,
provider.provider,
{
...value,

View File

@ -38,9 +38,8 @@ export type ModelParameterModalProps = {
isAdvancedMode: boolean
mode: string
modelId: string
pluginId: string
provider: string
setModel: (model: { modelId: string; provider: string; pluginId: string; mode?: string; features?: string[] }) => void
setModel: (model: { modelId: string; provider: string; mode?: string; features?: string[] }) => void
completionParams: FormValue
onCompletionParamsChange: (newParams: FormValue) => void
hideDebugWithMultipleModel?: boolean
@ -75,7 +74,6 @@ const ModelParameterModal: FC<ModelParameterModalProps> = ({
portalToFollowElemContentClassName,
isAdvancedMode,
modelId,
pluginId,
provider,
setModel,
completionParams,
@ -90,17 +88,13 @@ const ModelParameterModal: FC<ModelParameterModalProps> = ({
const { t } = useTranslation()
const { isAPIKeySet } = useProviderContext()
const [open, setOpen] = useState(false)
const { data: parameterRulesData, isLoading } = useSWR((provider && modelId) ? `/workspaces/current/model-providers/${pluginId}/${provider}/models/parameter-rules?model=${modelId}` : null, fetchModelParameterRules)
const { data: parameterRulesData, isLoading } = useSWR((provider && modelId) ? `/workspaces/current/model-providers/${provider}/models/parameter-rules?model=${modelId}` : null, fetchModelParameterRules)
const {
currentProvider,
currentModel,
activeTextGenerationModelList,
} = useTextGenerationCurrentProviderAndModelAndModelList(
{
plugin_id: pluginId,
provider,
model: modelId,
},
{ provider, model: modelId },
)
const hasDeprecated = !currentProvider || !currentModel
@ -118,12 +112,11 @@ const ModelParameterModal: FC<ModelParameterModalProps> = ({
})
}
const handleChangeModel = ({ provider, model, plugin_id }: DefaultModel) => {
const handleChangeModel = ({ provider, model }: DefaultModel) => {
const targetProvider = activeTextGenerationModelList.find(modelItem => modelItem.provider === provider)
const targetModelItem = targetProvider?.models.find(modelItem => modelItem.model === model)
setModel({
modelId: model,
pluginId: plugin_id,
provider,
mode: targetModelItem?.model_properties.mode as string,
features: targetModelItem?.features || [],
@ -208,7 +201,7 @@ const ModelParameterModal: FC<ModelParameterModalProps> = ({
{t('common.modelProvider.model').toLocaleUpperCase()}
</div>
<ModelSelector
defaultModel={(provider || modelId) ? { plugin_id: pluginId, provider, model: modelId } : undefined}
defaultModel={(provider || modelId) ? { provider, model: modelId } : undefined}
modelList={activeTextGenerationModelList}
onSelect={handleChangeModel}
triggerClassName='max-w-[295px]'

View File

@ -41,11 +41,11 @@ const ModelSelector: FC<ModelSelectorProps> = ({
defaultModel,
)
const handleSelect = (pluginId: string, provider: string, model: ModelItem) => {
const handleSelect = (provider: string, model: ModelItem) => {
setOpen(false)
if (onSelect)
onSelect({ plugin_id: pluginId, provider, model: model.model })
onSelect({ provider, model: model.model })
}
const handleToggle = () => {

View File

@ -25,7 +25,7 @@ import Tooltip from '@/app/components/base/tooltip'
type PopupItemProps = {
defaultModel?: DefaultModel
model: Model
onSelect: (pluginId: string, provider: string, model: ModelItem) => void
onSelect: (provider: string, model: ModelItem) => void
}
const PopupItem: FC<PopupItemProps> = ({
defaultModel,
@ -39,11 +39,11 @@ const PopupItem: FC<PopupItemProps> = ({
const updateModelList = useUpdateModelList()
const updateModelProviders = useUpdateModelProviders()
const currentProvider = modelProviders.find(provider => provider.provider === model.provider)!
const handleSelect = (pluginId: string, provider: string, modelItem: ModelItem) => {
const handleSelect = (provider: string, modelItem: ModelItem) => {
if (modelItem.status !== ModelStatusEnum.active)
return
onSelect(pluginId, provider, modelItem)
onSelect(provider, modelItem)
}
const handleOpenModelModal = () => {
setShowModelModal({
@ -80,7 +80,7 @@ const PopupItem: FC<PopupItemProps> = ({
group relative flex items-center px-3 py-1.5 h-8 rounded-lg
${modelItem.status === ModelStatusEnum.active ? 'cursor-pointer hover:bg-gray-50' : 'cursor-not-allowed hover:bg-gray-50/60'}
`}
onClick={() => handleSelect(model.plugin_id, model.provider, modelItem)}
onClick={() => handleSelect(model.provider, modelItem)}
>
<ModelIcon
className={`

View File

@ -15,7 +15,7 @@ import { XCircle } from '@/app/components/base/icons/src/vender/solid/general'
type PopupProps = {
defaultModel?: DefaultModel
modelList: Model[]
onSelect: (pluginId: string, provider: string, model: ModelItem) => void
onSelect: (provider: string, model: ModelItem) => void
}
const Popup: FC<PopupProps> = ({
defaultModel,

View File

@ -41,7 +41,7 @@ const CredentialPanel: FC<CredentialPanelProps> = ({
const handleChangePriority = async (key: PreferredProviderTypeEnum) => {
const res = await changeModelProviderPriority({
url: `/workspaces/current/model-providers/${provider.plugin_id}/${provider.provider}/preferred-provider-type`,
url: `/workspaces/current/model-providers/${provider.provider}/preferred-provider-type`,
body: {
preferred_provider_type: key,
},
@ -57,7 +57,7 @@ const CredentialPanel: FC<CredentialPanelProps> = ({
eventEmitter?.emit({
type: UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST,
payload: provider,
payload: provider.provider,
} as any)
}
}

View File

@ -52,12 +52,12 @@ const ProviderAddedCard: FC<ProviderAddedCardProps> = ({
const showQuota = systemConfig.enabled && [...MODEL_PROVIDER_QUOTA_GET_PAID].includes(provider.provider) && !IS_CE_EDITION
const showCredential = configurationMethods.includes(ConfigurationMethodEnum.predefinedModel) && isCurrentWorkspaceManager
const getModelList = async (pluginID: string, providerName: string) => {
const getModelList = async (providerName: string) => {
if (loading)
return
try {
setLoading(true)
const modelsData = await fetchModelProviderModelList(`/workspaces/current/model-providers/${pluginID}/${providerName}/models`)
const modelsData = await fetchModelProviderModelList(`/workspaces/current/model-providers/${providerName}/models`)
setModelList(modelsData.data)
setCollapsed(false)
setFetched(true)
@ -72,12 +72,12 @@ const ProviderAddedCard: FC<ProviderAddedCardProps> = ({
return
}
getModelList(provider.plugin_id, provider.provider)
getModelList(provider.provider)
}
eventEmitter?.useSubscription((v: any) => {
if (v?.type === UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST && v.payload.provider === provider.provider)
getModelList(v.payload.plugin_id, v.payload.provider)
if (v?.type === UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST && v.payload === provider.provider)
getModelList(v.payload)
})
return (
@ -172,7 +172,7 @@ const ProviderAddedCard: FC<ProviderAddedCardProps> = ({
models={modelList}
onCollapse={() => setCollapsed(true)}
onConfig={currentCustomConfigurationModelFixedFields => onOpenModal(ConfigurationMethodEnum.customizableModel, currentCustomConfigurationModelFixedFields)}
onChange={(provider: ModelProvider) => getModelList(provider.plugin_id, provider.provider)}
onChange={(provider: string) => getModelList(provider)}
/>
)
}

View File

@ -33,10 +33,10 @@ const ModelListItem = ({ model, provider, isConfigurable, onConfig, onModifyLoad
const toggleModelEnablingStatus = useCallback(async (enabled: boolean) => {
if (enabled)
await enableModel(`/workspaces/current/model-providers/${provider.plugin_id}/${provider.provider}/models/enable`, { model: model.model, model_type: model.model_type })
await enableModel(`/workspaces/current/model-providers/${provider.provider}/models/enable`, { model: model.model, model_type: model.model_type })
else
await disableModel(`/workspaces/current/model-providers/${provider.plugin_id}/${provider.provider}/models/disable`, { model: model.model, model_type: model.model_type })
}, [model.model, model.model_type, provider.plugin_id, provider.provider])
await disableModel(`/workspaces/current/model-providers/${provider.provider}/models/disable`, { model: model.model, model_type: model.model_type })
}, [model.model, model.model_type, provider.provider])
const { run: debouncedToggleModelEnablingStatus } = useDebounceFn(toggleModelEnablingStatus, { wait: 500 })

View File

@ -23,7 +23,7 @@ type ModelListProps = {
models: ModelItem[]
onCollapse: () => void
onConfig: (currentCustomConfigurationModelFixedFields?: CustomConfigurationModelFixedFields) => void
onChange?: (provider: ModelProvider) => void
onChange?: (provider: string) => void
}
const ModelList: FC<ModelListProps> = ({
provider,

View File

@ -19,7 +19,7 @@ export type ModelLoadBalancingModalProps = {
model: ModelItem
open?: boolean
onClose?: () => void
onSave?: (provider: ModelProvider) => void
onSave?: (provider: string) => void
}
// model balancing config modal
@ -30,7 +30,7 @@ const ModelLoadBalancingModal = ({ provider, model, open = false, onClose, onSav
const [loading, setLoading] = useState(false)
const { data, mutate } = useSWR(
`/workspaces/current/model-providers/${provider.plugin_id}/${provider.provider}/models/credentials?model=${model.model}&model_type=${model.model_type}`,
`/workspaces/current/model-providers/${provider.provider}/models/credentials?model=${model.model}&model_type=${model.model_type}`,
fetchModelLoadBalancingConfig,
)
@ -94,7 +94,7 @@ const ModelLoadBalancingModal = ({ provider, model, open = false, onClose, onSav
if (res.result === 'success') {
notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
mutate()
onSave?.(provider)
onSave?.(provider.provider)
onClose?.()
}
}

View File

@ -94,7 +94,6 @@ const SystemModel: FC<SystemModelSelectorProps> = ({
model_settings: [ModelTypeEnum.textGeneration, ModelTypeEnum.textEmbedding, ModelTypeEnum.rerank, ModelTypeEnum.speech2text, ModelTypeEnum.tts].map((modelType) => {
return {
model_type: modelType,
plugin_id: getCurrentDefaultModelByModelType(modelType)?.plugin_id,
provider: getCurrentDefaultModelByModelType(modelType)?.provider,
model: getCurrentDefaultModelByModelType(modelType)?.model,
}
@ -132,6 +131,7 @@ const SystemModel: FC<SystemModelSelectorProps> = ({
>
<PortalToFollowElemTrigger onClick={() => setOpen(v => !v)}>
<Button
className='relative'
variant={notConfigured ? 'primary' : 'secondary'}
size='small'
>

View File

@ -26,15 +26,14 @@ export const isNullOrUndefined = (value: any) => {
return value === undefined || value === null
}
// deprecated ???
export const validateCredentials = async (predefined: boolean, pluginID: string, provider: string, v: FormValue) => {
export const validateCredentials = async (predefined: boolean, provider: string, v: FormValue) => {
let body, url
if (predefined) {
body = {
credentials: v,
}
url = `/workspaces/current/model-providers/${pluginID}/${provider}/credentials/validate`
url = `/workspaces/current/model-providers/${provider}/credentials/validate`
}
else {
const { __model_name, __model_type, ...credentials } = v
@ -43,7 +42,7 @@ export const validateCredentials = async (predefined: boolean, pluginID: string,
model_type: __model_type,
credentials,
}
url = `/workspaces/current/model-providers/${pluginID}/${provider}/models/credentials/validate`
url = `/workspaces/current/model-providers/${provider}/models/credentials/validate`
}
try {
const res = await validateModelProvider({ url, body })
@ -57,14 +56,14 @@ export const validateCredentials = async (predefined: boolean, pluginID: string,
}
}
export const validateLoadBalancingCredentials = async (predefined: boolean, pluginID: string, provider: string, v: FormValue, id?: string): Promise<{
export const validateLoadBalancingCredentials = async (predefined: boolean, provider: string, v: FormValue, id?: string): Promise<{
status: ValidatedStatus
message?: string
}> => {
const { __model_name, __model_type, ...credentials } = v
try {
const res = await validateModelLoadBalancingCredentials({
url: `/workspaces/current/model-providers/${pluginID}/${provider}/models/load-balancing-configs/${id ? `${id}/` : ''}credentials-validate`,
url: `/workspaces/current/model-providers/${provider}/models/load-balancing-configs/${id ? `${id}/` : ''}credentials-validate`,
body: {
model: __model_name,
model_type: __model_type,
@ -81,7 +80,7 @@ export const validateLoadBalancingCredentials = async (predefined: boolean, plug
}
}
export const saveCredentials = async (predefined: boolean, pluginID: string, provider: string, v: FormValue, loadBalancing?: ModelLoadBalancingConfig) => {
export const saveCredentials = async (predefined: boolean, provider: string, v: FormValue, loadBalancing?: ModelLoadBalancingConfig) => {
let body, url
if (predefined) {
@ -90,7 +89,7 @@ export const saveCredentials = async (predefined: boolean, pluginID: string, pro
credentials: v,
load_balancing: loadBalancing,
}
url = `/workspaces/current/model-providers/${pluginID}/${provider}`
url = `/workspaces/current/model-providers/${provider}`
}
else {
const { __model_name, __model_type, ...credentials } = v
@ -100,7 +99,7 @@ export const saveCredentials = async (predefined: boolean, pluginID: string, pro
credentials,
load_balancing: loadBalancing,
}
url = `/workspaces/current/model-providers/${pluginID}/${provider}/models`
url = `/workspaces/current/model-providers/${provider}/models`
}
return setModelProvider({ url, body })
@ -120,12 +119,12 @@ export const savePredefinedLoadBalancingConfig = async (provider: string, v: For
return setModelProvider({ url, body })
}
export const removeCredentials = async (predefined: boolean, pluginID: string, provider: string, v: FormValue) => {
export const removeCredentials = async (predefined: boolean, provider: string, v: FormValue) => {
let url = ''
let body
if (predefined) {
url = `/workspaces/current/model-providers/${pluginID}/${provider}`
url = `/workspaces/current/model-providers/${provider}`
}
else {
if (v) {
@ -134,7 +133,7 @@ export const removeCredentials = async (predefined: boolean, pluginID: string, p
model: __model_name,
model_type: __model_type,
}
url = `/workspaces/current/model-providers/${pluginID}/${provider}/models`
url = `/workspaces/current/model-providers/${provider}/models`
}
}