sarvam-ai-sdk 0.0.4 → 0.0.6

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 CHANGED
@@ -69,9 +69,28 @@ const { text } = await transcribe({
69
69
  console.log(text); // പാചകം തുടരും സുഹൃത്തുക്കളെ
70
70
  ```
71
71
 
72
+ ## Translation
73
+
74
+ > NB: Only transliterates `prompt` and `role:user` messages, not `system` not `assistant`.
75
+
76
+ ```ts
77
+ import { sarvam } from "sarvam-ai-sdk";
78
+ import { generateText } from "ai";
79
+
80
+ const result = await generateText({
81
+ model: sarvam.translation({
82
+ "to": "en-IN",
83
+ "from": "ml-IN"
84
+ }),
85
+ prompt: "ഇതൊക്കെ ശ്രദ്ധിക്കണ്ടേ അംബാനെ?",
86
+ });
87
+
88
+ console.log(result.text); // Shouldn't we be careful about this, Ambane?
89
+ ```
90
+
72
91
  ## Transliterate
73
92
 
74
- > Only transliterates `prompt` and `role:user` messages, not `system` not `assistant`.
93
+ > NB: Only transliterates `prompt` and `role:user` messages, not `system` not `assistant`.
75
94
 
76
95
  ```ts
77
96
  import { sarvam } from "sarvam-ai-sdk";
@@ -88,6 +107,22 @@ const result = await generateText({
88
107
  console.log(result.text); // എടാ മോനെ, ഹാപ്പി അല്ലേ?
89
108
  ```
90
109
 
110
+ ## Language Identification
111
+
112
+ > NB: Only identifies `prompt` and `role:user` messages, not `system` not `assistant`.
113
+
114
+ ```ts
115
+ import { sarvam } from "sarvam-ai-sdk";
116
+ import { generateText } from "ai";
117
+
118
+ const result = await generateText({
119
+ model: sarvam.languageIdentification(),
120
+ prompt: "ബുദ്ധിയാണ് സാറേ ഇവൻ്റെ മെയിൻ",
121
+ });
122
+
123
+ console.log(result.text); // ml-IN
124
+ ```
125
+
91
126
  ## Tool Calling
92
127
 
93
128
  > [!WARNING]
@@ -101,7 +136,7 @@ import { sarvam } from "sarvam-ai-sdk";
101
136
 
102
137
  const result = await generateText({
103
138
  model: sarvam("sarvam-m", {
104
- simulateToolCalling: true, // ⚠️ important
139
+ simulate: "tool-calling" // ⚠️ important
105
140
  }),
106
141
  tools: {
107
142
  weather: tool({
@@ -121,6 +156,32 @@ const result = await generateText({
121
156
 
122
157
  console.log(result.toolResults);
123
158
  ```
159
+ ## Generate JSON object
160
+
161
+ > [!WARNING]
162
+ > Latest `sarvam-m` model isn't trained on native JSON object generation. So we simulate this with prompt engineering technique.
163
+
164
+ ```ts
165
+ import { z } from "zod";
166
+ import { sarvam } from "sarvam-ai-sdk";
167
+ import { generateObject } from 'ai';
168
+
169
+ const { object } = await generateObject({
170
+ model: sarvam("sarvam-m", {
171
+ simulate: "json-object" // ⚠️ important
172
+ }),
173
+ schema: z.object({
174
+ recipe: z.object({
175
+ name: z.string(),
176
+ ingredients: z.array(z.string()),
177
+ steps: z.array(z.string()),
178
+ }),
179
+ }),
180
+ prompt: 'Generate a South Indian recipe, in Malayalam',
181
+ });
182
+
183
+ console.log(object);
184
+ ```
124
185
 
125
186
  ## Documentation
126
187