Skip to content

Commit 414b264

Browse files
NiallJoeMaherclaude
andcommitted
workshop: add Chapter 1 preview stubs (weather tool)
- Add lib/ai/tools/get-weather.ts with TODO placeholder - Add TODO comment in route.ts showing where to wire tools - Provides clear starting point for Chapter 1 implementation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 40d3dd9 commit 414b264

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

app/(chat)/api/chat/route.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ export async function POST(request: Request) {
171171

172172
const stream = createUIMessageStream({
173173
execute: ({ writer: dataStream }) => {
174+
// TODO CHAPTER 1: Add tools to streamText
175+
// Import the weather tool:
176+
// import { getWeather } from "@/lib/ai/tools/get-weather";
177+
//
178+
// Then add these options to streamText below:
179+
// stopWhen: stepCountIs(5),
180+
// experimental_activeTools:
181+
// selectedChatModel === "chat-model-reasoning" ? [] : ["getWeather"],
182+
// tools: {
183+
// getWeather,
184+
// },
185+
//
186+
// See CHAPTER-1.md for complete implementation details.
187+
174188
const result = streamText({
175189
model: myProvider.languageModel(selectedChatModel),
176190
system: systemPrompt({ selectedChatModel, requestHints }),

lib/ai/tools/get-weather.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { tool } from "ai";
2+
import { z } from "zod";
3+
4+
// TODO CHAPTER 1: Implement the weather tool
5+
//
6+
// This tool should:
7+
// 1. Accept a city name OR latitude/longitude coordinates
8+
// 2. Geocode the city to coordinates using Open-Meteo Geocoding API
9+
// 3. Fetch weather data from Open-Meteo Weather API
10+
// 4. Return temperature and weather data
11+
//
12+
// Key implementation steps:
13+
// - Create a geocodeCity() helper function
14+
// - Handle both city and coordinate inputs
15+
// - Return helpful error messages if geocoding fails
16+
//
17+
// See CHAPTER-1.md for the complete implementation.
18+
19+
/**
20+
* Weather Tool - Gets current weather for a location
21+
*
22+
* Accepts either:
23+
* - city: A city name like "San Francisco" or "London"
24+
* - latitude + longitude: Coordinates like 37.7749, -122.4194
25+
*/
26+
export const getWeather = tool({
27+
description:
28+
"Get the current weather at a location. You can provide either coordinates or a city name.",
29+
inputSchema: z.object({
30+
latitude: z.number().optional(),
31+
longitude: z.number().optional(),
32+
city: z
33+
.string()
34+
.describe("City name (e.g., 'San Francisco', 'New York', 'London')")
35+
.optional(),
36+
}),
37+
execute: async () => {
38+
// TODO: Implement in Chapter 1
39+
// 1. If city provided, geocode it to lat/long
40+
// 2. Fetch weather data from Open-Meteo API
41+
// 3. Return the weather data
42+
43+
// Placeholder await to satisfy linter (remove when implementing)
44+
await Promise.resolve();
45+
46+
return {
47+
todo: "Implement weather tool in Chapter 1",
48+
hint: "See CHAPTER-1.md for the complete implementation",
49+
};
50+
},
51+
});

0 commit comments

Comments
 (0)