Skip to content

Commit

Permalink
Merge branch 'feat/model-provider-based-on-runtime' into deploy/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
zxhlyh committed Dec 28, 2023
2 parents 582ca01 + ef63077 commit c024882
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export enum ModelTypeEnum {
moderation = 'moderation',
}

export const MODEL_TYPE_TEXT = {
[ModelTypeEnum.textGeneration]: 'LLM',
[ModelTypeEnum.textEmbedding]: 'Text Embedding',
[ModelTypeEnum.rerank]: 'Rerank',
[ModelTypeEnum.speech2text]: 'Speech2text',
[ModelTypeEnum.moderation]: 'Moderation',
}

export enum ConfigurateMethodEnum {
predefinedModel = 'predefined-model',
customizableModel = 'customizable-model',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
DefaultModel,
DefaultModelResponse,
Model,
ModelProvider,
} from './declarations'
import {
ConfigurateMethodEnum,
Expand Down Expand Up @@ -263,11 +262,9 @@ export const useUpdateModelProvidersAndModelList = () => {
const { mutate } = useSWRConfig()
const updateModelList = useUpdateModelList()

const updateModelProvidersAndModelList = useCallback((provider: ModelProvider) => {
const updateModelProvidersAndModelList = useCallback(() => {
mutate('/workspaces/current/model-providers')
provider?.supported_model_types.forEach((modelType) => {
updateModelList(modelType)
})
updateModelList(1)
}, [mutate, updateModelList])

return updateModelProvidersAndModelList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ const ModelProviderPage = () => {
currentCustomConfigrationModelFixedFields: customConfigrationModelFixedFields,
},
onSaveCallback: () => {
updateModelProvidersAndModelList(provider)
updateModelProvidersAndModelList()

if (customConfigrationModelFixedFields && provider.custom_configuration.status === CustomConfigurationStatusEnum.active) {
console.log('1')
eventEmitter?.emit({
type: UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST,
payload: provider.provider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import type {
} from '../declarations'
import {
useLanguage,
useUpdateModelList,
useUpdateModelProvidersAndModelList,
} from '../hooks'
import ModelIcon from '../model-icon'
import ModelName from '../model-name'
import {
ConfigurateMethodEnum,
ModelStatusEnum,
ModelTypeEnum,
} from '../declarations'
import { Check } from '@/app/components/base/icons/src/vender/line/general'
import { useModalContext } from '@/context/modal-context'
Expand All @@ -33,6 +35,7 @@ const PopupItem: FC<PopupItemProps> = ({
const language = useLanguage()
const { setShowModelModal } = useModalContext()
const { modelProviders } = useProviderContext()
const updateModelList = useUpdateModelList()
const updateModelProvidersAndModelList = useUpdateModelProvidersAndModelList()
const currentProvider = modelProviders.find(provider => provider.provider === model.provider)!
const handleSelect = (provider: string, modelItem: ModelItem) => {
Expand All @@ -48,7 +51,12 @@ const PopupItem: FC<PopupItemProps> = ({
currentConfigurateMethod: ConfigurateMethodEnum.predefinedModel,
},
onSaveCallback: () => {
updateModelProvidersAndModelList(currentProvider)
updateModelProvidersAndModelList()

const modelType = model.models[0].model_type

if (modelType !== ModelTypeEnum.textGeneration)
updateModelList(modelType)
},
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const ProviderAddedCard: FC<ProviderAddedCardProps> = ({
const showQuota = systemConfig.enabled || ['minimax', 'spark', 'zhipuai', 'anthropic'].includes(provider.provider)

const getModelList = async (providerName: string) => {
console.log('3')
if (loading)
return
try {
Expand All @@ -67,9 +66,8 @@ const ProviderAddedCard: FC<ProviderAddedCardProps> = ({
}

eventEmitter?.useSubscription((v: any) => {
console.log('2')
if (v?.type === UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST)
getModelList(v.payload as string)
if (v?.type === UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST && v.payload === provider.provider)
getModelList(v.payload)
})

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
} from './declarations'
import {
FormTypeEnum,
MODEL_TYPE_TEXT,
ModelTypeEnum,
} from './declarations'
import {
Expand Down Expand Up @@ -123,15 +124,12 @@ export const genModelTypeFormSchema = (modelTypes: ModelTypeEnum[]) => {
default: modelTypes[0],
required: true,
show_on: [],
options: modelTypes.map((modelType) => {
const text = modelType.replace(/\b(\w)(\w*)\b/g, (match, first, second) => {
return `${first.toUpperCase()}${second.toLowerCase()}`
}).replace(/-/g, ' ')
options: modelTypes.map((modelType: ModelTypeEnum) => {
return {
value: modelType,
label: {
zh_Hans: text,
en_US: text,
zh_Hans: MODEL_TYPE_TEXT[modelType],
en_US: MODEL_TYPE_TEXT[modelType],
},
show_on: [],
}
Expand Down

0 comments on commit c024882

Please sign in to comment.