/ai/models route

This commit is contained in:
2026-01-31 14:16:12 +00:00
parent 8196fb0bf6
commit 95beddaa6c
7 changed files with 45 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
import type { ChatRequest, ChatResponse } from "@sprint/shared";
import type { ChatRequest, ChatResponse, ModelsResponse } from "@sprint/shared";
import { useMutation } from "@tanstack/react-query";
import { apiClient } from "@/lib/server";
@@ -13,3 +13,15 @@ export function useChatMutation() {
},
});
}
export function useModels() {
return useMutation<ModelsResponse, Error>({
mutationKey: ["ai", "models"],
mutationFn: async () => {
const { data, error } = await apiClient.aiModels();
if (error) throw new Error(error);
if (!data) throw new Error("failed to get models");
return data as ModelsResponse;
},
});
}