sarvam-ai-sdk 0.0.1 → 0.0.3

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
@@ -5,18 +5,18 @@ contains language model support for the Sarvam chat completion, Text-to-Speech a
5
5
 
6
6
  ## Setup
7
7
 
8
- The **[Sarvam](http://sarvam.ai)** provider is available in the `@ai-sdk/sarvam` module. You can install it with
8
+ The **[Sarvam](http://sarvam.ai)** provider is available in the `sarvam-ai-sdk` module. You can install it with
9
9
 
10
10
  ```bash
11
- npm i @ai-sdk/sarvam
11
+ npm i sarvam-ai-sdk
12
12
  ```
13
13
 
14
14
  ## Provider Instance
15
15
 
16
- You can import the default provider instance `sarvam` from `@ai-sdk/sarvam`:
16
+ You can import the default provider instance `sarvam` from `sarvam-ai-sdk`:
17
17
 
18
18
  ```ts
19
- import { sarvam } from '@ai-sdk/sarvam';
19
+ import { sarvam } from 'sarvam-ai-sdk';
20
20
  ```
21
21
 
22
22
  Create `.env` file with API key from **[Sarvam Dashboard](https://dashboard.sarvam.ai/)**
@@ -27,7 +27,7 @@ SARVAM_API_KEY="your_api_key"
27
27
  ## Example
28
28
 
29
29
  ```ts
30
- import { sarvam } from '@ai-sdk/sarvam';
30
+ import { sarvam } from 'sarvam-ai-sdk';
31
31
  import { generateText } from 'ai';
32
32
 
33
33
  const { text } = await generateText({
@@ -41,7 +41,7 @@ console.log(text); // പാചകം തുടരൂ, സുഹൃത്തു
41
41
  ## Text-to-Speech
42
42
 
43
43
  ```ts
44
- import { sarvam } from "@ai-sdk/sarvam";
44
+ import { sarvam } from "sarvam-ai-sdk";
45
45
  import { experimental_generateSpeech as generateSpeech } from "ai";
46
46
  import { writeFile } from "fs/promises";
47
47
 
@@ -57,7 +57,7 @@ await writeFile("./src/transcript-test.wav", audioBuffer);
57
57
  ## Speech-to-Text
58
58
 
59
59
  ```ts
60
- import { sarvam } from "@ai-sdk/sarvam";
60
+ import { sarvam } from "sarvam-ai-sdk";
61
61
  import { experimental_transcribe as transcribe } from "ai";
62
62
  import { readFile } from "fs/promises";
63
63
 
@@ -69,6 +69,59 @@ const { text } = await transcribe({
69
69
  console.log(text); // പാചകം തുടരും സുഹൃത്തുക്കളെ
70
70
  ```
71
71
 
72
+ ## Transliterate
73
+
74
+ > 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.transliterate({
82
+ from: "en-IN"
83
+ to: "ml-IN",
84
+ }),
85
+ prompt: "eda mone, happy alle?",
86
+ });
87
+
88
+ console.log(result.text); // എടാ മോനെ, ഹാപ്പി അല്ലേ?
89
+ ```
90
+
91
+ ## Tool Calling
92
+
93
+ > [!WARNING]
94
+ > Latest `sarvam-m` model isn't trained on native tool calling feature (aka JSON mode). So we simulate this with prompt engineering technique.
95
+
96
+ ```ts
97
+ import { z } from "zod";
98
+ import { generateText, tool } from "ai";
99
+ import { sarvam } from "sarvam-ai-sdk";
100
+
101
+
102
+ const result = await generateText({
103
+ model: sarvam("sarvam-m", {
104
+ simulateToolCalling: true, // ⚠️ important
105
+ }),
106
+ tools: {
107
+ weather: tool({
108
+ description: "Get the weather in a location",
109
+ parameters: z.object({
110
+ location: z.string().describe("The location to get the weather for"),
111
+ }),
112
+ execute: async ({ location }) => ({
113
+ location,
114
+ temperature: 72 + Math.floor(Math.random() * 21) - 10,
115
+ }),
116
+ }),
117
+ },
118
+ system: "Your are a helpful AI",
119
+ prompt: "കൊച്ചിയിലെ കാലാവസ്ഥ എന്താണ്?",
120
+ });
121
+
122
+ console.log(result.toolResults);
123
+ ```
124
+
72
125
  ## Documentation
73
126
 
74
127
  Please check out the **[Sarvam provider documentation](https://ai-sdk.dev/providers/ai-sdk-providers/sarvam)** and **[Sarvam API documentation](https://docs.sarvam.ai)** for more information.