mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-20 07:00:09 +08:00
feat(hooks): add useModels hook for fetching agent models
This commit is contained in:
parent
f35987a9a9
commit
8efafc6ba9
19
src/renderer/src/hooks/agents/useModels.ts
Normal file
19
src/renderer/src/hooks/agents/useModels.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { ApiModelsFilter } from '@renderer/types'
|
||||||
|
import { useCallback } from 'react'
|
||||||
|
import useSWR from 'swr'
|
||||||
|
|
||||||
|
import { useAgentClient } from './useAgentClient'
|
||||||
|
|
||||||
|
export const useModels = (filter: ApiModelsFilter) => {
|
||||||
|
const client = useAgentClient()
|
||||||
|
const path = client.getModelsPath(filter)
|
||||||
|
const fetcher = useCallback(() => {
|
||||||
|
return client.getModels(filter)
|
||||||
|
}, [client, filter])
|
||||||
|
const { data, error, isLoading } = useSWR(path, fetcher)
|
||||||
|
return {
|
||||||
|
models: data?.data,
|
||||||
|
error,
|
||||||
|
isLoading
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user