paprflare-sdk 0.0.28 → 0.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +326 -326
- package/dist/index.d.mts +1 -13
- package/dist/index.d.ts +1 -13
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,327 +1,327 @@
|
|
|
1
|
-
# 🎯 Perfect API - Migration Guide
|
|
2
|
-
|
|
3
|
-
## What Changed?
|
|
4
|
-
|
|
5
|
-
We've completely reorganized the API to be **ultra-simple** with **automatic type inference**.
|
|
6
|
-
|
|
7
|
-
## Key Improvements
|
|
8
|
-
|
|
9
|
-
### 1. ✅ No More Type Casting
|
|
10
|
-
|
|
11
|
-
**Before:**
|
|
12
|
-
```typescript
|
|
13
|
-
const response = await client.chat(messages, { stream: true });
|
|
14
|
-
|
|
15
|
-
if (isStreamingResponse(response)) {
|
|
16
|
-
await (response as StreamingChatResponse).toConsole(); // ❌ Casting needed
|
|
17
|
-
}
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
**After:**
|
|
21
|
-
```typescript
|
|
22
|
-
const response = await client.chat({
|
|
23
|
-
messages,
|
|
24
|
-
stream: true,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
await response.toConsole(); // ✅ No casting needed!
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### 2. ✅ Unified API with Messages
|
|
31
|
-
|
|
32
|
-
**Before:**
|
|
33
|
-
```typescript
|
|
34
|
-
await client.chat(messages, config);
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
**After:**
|
|
38
|
-
```typescript
|
|
39
|
-
await client.chat({
|
|
40
|
-
messages,
|
|
41
|
-
...options,
|
|
42
|
-
});
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### 3. ✅ Mode-Specific Configuration
|
|
46
|
-
|
|
47
|
-
**Before:** All config options visible regardless of mode
|
|
48
|
-
|
|
49
|
-
**After:** Only relevant config for your mode
|
|
50
|
-
|
|
51
|
-
```typescript
|
|
52
|
-
// Cloud mode - only cloud options
|
|
53
|
-
new PaprFlare({
|
|
54
|
-
mode: 'cloud',
|
|
55
|
-
apiKey: 'pk_...',
|
|
56
|
-
region: 'in-mumbai',
|
|
57
|
-
// ❌ TypeScript prevents: provider, cache, database
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// Self-managed - only self-managed options
|
|
61
|
-
new PaprFlare({
|
|
62
|
-
mode: 'self-managed',
|
|
63
|
-
provider: createOpenAIProvider({ apiKey: '...' }),
|
|
64
|
-
cache: { type: 'memory' },
|
|
65
|
-
database: new MemoryAdapter(),
|
|
66
|
-
// ❌ TypeScript prevents: apiKey, region
|
|
67
|
-
});
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### 4. ✅ Built-in Database & Threads
|
|
71
|
-
|
|
72
|
-
**Before:** Separate initialization
|
|
73
|
-
|
|
74
|
-
**After:** Built into client
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
const client = new PaprFlare({
|
|
78
|
-
mode: 'self-managed',
|
|
79
|
-
provider: createOpenAIProvider({ apiKey: '...' }),
|
|
80
|
-
database: new MemoryAdapter(),
|
|
81
|
-
threads: { enabled: true },
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// Access directly
|
|
85
|
-
await client.database.startConversation('user-123');
|
|
86
|
-
await client.threads.createThread('user-123');
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
## Complete Migration
|
|
90
|
-
|
|
91
|
-
### Step 1: Update Imports
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
// Before
|
|
95
|
-
import { PaprFlareClient, isStreamingResponse } from '@paprflare/ai-sdk';
|
|
96
|
-
|
|
97
|
-
// After
|
|
98
|
-
import { PaprFlare } from '@paprflare/ai-sdk';
|
|
99
|
-
// isStreamingResponse no longer needed!
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### Step 2: Update Configuration
|
|
103
|
-
|
|
104
|
-
```typescript
|
|
105
|
-
// Before
|
|
106
|
-
const client = new PaprFlareClient({
|
|
107
|
-
mode: 'self-managed',
|
|
108
|
-
selfManaged: {
|
|
109
|
-
provider: createOpenAIProvider({ apiKey: '...' }),
|
|
110
|
-
cache: { type: 'memory' },
|
|
111
|
-
},
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
// After
|
|
115
|
-
const client = new PaprFlare({
|
|
116
|
-
mode: 'self-managed',
|
|
117
|
-
provider: createOpenAIProvider({ apiKey: '...' }),
|
|
118
|
-
cache: { type: 'memory' },
|
|
119
|
-
database: new MemoryAdapter(), // Optional
|
|
120
|
-
threads: { enabled: true }, // Optional
|
|
121
|
-
});
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### Step 3: Update Chat Calls
|
|
125
|
-
|
|
126
|
-
```typescript
|
|
127
|
-
// Before
|
|
128
|
-
const response = await client.chat(messages, {
|
|
129
|
-
stream: true,
|
|
130
|
-
temperature: 0.7,
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
// After
|
|
134
|
-
const response = await client.chat({
|
|
135
|
-
messages,
|
|
136
|
-
stream: true,
|
|
137
|
-
temperature: 0.7,
|
|
138
|
-
});
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
### Step 4: Remove Type Guards
|
|
142
|
-
|
|
143
|
-
```typescript
|
|
144
|
-
// Before
|
|
145
|
-
const response = await client.chat(messages, { stream: true });
|
|
146
|
-
if (isStreamingResponse(response)) {
|
|
147
|
-
await response.toConsole();
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// After
|
|
151
|
-
const response = await client.chat({
|
|
152
|
-
messages,
|
|
153
|
-
stream: true,
|
|
154
|
-
});
|
|
155
|
-
await response.toConsole(); // ✅ TypeScript knows it's streaming!
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
## New Features
|
|
159
|
-
|
|
160
|
-
### 1. Built-in Database
|
|
161
|
-
|
|
162
|
-
```typescript
|
|
163
|
-
const client = new PaprFlare({
|
|
164
|
-
mode: 'self-managed',
|
|
165
|
-
provider: createOpenAIProvider({ apiKey: '...' }),
|
|
166
|
-
database: new MemoryAdapter(), // or PrismaAdapter, DrizzleAdapter
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
// Start conversation
|
|
170
|
-
const convId = await client.database!.startConversation('user-123');
|
|
171
|
-
|
|
172
|
-
// Auto-save messages
|
|
173
|
-
const response = await client.chat({
|
|
174
|
-
messages: [{ role: 'user', content: 'Hello' }],
|
|
175
|
-
stream: true,
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
await response.process({
|
|
179
|
-
onComplete: (msg) => client.database!.addMessage(convId, msg),
|
|
180
|
-
});
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
### 2. Built-in Thread Management
|
|
184
|
-
|
|
185
|
-
```typescript
|
|
186
|
-
const client = new PaprFlare({
|
|
187
|
-
mode: 'self-managed',
|
|
188
|
-
provider: createOpenAIProvider({ apiKey: '...' }),
|
|
189
|
-
threads: { enabled: true },
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
// Create thread
|
|
193
|
-
const threadId = await client.threads.createThread('user-123');
|
|
194
|
-
|
|
195
|
-
// Send message (context managed automatically)
|
|
196
|
-
const stream = await client.threads.sendMessage(threadId, 'Hello!');
|
|
197
|
-
await stream.toConsole();
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
### 3. One-Liner API Routes
|
|
201
|
-
|
|
202
|
-
```typescript
|
|
203
|
-
// Next.js App Router
|
|
204
|
-
export async function POST(req: Request) {
|
|
205
|
-
const { messages } = await req.json();
|
|
206
|
-
|
|
207
|
-
return (await client.chat({
|
|
208
|
-
messages,
|
|
209
|
-
stream: true,
|
|
210
|
-
})).toResponse(); // ✅ ONE LINE!
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Express
|
|
214
|
-
app.post('/chat', async (req, res) => {
|
|
215
|
-
return (await client.chat({
|
|
216
|
-
messages: req.body.messages,
|
|
217
|
-
stream: true,
|
|
218
|
-
})).toResponse(res);
|
|
219
|
-
});
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
## Complete Examples
|
|
223
|
-
|
|
224
|
-
### Streaming
|
|
225
|
-
|
|
226
|
-
```typescript
|
|
227
|
-
const response = await client.chat({
|
|
228
|
-
messages: [{ role: 'user', content: 'Hello' }],
|
|
229
|
-
stream: true,
|
|
230
|
-
temperature: 0.7,
|
|
231
|
-
maxTokens: 2000,
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
// Choose your method:
|
|
235
|
-
await response.toConsole(); // Console
|
|
236
|
-
await response.toResponse(); // HTTP Response
|
|
237
|
-
const text = await response.toText(); // Full text
|
|
238
|
-
await response.process({ onText: (d) => console.log(d) }); // Callbacks
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
### Non-Streaming
|
|
242
|
-
|
|
243
|
-
```typescript
|
|
244
|
-
const response = await client.chat({
|
|
245
|
-
messages: [{ role: 'user', content: 'Hello' }],
|
|
246
|
-
temperature: 0.7,
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
console.log(response.message.content);
|
|
250
|
-
console.log(response.usage?.totalTokens);
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
### With Database
|
|
254
|
-
|
|
255
|
-
```typescript
|
|
256
|
-
const client = new PaprFlare({
|
|
257
|
-
mode: 'self-managed',
|
|
258
|
-
provider: createOpenAIProvider({ apiKey: '...' }),
|
|
259
|
-
database: new MemoryAdapter(),
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
const convId = await client.database!.startConversation('user-123');
|
|
263
|
-
|
|
264
|
-
const response = await client.chat({
|
|
265
|
-
messages: [{ role: 'user', content: 'Hello' }],
|
|
266
|
-
stream: true,
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
await response.process({
|
|
270
|
-
onText: (delta) => process.stdout.write(delta),
|
|
271
|
-
onComplete: (msg) => client.database!.addMessage(convId, msg),
|
|
272
|
-
});
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
### With Threads
|
|
276
|
-
|
|
277
|
-
```typescript
|
|
278
|
-
const client = new PaprFlare({
|
|
279
|
-
mode: 'self-managed',
|
|
280
|
-
provider: createOpenAIProvider({ apiKey: '...' }),
|
|
281
|
-
threads: { enabled: true },
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
const threadId = await client.threads.createThread('user-123');
|
|
285
|
-
|
|
286
|
-
const stream = await client.threads.sendMessage(
|
|
287
|
-
threadId,
|
|
288
|
-
'Explain quantum computing'
|
|
289
|
-
);
|
|
290
|
-
|
|
291
|
-
await stream.toConsole();
|
|
292
|
-
|
|
293
|
-
// Follow-up (context maintained)
|
|
294
|
-
const stream2 = await client.threads.sendMessage(
|
|
295
|
-
threadId,
|
|
296
|
-
'Explain that in simpler terms'
|
|
297
|
-
);
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
## Benefits Summary
|
|
301
|
-
|
|
302
|
-
| Feature | Before | After |
|
|
303
|
-
|---------|--------|-------|
|
|
304
|
-
| Type inference | Manual casting | Automatic ✅ |
|
|
305
|
-
| API calls | 2 parameters | 1 unified object ✅ |
|
|
306
|
-
| Type guards | Required | Not needed ✅ |
|
|
307
|
-
| Config types | All options visible | Mode-specific ✅ |
|
|
308
|
-
| Database | Separate init | Built-in ✅ |
|
|
309
|
-
| Threads | Separate init | Built-in ✅ |
|
|
310
|
-
| Code reduction | Baseline | 50% less ✅ |
|
|
311
|
-
|
|
312
|
-
## Breaking Changes
|
|
313
|
-
|
|
314
|
-
1. **Import name:** `PaprFlareClient` → `PaprFlare`
|
|
315
|
-
2. **Config structure:** `selfManaged: {}` → top-level options
|
|
316
|
-
3. **Chat signature:** `chat(messages, config)` → `chat({ messages, ...config })`
|
|
317
|
-
4. **Type guards:** `isStreamingResponse()` no longer needed
|
|
318
|
-
|
|
319
|
-
## Backwards Compatibility
|
|
320
|
-
|
|
321
|
-
The old API still works but is deprecated. Update when convenient.
|
|
322
|
-
|
|
323
|
-
---
|
|
324
|
-
|
|
325
|
-
**You're now using the simplest AI SDK API possible! 🚀**
|
|
326
|
-
|
|
1
|
+
# 🎯 Perfect API - Migration Guide
|
|
2
|
+
|
|
3
|
+
## What Changed?
|
|
4
|
+
|
|
5
|
+
We've completely reorganized the API to be **ultra-simple** with **automatic type inference**.
|
|
6
|
+
|
|
7
|
+
## Key Improvements
|
|
8
|
+
|
|
9
|
+
### 1. ✅ No More Type Casting
|
|
10
|
+
|
|
11
|
+
**Before:**
|
|
12
|
+
```typescript
|
|
13
|
+
const response = await client.chat(messages, { stream: true });
|
|
14
|
+
|
|
15
|
+
if (isStreamingResponse(response)) {
|
|
16
|
+
await (response as StreamingChatResponse).toConsole(); // ❌ Casting needed
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**After:**
|
|
21
|
+
```typescript
|
|
22
|
+
const response = await client.chat({
|
|
23
|
+
messages,
|
|
24
|
+
stream: true,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
await response.toConsole(); // ✅ No casting needed!
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 2. ✅ Unified API with Messages
|
|
31
|
+
|
|
32
|
+
**Before:**
|
|
33
|
+
```typescript
|
|
34
|
+
await client.chat(messages, config);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**After:**
|
|
38
|
+
```typescript
|
|
39
|
+
await client.chat({
|
|
40
|
+
messages,
|
|
41
|
+
...options,
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 3. ✅ Mode-Specific Configuration
|
|
46
|
+
|
|
47
|
+
**Before:** All config options visible regardless of mode
|
|
48
|
+
|
|
49
|
+
**After:** Only relevant config for your mode
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
// Cloud mode - only cloud options
|
|
53
|
+
new PaprFlare({
|
|
54
|
+
mode: 'cloud',
|
|
55
|
+
apiKey: 'pk_...',
|
|
56
|
+
region: 'in-mumbai',
|
|
57
|
+
// ❌ TypeScript prevents: provider, cache, database
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Self-managed - only self-managed options
|
|
61
|
+
new PaprFlare({
|
|
62
|
+
mode: 'self-managed',
|
|
63
|
+
provider: createOpenAIProvider({ apiKey: '...' }),
|
|
64
|
+
cache: { type: 'memory' },
|
|
65
|
+
database: new MemoryAdapter(),
|
|
66
|
+
// ❌ TypeScript prevents: apiKey, region
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### 4. ✅ Built-in Database & Threads
|
|
71
|
+
|
|
72
|
+
**Before:** Separate initialization
|
|
73
|
+
|
|
74
|
+
**After:** Built into client
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
const client = new PaprFlare({
|
|
78
|
+
mode: 'self-managed',
|
|
79
|
+
provider: createOpenAIProvider({ apiKey: '...' }),
|
|
80
|
+
database: new MemoryAdapter(),
|
|
81
|
+
threads: { enabled: true },
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Access directly
|
|
85
|
+
await client.database.startConversation('user-123');
|
|
86
|
+
await client.threads.createThread('user-123');
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Complete Migration
|
|
90
|
+
|
|
91
|
+
### Step 1: Update Imports
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
// Before
|
|
95
|
+
import { PaprFlareClient, isStreamingResponse } from '@paprflare/ai-sdk';
|
|
96
|
+
|
|
97
|
+
// After
|
|
98
|
+
import { PaprFlare } from '@paprflare/ai-sdk';
|
|
99
|
+
// isStreamingResponse no longer needed!
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Step 2: Update Configuration
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
// Before
|
|
106
|
+
const client = new PaprFlareClient({
|
|
107
|
+
mode: 'self-managed',
|
|
108
|
+
selfManaged: {
|
|
109
|
+
provider: createOpenAIProvider({ apiKey: '...' }),
|
|
110
|
+
cache: { type: 'memory' },
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// After
|
|
115
|
+
const client = new PaprFlare({
|
|
116
|
+
mode: 'self-managed',
|
|
117
|
+
provider: createOpenAIProvider({ apiKey: '...' }),
|
|
118
|
+
cache: { type: 'memory' },
|
|
119
|
+
database: new MemoryAdapter(), // Optional
|
|
120
|
+
threads: { enabled: true }, // Optional
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Step 3: Update Chat Calls
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
// Before
|
|
128
|
+
const response = await client.chat(messages, {
|
|
129
|
+
stream: true,
|
|
130
|
+
temperature: 0.7,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// After
|
|
134
|
+
const response = await client.chat({
|
|
135
|
+
messages,
|
|
136
|
+
stream: true,
|
|
137
|
+
temperature: 0.7,
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Step 4: Remove Type Guards
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
// Before
|
|
145
|
+
const response = await client.chat(messages, { stream: true });
|
|
146
|
+
if (isStreamingResponse(response)) {
|
|
147
|
+
await response.toConsole();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// After
|
|
151
|
+
const response = await client.chat({
|
|
152
|
+
messages,
|
|
153
|
+
stream: true,
|
|
154
|
+
});
|
|
155
|
+
await response.toConsole(); // ✅ TypeScript knows it's streaming!
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## New Features
|
|
159
|
+
|
|
160
|
+
### 1. Built-in Database
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
const client = new PaprFlare({
|
|
164
|
+
mode: 'self-managed',
|
|
165
|
+
provider: createOpenAIProvider({ apiKey: '...' }),
|
|
166
|
+
database: new MemoryAdapter(), // or PrismaAdapter, DrizzleAdapter
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Start conversation
|
|
170
|
+
const convId = await client.database!.startConversation('user-123');
|
|
171
|
+
|
|
172
|
+
// Auto-save messages
|
|
173
|
+
const response = await client.chat({
|
|
174
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
175
|
+
stream: true,
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
await response.process({
|
|
179
|
+
onComplete: (msg) => client.database!.addMessage(convId, msg),
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### 2. Built-in Thread Management
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
const client = new PaprFlare({
|
|
187
|
+
mode: 'self-managed',
|
|
188
|
+
provider: createOpenAIProvider({ apiKey: '...' }),
|
|
189
|
+
threads: { enabled: true },
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// Create thread
|
|
193
|
+
const threadId = await client.threads.createThread('user-123');
|
|
194
|
+
|
|
195
|
+
// Send message (context managed automatically)
|
|
196
|
+
const stream = await client.threads.sendMessage(threadId, 'Hello!');
|
|
197
|
+
await stream.toConsole();
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### 3. One-Liner API Routes
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
// Next.js App Router
|
|
204
|
+
export async function POST(req: Request) {
|
|
205
|
+
const { messages } = await req.json();
|
|
206
|
+
|
|
207
|
+
return (await client.chat({
|
|
208
|
+
messages,
|
|
209
|
+
stream: true,
|
|
210
|
+
})).toResponse(); // ✅ ONE LINE!
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Express
|
|
214
|
+
app.post('/chat', async (req, res) => {
|
|
215
|
+
return (await client.chat({
|
|
216
|
+
messages: req.body.messages,
|
|
217
|
+
stream: true,
|
|
218
|
+
})).toResponse(res);
|
|
219
|
+
});
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Complete Examples
|
|
223
|
+
|
|
224
|
+
### Streaming
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
const response = await client.chat({
|
|
228
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
229
|
+
stream: true,
|
|
230
|
+
temperature: 0.7,
|
|
231
|
+
maxTokens: 2000,
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// Choose your method:
|
|
235
|
+
await response.toConsole(); // Console
|
|
236
|
+
await response.toResponse(); // HTTP Response
|
|
237
|
+
const text = await response.toText(); // Full text
|
|
238
|
+
await response.process({ onText: (d) => console.log(d) }); // Callbacks
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Non-Streaming
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
const response = await client.chat({
|
|
245
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
246
|
+
temperature: 0.7,
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
console.log(response.message.content);
|
|
250
|
+
console.log(response.usage?.totalTokens);
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### With Database
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
const client = new PaprFlare({
|
|
257
|
+
mode: 'self-managed',
|
|
258
|
+
provider: createOpenAIProvider({ apiKey: '...' }),
|
|
259
|
+
database: new MemoryAdapter(),
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
const convId = await client.database!.startConversation('user-123');
|
|
263
|
+
|
|
264
|
+
const response = await client.chat({
|
|
265
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
266
|
+
stream: true,
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
await response.process({
|
|
270
|
+
onText: (delta) => process.stdout.write(delta),
|
|
271
|
+
onComplete: (msg) => client.database!.addMessage(convId, msg),
|
|
272
|
+
});
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### With Threads
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
const client = new PaprFlare({
|
|
279
|
+
mode: 'self-managed',
|
|
280
|
+
provider: createOpenAIProvider({ apiKey: '...' }),
|
|
281
|
+
threads: { enabled: true },
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
const threadId = await client.threads.createThread('user-123');
|
|
285
|
+
|
|
286
|
+
const stream = await client.threads.sendMessage(
|
|
287
|
+
threadId,
|
|
288
|
+
'Explain quantum computing'
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
await stream.toConsole();
|
|
292
|
+
|
|
293
|
+
// Follow-up (context maintained)
|
|
294
|
+
const stream2 = await client.threads.sendMessage(
|
|
295
|
+
threadId,
|
|
296
|
+
'Explain that in simpler terms'
|
|
297
|
+
);
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## Benefits Summary
|
|
301
|
+
|
|
302
|
+
| Feature | Before | After |
|
|
303
|
+
|---------|--------|-------|
|
|
304
|
+
| Type inference | Manual casting | Automatic ✅ |
|
|
305
|
+
| API calls | 2 parameters | 1 unified object ✅ |
|
|
306
|
+
| Type guards | Required | Not needed ✅ |
|
|
307
|
+
| Config types | All options visible | Mode-specific ✅ |
|
|
308
|
+
| Database | Separate init | Built-in ✅ |
|
|
309
|
+
| Threads | Separate init | Built-in ✅ |
|
|
310
|
+
| Code reduction | Baseline | 50% less ✅ |
|
|
311
|
+
|
|
312
|
+
## Breaking Changes
|
|
313
|
+
|
|
314
|
+
1. **Import name:** `PaprFlareClient` → `PaprFlare`
|
|
315
|
+
2. **Config structure:** `selfManaged: {}` → top-level options
|
|
316
|
+
3. **Chat signature:** `chat(messages, config)` → `chat({ messages, ...config })`
|
|
317
|
+
4. **Type guards:** `isStreamingResponse()` no longer needed
|
|
318
|
+
|
|
319
|
+
## Backwards Compatibility
|
|
320
|
+
|
|
321
|
+
The old API still works but is deprecated. Update when convenient.
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
**You're now using the simplest AI SDK API possible! 🚀**
|
|
326
|
+
|
|
327
327
|
Made with ❤️ in India 🇮🇳
|
package/dist/index.d.mts
CHANGED
|
@@ -1138,21 +1138,9 @@ declare class SarvamProvider {
|
|
|
1138
1138
|
private parseStream;
|
|
1139
1139
|
/**
|
|
1140
1140
|
* Format messages for Sarvam AI API
|
|
1141
|
-
*
|
|
1141
|
+
* Note: Tool calls are not supported by Sarvam AI
|
|
1142
1142
|
*/
|
|
1143
1143
|
private formatMessages;
|
|
1144
|
-
/**
|
|
1145
|
-
* Format tools for Sarvam AI API (OpenAI-compatible format)
|
|
1146
|
-
*/
|
|
1147
|
-
private formatTools;
|
|
1148
|
-
/**
|
|
1149
|
-
* Format tool choice for Sarvam AI API
|
|
1150
|
-
*/
|
|
1151
|
-
private formatToolChoice;
|
|
1152
|
-
/**
|
|
1153
|
-
* Convert Zod schema to JSON Schema
|
|
1154
|
-
*/
|
|
1155
|
-
private zodToJsonSchema;
|
|
1156
1144
|
}
|
|
1157
1145
|
/**
|
|
1158
1146
|
* Create Sarvam provider instance
|