Skip to content

Commit 50b4310

Browse files
committed
docs: update README with new examples for tool calling and structured generation using Vercel AI SDK
1 parent 95cf51e commit 50b4310

File tree

1 file changed

+66
-8
lines changed

1 file changed

+66
-8
lines changed

README.md

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ bun add ai zod
2828
### Native Apple AI Interface
2929

3030
```typescript
31-
import { chat, appleAISDK } from "@meridius-labs/apple-on-device-ai";
31+
import { chat } from "@meridius-labs/apple-on-device-ai";
3232

3333
// Simple text generation
3434
const response = await chat({ messages: "What is the capital of France?" });
@@ -99,22 +99,20 @@ console.log(withTools.toolCalls); // [{ function: { name: "calculator" }, ... }]
9999
### Vercel AI SDK Integration
100100

101101
```typescript
102-
import { createAppleAI } from "@meridius-labs/apple-on-device-ai";
102+
import { appleAI } from "@meridius-labs/apple-on-device-ai";
103103
import { generateText, streamText, generateObject } from "ai";
104104
import { z } from "zod";
105105

106-
const ai = createAppleAI();
107-
108106
// Text generation
109107
const { text } = await generateText({
110-
model: ai("apple-on-device"),
108+
model: appleAI(),
111109
messages: [{ role: "user", content: "Explain quantum computing" }],
112110
});
113111
console.log(text);
114112

115113
// Streaming
116114
const { textStream } = await streamText({
117-
model: ai("apple-on-device"),
115+
model: appleAI(),
118116
messages: [{ role: "user", content: "Write a poem about technology" }],
119117
});
120118
for await (const delta of textStream) {
@@ -123,7 +121,7 @@ for await (const delta of textStream) {
123121

124122
// Structured object generation
125123
const { object } = await generateObject({
126-
model: ai("apple-on-device"),
124+
model: appleAI(),
127125
prompt: "Generate a chocolate chip cookie recipe",
128126
schema: z.object({
129127
recipe: z.object({
@@ -137,7 +135,7 @@ console.log(object);
137135

138136
// Tool calling
139137
const { text, toolCalls } = await generateText({
140-
model: ai("apple-on-device"),
138+
model: appleAI(),
141139
messages: [{ role: "user", content: "What's the weather in Tokyo?" }],
142140
tools: {
143141
weather: {
@@ -154,6 +152,66 @@ const { text, toolCalls } = await generateText({
154152
console.log(toolCalls);
155153
```
156154

155+
### Tool Calling & Structured Generation with Vercel AI SDK
156+
157+
#### Tool Calling Example
158+
159+
You can define tools using the `tool` helper and provide an `inputSchema` (Zod) and an `execute` function. The model will call your tool when appropriate, and you can handle tool calls and streaming output as follows:
160+
161+
```typescript
162+
import { appleAI } from "@meridius-labs/apple-on-device-ai";
163+
import { streamText, tool } from "ai";
164+
import { z } from "zod";
165+
166+
const result = streamText({
167+
model: appleAI(),
168+
messages: [{ role: "user", content: "What's the weather in Tokyo?" }],
169+
tools: {
170+
weather: tool({
171+
description: "Get weather information",
172+
inputSchema: z.object({ location: z.string() }),
173+
execute: async ({ location }) => ({
174+
temperature: 72,
175+
condition: "sunny",
176+
location,
177+
}),
178+
}),
179+
},
180+
});
181+
182+
for await (const delta of result.fullStream) {
183+
if (delta.type === "text") {
184+
process.stdout.write(delta.text);
185+
} else if (delta.type === "tool-call") {
186+
console.log(`\n🔧 Tool call: ${delta.toolName}`);
187+
console.log(` Arguments: ${JSON.stringify(delta.input)}`);
188+
} else if (delta.type === "tool-result") {
189+
console.log(`✅ Tool result: ${JSON.stringify(delta.output)}`);
190+
}
191+
}
192+
```
193+
194+
#### Structured/Object Generation Example
195+
196+
You can generate structured objects directly from the model using Zod schemas:
197+
198+
```typescript
199+
import { appleAI } from "@meridius-labs/apple-on-device-ai";
200+
import { generateObject } from "ai";
201+
import { z } from "zod";
202+
203+
const { object } = await generateObject({
204+
model: appleAI(),
205+
prompt: "Generate a user profile",
206+
schema: z.object({
207+
name: z.string(),
208+
age: z.number(),
209+
email: z.string().email(),
210+
}),
211+
});
212+
console.log(object); // { name: "Alice", age: 30, email: "alice@example.com" }
213+
```
214+
157215
## Requirements
158216

159217
- **macOS 26+** with Apple Intelligence enabled

0 commit comments

Comments
 (0)