allow creating and listing custom language model (#134)
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { IpcClient } from "@/ipc/ipc_client";
|
||||
import type { LanguageModelProvider } from "@/ipc/ipc_types";
|
||||
import type {
|
||||
CreateCustomLanguageModelProviderParams,
|
||||
LanguageModelProvider,
|
||||
} from "@/ipc/ipc_types";
|
||||
import { showError } from "@/lib/toast";
|
||||
|
||||
export interface CreateCustomLanguageModelProviderParams {
|
||||
id: string;
|
||||
name: string;
|
||||
apiBaseUrl: string;
|
||||
envVarName?: string;
|
||||
}
|
||||
|
||||
export function useCustomLanguageModelProvider() {
|
||||
const queryClient = useQueryClient();
|
||||
const ipcClient = IpcClient.getInstance();
|
||||
|
||||
29
src/hooks/useLanguageModelsForProvider.ts
Normal file
29
src/hooks/useLanguageModelsForProvider.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { IpcClient } from "@/ipc/ipc_client";
|
||||
import type { LanguageModel } from "@/ipc/ipc_types";
|
||||
|
||||
/**
|
||||
* Fetches the list of available language models for a specific provider.
|
||||
*
|
||||
* @param providerId The ID of the language model provider.
|
||||
* @returns TanStack Query result object for the language models.
|
||||
*/
|
||||
export function useLanguageModelsForProvider(providerId: string | undefined) {
|
||||
const ipcClient = IpcClient.getInstance();
|
||||
|
||||
return useQuery<
|
||||
LanguageModel[],
|
||||
Error // Specify Error type for better error handling
|
||||
>({
|
||||
queryKey: ["language-models", providerId],
|
||||
queryFn: async () => {
|
||||
if (!providerId) {
|
||||
// Avoid calling IPC if providerId is not set
|
||||
// Return an empty array as it's a query, not an error state
|
||||
return [];
|
||||
}
|
||||
return ipcClient.getLanguageModels({ providerId });
|
||||
},
|
||||
enabled: !!providerId,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user