mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
useQuery for model list
This commit is contained in:
parent
f2bf2e4470
commit
59a9235041
|
@ -1,19 +1,14 @@
|
|||
import React from 'react'
|
||||
import useSWR from 'swr'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { usePluginPageContext } from '@/app/components/plugins/plugin-page/context'
|
||||
import ModelIcon from '@/app/components/header/account-setting/model-provider-page/model-icon'
|
||||
import ModelName from '@/app/components/header/account-setting/model-provider-page/model-name'
|
||||
import { fetchModelProviderModelList } from '@/service/common'
|
||||
import { useModelProviderModelList } from '@/service/use-models'
|
||||
|
||||
const ModelList = () => {
|
||||
const { t } = useTranslation()
|
||||
const currentPluginDetail = usePluginPageContext(v => v.currentPluginDetail)
|
||||
|
||||
const { data: res } = useSWR(
|
||||
`/workspaces/current/model-providers/${currentPluginDetail.plugin_id}/${currentPluginDetail.name}/models`,
|
||||
fetchModelProviderModelList,
|
||||
)
|
||||
const { data: res } = useModelProviderModelList(`${currentPluginDetail.plugin_id}/${currentPluginDetail.name}`)
|
||||
|
||||
if (!res)
|
||||
return null
|
||||
|
|
17
web/service/use-models.ts
Normal file
17
web/service/use-models.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { get } from './base'
|
||||
import type {
|
||||
ModelItem,
|
||||
} from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||
import {
|
||||
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`),
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user