Skip to content
Source
Sign inSign up
TanStack/cli
Open History to see the last commit

example.ai-hook.ts

22 lines676 Bytes

1import {
2 fetchServerSentEvents,
3 useChat,
4 createChatClientOptions,
5} from "@tanstack/ai-react";
6import type { InferChatMessages } from "@tanstack/ai-react";
7import { clientTools } from "@tanstack/ai-client";
8​
9import { recommendGuitarToolDef } from "@/lib/example.guitar-tools";
10​
11const recommendGuitarToolClient = recommendGuitarToolDef.client(({ id }) => ({
12 id: +id,
13}));
14​
15const chatOptions = createChatClientOptions({
16 connection: fetchServerSentEvents("/demo/api/tanchat"),
17 tools: clientTools(recommendGuitarToolClient),
18});
19​
20export type ChatMessages = InferChatMessages<typeof chatOptions>;
21​
22export const useGuitarRecommendationChat = () => useChat(chatOptions);