sarvam-ai-sdk 0.3.0-beta → 0.3.1
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 +51 -46
- package/dist/{index.mjs → index.cjs} +270 -325
- package/dist/{index.d.mts → index.d.cts} +84 -169
- package/dist/index.d.ts +84 -169
- package/dist/index.js +243 -352
- package/package.json +12 -9
package/README.md
CHANGED
|
@@ -18,6 +18,15 @@ npm i sarvam-ai-sdk ai@6
|
|
|
18
18
|
> [!WARNING]
|
|
19
19
|
> This package only works with Vercel AI-SDK v6, not v7. Make sure to install `ai@6` in your project.
|
|
20
20
|
|
|
21
|
+
### Version Compatibility
|
|
22
|
+
|
|
23
|
+
| Sarvam AI SDK Version | Vercel AI SDK Version |
|
|
24
|
+
|-----------------------|-----------------------|
|
|
25
|
+
| 0.4.x (beta) | 7.x.x (beta) |
|
|
26
|
+
| 0.3.x (current) | 6.x.x (current) |
|
|
27
|
+
| 0.2.x | 5.x.x |
|
|
28
|
+
| 0.1.x | 4.x.x |
|
|
29
|
+
|
|
21
30
|
## Provider Instance
|
|
22
31
|
|
|
23
32
|
You can import the default provider instance `sarvam` from `sarvam-ai-sdk`:
|
|
@@ -68,19 +77,6 @@ import { sarvam } from "sarvam-ai-sdk";
|
|
|
68
77
|
import { experimental_transcribe as transcribe } from "ai";
|
|
69
78
|
import { readFile } from "fs/promises";
|
|
70
79
|
|
|
71
|
-
const { text } = await transcribe({
|
|
72
|
-
model: sarvam.transcription("saarika:v2.5", "ml-IN"),
|
|
73
|
-
audio: await readFile("./src/transcript-test.wav"),
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
console.log(text); // പാചകം തുടരും സുഹൃത്തുക്കളെ
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
```ts
|
|
80
|
-
import { sarvam } from "sarvam-ai-sdk";
|
|
81
|
-
import { experimental_transcribe as transcribe } from "ai";
|
|
82
|
-
import { readFile } from "fs/promises";
|
|
83
|
-
|
|
84
80
|
const { text } = await transcribe({
|
|
85
81
|
model: sarvam.transcription("saaras:v3", "en-IN"),
|
|
86
82
|
audio: await readFile("./src/transcript-test.wav"),
|
|
@@ -89,24 +85,9 @@ const { text } = await transcribe({
|
|
|
89
85
|
console.log(text); // Pachakam thudaroo, suhruthukkale.
|
|
90
86
|
```
|
|
91
87
|
|
|
92
|
-
## Speech-to-Text-Translate
|
|
93
|
-
|
|
94
|
-
```ts
|
|
95
|
-
import { sarvam } from "sarvam-ai-sdk";
|
|
96
|
-
import { experimental_transcribe as transcribe } from "ai";
|
|
97
|
-
import { readFile } from "fs/promises";
|
|
98
|
-
|
|
99
|
-
const result = await transcribe({
|
|
100
|
-
model: sarvam.speechTranslation("saaras:v2.5"),
|
|
101
|
-
audio: await readFile("./src/transcript-test.wav"),
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
console.log(result.text); // Cooking continues, my friends
|
|
105
|
-
```
|
|
106
|
-
|
|
107
88
|
## Translation
|
|
108
89
|
|
|
109
|
-
> NB: Only
|
|
90
|
+
> NB: Only translates `prompt` and `role:user` messages, not `role:system` not `role:assistant`.
|
|
110
91
|
|
|
111
92
|
```ts
|
|
112
93
|
import { sarvam } from "sarvam-ai-sdk";
|
|
@@ -188,29 +169,56 @@ console.log(result.toolResults);
|
|
|
188
169
|
```
|
|
189
170
|
|
|
190
171
|
## Generate JSON object
|
|
172
|
+
> NB: `generateObject` is deprecated, use `generateText` with `Output` tool.
|
|
191
173
|
|
|
192
174
|
```ts
|
|
193
175
|
import { z } from "zod";
|
|
194
176
|
import { sarvam } from "sarvam-ai-sdk";
|
|
195
|
-
import { generateObject } from
|
|
177
|
+
import { generateObject } from "ai";
|
|
196
178
|
|
|
197
179
|
const { object } = await generateObject({
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
180
|
+
model: sarvam("sarvam-30b"),
|
|
181
|
+
schemaName: "Recipe",
|
|
182
|
+
schemaDescription: "A recipe with a name, ingredients and steps",
|
|
183
|
+
schema: z.object({
|
|
184
|
+
recipe: z.object({
|
|
185
|
+
name: z.string(),
|
|
186
|
+
ingredients: z.array(z.string()),
|
|
187
|
+
steps: z.array(z.string()),
|
|
188
|
+
}),
|
|
189
|
+
}),
|
|
190
|
+
prompt: "Generate a South Indian recipe, in Malayalam",
|
|
209
191
|
});
|
|
210
192
|
|
|
211
193
|
console.log(object);
|
|
212
194
|
```
|
|
213
195
|
|
|
196
|
+
## Generating Structured Outputs
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
import { z } from "zod";
|
|
200
|
+
import { sarvam } from "sarvam-ai-sdk";
|
|
201
|
+
import { generateText, Output } from "ai";
|
|
202
|
+
|
|
203
|
+
const { output } = await generateText({
|
|
204
|
+
model: sarvam("sarvam-105b"),
|
|
205
|
+
output: Output.object({
|
|
206
|
+
name: "Recipe",
|
|
207
|
+
description: "A recipe with a name, ingredients and steps",
|
|
208
|
+
schema: z.object({
|
|
209
|
+
recipe: z.object({
|
|
210
|
+
name: z.string(),
|
|
211
|
+
ingredients: z.array(z.string()),
|
|
212
|
+
steps: z.array(z.string()),
|
|
213
|
+
}),
|
|
214
|
+
}),
|
|
215
|
+
}),
|
|
216
|
+
prompt: "Generate a South Indian recipe, in Malayalam",
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
console.log(output);
|
|
220
|
+
```
|
|
221
|
+
|
|
214
222
|
## All APIs
|
|
215
223
|
|
|
216
224
|
```ts
|
|
@@ -232,11 +240,8 @@ sarvam.languageIdentification();
|
|
|
232
240
|
// Text-to-Speech
|
|
233
241
|
sarvam.speech("bulbul:v3", "ml-IN");
|
|
234
242
|
|
|
235
|
-
// Speech-to-Text
|
|
236
|
-
sarvam.transcription("
|
|
237
|
-
|
|
238
|
-
// Speech-to-Text + Translate to English
|
|
239
|
-
sarvam.speechTranslation("saaras:v3");
|
|
243
|
+
// Speech-to-Text
|
|
244
|
+
sarvam.transcription("saaras:v3");
|
|
240
245
|
```
|
|
241
246
|
|
|
242
247
|
|