import { generateText, tool, stepCountIs } from 'ai';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';
const result = await generateText({
model: openai('gpt-4'),
tools: {
weather: tool({
description: 'Get the weather in a location',
inputSchema: z.object({
location: z.string(),
}),
execute: async ({ location }) => ({
location,
temperature: 72,
}),
}),
cityAttractions: tool({
description: 'Get attractions in a city',
inputSchema: z.object({
city: z.string(),
}),
execute: async ({ city }) => ({
attractions: ['Golden Gate Bridge', 'Alcatraz'],
}),
}),
},
prompt: 'What is the weather in San Francisco and what should I visit?',
stopWhen: stepCountIs(10), // Allow up to 10 steps
});