import { chat, toolDefinition } from '@tanstack/ai';
import { createOpenaiChat } from '@tanstack/ai-openai';
import type { OpenAIChatModel } from '@tanstack/ai-openai';
import { z } from 'zod';
const adapter = createOpenaiChat(
'google/gemma-3-27b-it' as OpenAIChatModel,
process.env.SUPA_API_KEY!,
{ baseURL: 'https://api.supa.works/openai/v1' },
);
const getWeather = toolDefinition({
name: 'get_weather',
description: 'Get the current weather for a city',
inputSchema: z.object({
city: z.string(),
unit: z.enum(['celsius', 'fahrenheit']).optional(),
}),
outputSchema: z.object({
city: z.string(),
temperature: z.number(),
summary: z.string(),
}),
}).server(async ({ city, unit }) => ({
city,
temperature: 72,
summary: 'Sunny',
}));
await chat({
adapter,
stream: false,
messages: [
{
role: 'user',
content: [{ type: 'text', content: 'What is the weather in Boston?' }],
},
],
tools: [getWeather],
});