Files
dify/web/service/use-models.ts
+40 5bbf685035 feat: fix i18n missing keys and merge upstream/main (#24615)
Signed-off-by: -LAN- <[email protected]>
Signed-off-by: kenwoodjw <[email protected]>
Signed-off-by: Yongtao Huang <[email protected]>
Signed-off-by: yihong0618 <[email protected]>
Signed-off-by: zhanluxianshen <[email protected]>
Co-authored-by: -LAN- <[email protected]>
Co-authored-by: GuanMu <[email protected]>
Co-authored-by: Davide Delbianco <[email protected]>
Co-authored-by: NeatGuyCoding <[email protected]>
Co-authored-by: kenwoodjw <[email protected]>
Co-authored-by: Yongtao Huang <[email protected]>
Co-authored-by: Yongtao Huang <[email protected]>
Co-authored-by: Qiang Lee <[email protected]>
Co-authored-by: 李强04 <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Asuka Minato <[email protected]>
Co-authored-by: Matri Qi <[email protected]>
Co-authored-by: huayaoyue6 <[email protected]>
Co-authored-by: Bowen Liang <[email protected]>
Co-authored-by: znn <[email protected]>
Co-authored-by: crazywoola <[email protected]>
Co-authored-by: crazywoola <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: yihong <[email protected]>
Co-authored-by: Muke Wang <[email protected]>
Co-authored-by: wangmuke <[email protected]>
Co-authored-by: Wu Tianwei <[email protected]>
Co-authored-by: quicksand <[email protected]>
Co-authored-by: 非法操作 <[email protected]>
Co-authored-by: zxhlyh <[email protected]>
Co-authored-by: Eric Guo <[email protected]>
Co-authored-by: Zhedong Cen <[email protected]>
Co-authored-by: jiangbo721 <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: hjlarry <[email protected]>
Co-authored-by: lxsummer <[email protected]>
Co-authored-by: 湛露先生 <[email protected]>
Co-authored-by: Guangdong Liu <[email protected]>
Co-authored-by: QuantumGhost <[email protected]>
Co-authored-by: Claude <[email protected]>
Co-authored-by: Yessenia-d <[email protected]>
Co-authored-by: huangzhuo1949 <[email protected]>
Co-authored-by: huangzhuo <[email protected]>
Co-authored-by: 17hz <[email protected]>
Co-authored-by: Amy <[email protected]>
Co-authored-by: Joel <[email protected]>
Co-authored-by: Nite Knite <[email protected]>
Co-authored-by: Yeuoly <[email protected]>
Co-authored-by: Petrus Han <[email protected]>
Co-authored-by: iamjoel <[email protected]>
Co-authored-by: Kalo Chin <[email protected]>
Co-authored-by: Ujjwal Maurya <[email protected]>
Co-authored-by: Maries <[email protected]>
2025-08-27 15:07:28 +08:00

156 lines
4.5 KiB
TypeScript

import {
del,
get,
post,
put,
} from './base'
import type {
ModelCredential,
ModelItem,
ModelLoadBalancingConfig,
ModelTypeEnum,
ProviderCredential,
} from '@/app/components/header/account-setting/model-provider-page/declarations'
import {
useMutation,
useQuery,
// useQueryClient,
} from '@tanstack/react-query'
const NAME_SPACE = 'models'
export const useModelProviderModelList = (provider: string) => {
return useQuery({
queryKey: [NAME_SPACE, 'model-list', provider],
queryFn: () => get<{ data: ModelItem[] }>(`/workspaces/current/model-providers/${provider}/models`),
})
}
export const useGetProviderCredential = (enabled: boolean, provider: string, credentialId?: string) => {
return useQuery({
enabled,
queryKey: [NAME_SPACE, 'model-list', provider, credentialId],
queryFn: () => get<ProviderCredential>(`/workspaces/current/model-providers/${provider}/credentials${credentialId ? `?credential_id=${credentialId}` : ''}`),
})
}
export const useAddProviderCredential = (provider: string) => {
return useMutation({
mutationFn: (data: ProviderCredential) => post<{ result: string }>(`/workspaces/current/model-providers/${provider}/credentials`, {
body: data,
}),
})
}
export const useEditProviderCredential = (provider: string) => {
return useMutation({
mutationFn: (data: ProviderCredential) => put<{ result: string }>(`/workspaces/current/model-providers/${provider}/credentials`, {
body: data,
}),
})
}
export const useDeleteProviderCredential = (provider: string) => {
return useMutation({
mutationFn: (data: {
credential_id: string
}) => del<{ result: string }>(`/workspaces/current/model-providers/${provider}/credentials`, {
body: data,
}),
})
}
export const useActiveProviderCredential = (provider: string) => {
return useMutation({
mutationFn: (data: {
credential_id: string
model?: string
model_type?: ModelTypeEnum
}) => post<{ result: string }>(`/workspaces/current/model-providers/${provider}/credentials/switch`, {
body: data,
}),
})
}
export const useGetModelCredential = (
enabled: boolean,
provider: string,
credentialId?: string,
model?: string,
modelType?: string,
configFrom?: string,
) => {
return useQuery({
enabled,
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,
})
}
export const useAddModelCredential = (provider: string) => {
return useMutation({
mutationFn: (data: ModelCredential) => post<{ result: string }>(`/workspaces/current/model-providers/${provider}/models/credentials`, {
body: data,
}),
})
}
export const useEditModelCredential = (provider: string) => {
return useMutation({
mutationFn: (data: ModelCredential) => put<{ result: string }>(`/workspaces/current/model-providers/${provider}/models/credentials`, {
body: data,
}),
})
}
export const useDeleteModelCredential = (provider: string) => {
return useMutation({
mutationFn: (data: {
credential_id: string
model?: string
model_type?: ModelTypeEnum
}) => del<{ result: string }>(`/workspaces/current/model-providers/${provider}/models/credentials`, {
body: data,
}),
})
}
export const useDeleteModel = (provider: string) => {
return useMutation({
mutationFn: (data: {
model: string
model_type: ModelTypeEnum
}) => del<{ result: string }>(`/workspaces/current/model-providers/${provider}/models/credentials`, {
body: data,
}),
})
}
export const useActiveModelCredential = (provider: string) => {
return useMutation({
mutationFn: (data: {
credential_id: string
model?: string
model_type?: ModelTypeEnum
}) => post<{ result: string }>(`/workspaces/current/model-providers/${provider}/models/credentials/switch`, {
body: data,
}),
})
}
export const useUpdateModelLoadBalancingConfig = (provider: string) => {
return useMutation({
mutationFn: (data: {
config_from: string
model: string
model_type: ModelTypeEnum
load_balancing: ModelLoadBalancingConfig
credential_id?: string
}) => post<{ result: string }>(`/workspaces/current/model-providers/${provider}/models`, {
body: data,
}),
})
}