From c8dc5e484937136b4466bf3a37d6de58606a0234 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Wed, 30 Oct 2024 09:08:46 +0800 Subject: [PATCH] update model provider api responses --- .../model-provider-page/declarations.ts | 32 +++++++++++-------- .../model-provider-page/hooks.ts | 9 ++++-- .../system-model-selector/index.tsx | 1 + web/service/common.ts | 8 ++--- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/web/app/components/header/account-setting/model-provider-page/declarations.ts b/web/app/components/header/account-setting/model-provider-page/declarations.ts index c50a17c6b2..930ae4b852 100644 --- a/web/app/components/header/account-setting/model-provider-page/declarations.ts +++ b/web/app/components/header/account-setting/model-provider-page/declarations.ts @@ -1,6 +1,6 @@ export type FormValue = Record -export interface TypeWithI18N { +export type TypeWithI18N = { en_US: T zh_Hans: T [key: string]: T @@ -17,7 +17,7 @@ export enum FormTypeEnum { file = 'file', } -export interface FormOption { +export type FormOption = { label: TypeWithI18N value: string show_on: FormShowOnObject[] @@ -89,12 +89,12 @@ export enum CustomConfigurationStatusEnum { noConfigure = 'no-configure', } -export interface FormShowOnObject { +export type FormShowOnObject = { variable: string value: string } -export interface CredentialFormSchemaBase { +export type 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 interface ModelItem { +export type ModelItem = { model: string label: TypeWithI18N model_type: ModelTypeEnum @@ -141,7 +141,7 @@ export enum QuotaUnitEnum { credits = 'credits', } -export interface QuotaConfiguration { +export type QuotaConfiguration = { quota_type: CurrentSystemQuotaTypeEnum quota_unit: QuotaUnitEnum quota_limit: number @@ -150,7 +150,8 @@ export interface QuotaConfiguration { is_valid: boolean } -export interface ModelProvider { +export type ModelProvider = { + plugin_id: string provider: string label: TypeWithI18N description?: TypeWithI18N @@ -184,7 +185,8 @@ export interface ModelProvider { } } -export interface Model { +export type Model = { + plugin_id: string provider: string icon_large: TypeWithI18N icon_small: TypeWithI18N @@ -193,27 +195,29 @@ export interface Model { status: ModelStatusEnum } -export interface DefaultModelResponse { +export type DefaultModelResponse = { model: string model_type: ModelTypeEnum provider: { + plugin_id: string provider: string icon_large: TypeWithI18N icon_small: TypeWithI18N } } -export interface DefaultModel { +export type DefaultModel = { + plugin_id: string provider: string model: string } -export interface CustomConfigurationModelFixedFields { +export type CustomConfigurationModelFixedFields = { __model_name: string __model_type: ModelTypeEnum } -export interface ModelParameterRule { +export type ModelParameterRule = { default?: number | string | boolean | string[] help?: TypeWithI18N label: TypeWithI18N @@ -228,7 +232,7 @@ export interface ModelParameterRule { tagPlaceholder?: TypeWithI18N } -export interface ModelLoadBalancingConfigEntry { +export type ModelLoadBalancingConfigEntry = { /** model balancing config entry id */ id?: string /** is config entry enabled */ @@ -243,7 +247,7 @@ export interface ModelLoadBalancingConfigEntry { ttl?: number } -export interface ModelLoadBalancingConfig { +export type ModelLoadBalancingConfig = { enabled: boolean configs: ModelLoadBalancingConfigEntry[] } diff --git a/web/app/components/header/account-setting/model-provider-page/hooks.ts b/web/app/components/header/account-setting/model-provider-page/hooks.ts index 54396cc538..95bbd24f4a 100644 --- a/web/app/components/header/account-setting/model-provider-page/hooks.ts +++ b/web/app/components/header/account-setting/model-provider-page/hooks.ts @@ -36,11 +36,12 @@ export const useSystemDefaultModelAndModelList: UseDefaultModelAndModelList = ( modelList, ) => { const currentDefaultModel = useMemo(() => { - const currentProvider = modelList.find(provider => provider.provider === defaultModel?.provider.provider) + const currentProvider = modelList.find(provider => provider.provider === defaultModel?.provider.provider && provider.plugin_id === defaultModel?.provider.plugin_id) 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 @@ -172,7 +173,11 @@ export const useModelListAndDefaultModelAndCurrentProviderAndModel = (type: Mode const { modelList, defaultModel } = useModelListAndDefaultModel(type) const { currentProvider, currentModel } = useCurrentProviderAndModel( modelList, - { provider: defaultModel?.provider.provider || '', model: defaultModel?.model || '' }, + { + plugin_id: defaultModel?.provider.plugin_id || '', + provider: defaultModel?.provider.provider || '', + model: defaultModel?.model || '', + }, ) return { diff --git a/web/app/components/header/account-setting/model-provider-page/system-model-selector/index.tsx b/web/app/components/header/account-setting/model-provider-page/system-model-selector/index.tsx index 846738d4ae..d125bd99fb 100644 --- a/web/app/components/header/account-setting/model-provider-page/system-model-selector/index.tsx +++ b/web/app/components/header/account-setting/model-provider-page/system-model-selector/index.tsx @@ -94,6 +94,7 @@ const SystemModel: FC = ({ 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, } diff --git a/web/service/common.ts b/web/service/common.ts index d3c07f3c1d..1fc9b60f45 100644 --- a/web/service/common.ts +++ b/web/service/common.ts @@ -38,11 +38,11 @@ import type { import type { RETRIEVE_METHOD } from '@/types/app' import type { SystemFeatures } from '@/types/feature' -interface LoginSuccess { +type LoginSuccess = { result: 'success' data: { access_token: string;refresh_token: string } } -interface LoginFail { +type LoginFail = { result: 'fail' data: string code: string @@ -183,7 +183,7 @@ export const fetchModelProviders: Fetcher<{ data: ModelProvider[] }, string> = ( return get<{ data: ModelProvider[] }>(url) } -export interface ModelProviderCredentials { +export type ModelProviderCredentials = { credentials?: Record load_balancing: ModelLoadBalancingConfig } @@ -297,7 +297,7 @@ export const moderate = (url: string, body: { app_id: string; text: string }) => return post(url, { body }) as Promise } -interface RetrievalMethodsRes { +type RetrievalMethodsRes = { retrieval_method: RETRIEVE_METHOD[] } export const fetchSupportRetrievalMethods: Fetcher = (url) => {