import { generateText, tool } from 'ai';
import { z } from 'zod';
const result = await generateText({
model: 'openai/gpt-5.5',
tools: {
getWeather: tool({
description: '获取指定城市的当前天气',
parameters: z.object({
city: z.string().describe('城市名称,如"北京"'),
}),
execute: async ({ city }) => {
// 调用天气 API
return { city, temperature: 25, condition: '晴' };
},
}),
},
prompt: '北京今天天气怎么样?',
});
console.log(result.toolResults); // 包含工具调用结果