allow creating and listing custom language model (#134)

This commit is contained in:
Will Chen
2025-05-12 16:00:16 -07:00
committed by GitHub
parent c63781d7cc
commit 477015b43d
13 changed files with 925 additions and 291 deletions

View File

@@ -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();

View 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,
});
}