Skip to content

Commit abeda72

Browse files
committed
Use AI Gateway
1 parent 5c32447 commit abeda72

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
1-
import { createFileRoute } from '@tanstack/react-router'
2-
import { anthropic } from '@ai-sdk/anthropic'
3-
import { convertToModelMessages, stepCountIs, streamText } from 'ai'
1+
import { createFileRoute } from "@tanstack/react-router";
42

5-
import getTools from '@/utils/demo.tools'
3+
import { convertToModelMessages, stepCountIs, streamText } from "ai";
4+
5+
import getTools from "@/utils/demo.tools";
66

77
const SYSTEM_PROMPT = `You are a helpful assistant for a store that sells guitars.
88
99
You can use the following tools to help the user:
1010
1111
- getGuitars: Get all guitars from the database
1212
- recommendGuitar: Recommend a guitar to the user
13-
`
13+
`;
1414

15-
export const Route = createFileRoute('/demo/api/tanchat')({
15+
export const Route = createFileRoute("/demo/api/tanchat")({
1616
server: {
1717
handlers: {
1818
POST: async ({ request }) => {
1919
try {
20-
const { messages } = await request.json()
20+
const { messages } = await request.json();
2121

22-
const tools = await getTools()
22+
const tools = await getTools();
2323

2424
const result = await streamText({
25-
model: anthropic('claude-haiku-4-5'),
25+
model: "anthropic/claude-haiku-4-5",
2626
messages: convertToModelMessages(messages),
2727
temperature: 0.7,
2828
stopWhen: stepCountIs(5),
2929
system: SYSTEM_PROMPT,
3030
tools,
31-
})
31+
});
3232

33-
return result.toUIMessageStreamResponse()
33+
return result.toUIMessageStreamResponse();
3434
} catch (error) {
35-
console.error('Chat API error:', error)
35+
console.error("Chat API error:", error);
3636
return new Response(
37-
JSON.stringify({ error: 'Failed to process chat request' }),
37+
JSON.stringify({ error: "Failed to process chat request" }),
3838
{
3939
status: 500,
40-
headers: { 'Content-Type': 'application/json' },
41-
},
42-
)
40+
headers: { "Content-Type": "application/json" },
41+
}
42+
);
4343
}
4444
},
4545
},
4646
},
47-
})
47+
});

0 commit comments

Comments
 (0)