update model provider api responses

This commit is contained in:
JzoNg 2024-10-30 09:08:46 +08:00
parent 1387c6bd1c
commit c8dc5e4849
4 changed files with 30 additions and 20 deletions

View File

@ -1,6 +1,6 @@
export type FormValue = Record<string, any>
export interface TypeWithI18N<T = string> {
export type TypeWithI18N<T = string> = {
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[]
}

View File

@ -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 {

View File

@ -94,6 +94,7 @@ 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,
}

View File

@ -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<string, string | undefined | boolean>
load_balancing: ModelLoadBalancingConfig
}
@ -297,7 +297,7 @@ export const moderate = (url: string, body: { app_id: string; text: string }) =>
return post(url, { body }) as Promise<ModerateResponse>
}
interface RetrievalMethodsRes {
type RetrievalMethodsRes = {
retrieval_method: RETRIEVE_METHOD[]
}
export const fetchSupportRetrievalMethods: Fetcher<RetrievalMethodsRes, string> = (url) => {