feat: support dynamic loading models

This commit is contained in:
Henry Li
2026-01-19 18:54:04 +08:00
parent 1a7c853811
commit 541586dc66
5 changed files with 49 additions and 23 deletions

View File

@@ -0,0 +1,9 @@
import { getBackendBaseURL } from "../config";
import type { Model } from "./types";
export async function loadModels() {
const res = fetch(`${getBackendBaseURL()}/api/models`);
const { models } = (await (await res).json()) as { models: Model[] };
return models;
}

View File

@@ -0,0 +1,11 @@
import { useQuery } from "@tanstack/react-query";
import { loadModels } from "./api";
export function useModels() {
const { data, isLoading, error } = useQuery({
queryKey: ["models"],
queryFn: () => loadModels(),
});
return { models: data ?? [], isLoading, error };
}

View File

@@ -0,0 +1,2 @@
export * from "./api";
export * from "./types";

View File

@@ -0,0 +1,7 @@
export interface Model {
id: string;
name: string;
display_name: string;
description?: string | null;
supports_thinking?: boolean;
}