mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-24 23:46:52 +08:00
### What problem does this PR solve? Fix: Document Previewer is not working #9606 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { LlmModelType } from '@/constants/knowledge';
|
|
import userService from '@/services/user-service';
|
|
import { useQuery } from '@tanstack/react-query';
|
|
|
|
import {
|
|
IThirdOAIModelCollection as IThirdAiModelCollection,
|
|
IThirdOAIModel,
|
|
} from '@/interfaces/database/llm';
|
|
import { buildLlmUuid } from '@/utils/llm-util';
|
|
|
|
export const enum LLMApiAction {
|
|
LlmList = 'llmList',
|
|
}
|
|
|
|
export const useFetchLlmList = (modelType?: LlmModelType) => {
|
|
const { data } = useQuery<IThirdAiModelCollection>({
|
|
queryKey: [LLMApiAction.LlmList],
|
|
initialData: {},
|
|
queryFn: async () => {
|
|
const { data } = await userService.llm_list({ model_type: modelType });
|
|
|
|
return data?.data ?? {};
|
|
},
|
|
});
|
|
|
|
return data;
|
|
};
|
|
|
|
type IThirdOAIModelWithUuid = IThirdOAIModel & { uuid: string };
|
|
|
|
export function useSelectFlatLlmList(modelType?: LlmModelType) {
|
|
const llmList = useFetchLlmList(modelType);
|
|
|
|
return Object.values(llmList).reduce<IThirdOAIModelWithUuid[]>((pre, cur) => {
|
|
pre.push(...cur.map((x) => ({ ...x, uuid: buildLlmUuid(x) })));
|
|
|
|
return pre;
|
|
}, []);
|
|
}
|
|
|
|
export function useFindLlmByUuid(modelType?: LlmModelType) {
|
|
const flatList = useSelectFlatLlmList(modelType);
|
|
|
|
return (uuid: string) => {
|
|
return flatList.find((x) => x.uuid === uuid);
|
|
};
|
|
}
|