mirror of
https://github.com/langgenius/dify.git
synced 2026-04-27 14:08:18 +08:00
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import {
|
|
del,
|
|
get,
|
|
post,
|
|
} from './base'
|
|
import type {
|
|
ModelItem,
|
|
} 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 useAddModelCredential = (providerName: string) => {
|
|
return useMutation({
|
|
mutationFn: (data: any) => post<{ result: string }>(`/workspaces/current/model-providers/${providerName}/credentials`, data),
|
|
})
|
|
}
|
|
|
|
export const useGetModelCredential = (providerName: string, credentialId: string) => {
|
|
return useQuery({
|
|
queryKey: [NAME_SPACE, 'model-credential', providerName, credentialId],
|
|
queryFn: () => get<{ data: Credential[] }>(`/workspaces/current/model-providers/${providerName}/credentials?credential_id=${credentialId}`),
|
|
})
|
|
}
|
|
|
|
export const useDeleteModelCredential = (providerName: string) => {
|
|
return useMutation({
|
|
mutationFn: (credentialId: string) => del<{ result: string }>(`/workspaces/current/model-providers/${providerName}/credentials`, {
|
|
body: {
|
|
credential_id: credentialId,
|
|
},
|
|
}),
|
|
})
|
|
}
|