sarvamai 1.1.4 → 1.1.5-alpha.2
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/dist/cjs/BaseClient.js +2 -2
- package/dist/cjs/api/resources/chat/client/Client.d.ts +43 -8
- package/dist/cjs/api/resources/chat/client/Client.js +151 -40
- package/dist/cjs/api/resources/chat/client/requests/ChatCompletionsRequest.d.ts +12 -4
- package/dist/cjs/api/types/ChatCompletionChunk.d.ts +15 -0
- package/dist/cjs/api/types/ChatCompletionChunk.js +2 -0
- package/dist/cjs/api/types/ChatCompletionMessageToolCall.d.ts +8 -0
- package/dist/cjs/api/types/ChatCompletionMessageToolCall.js +3 -0
- package/dist/cjs/api/types/ChatCompletionNamedToolChoice.d.ts +6 -0
- package/dist/cjs/api/types/ChatCompletionNamedToolChoice.js +3 -0
- package/dist/cjs/api/types/ChatCompletionNamedToolChoiceFunction.d.ts +4 -0
- package/dist/cjs/api/types/ChatCompletionNamedToolChoiceFunction.js +3 -0
- package/dist/cjs/api/types/ChatCompletionRequestAssistantMessage.d.ts +4 -1
- package/dist/cjs/api/types/ChatCompletionRequestMessage.d.ts +4 -1
- package/dist/cjs/api/types/ChatCompletionRequestToolMessage.d.ts +6 -0
- package/dist/cjs/api/types/ChatCompletionRequestToolMessage.js +3 -0
- package/dist/cjs/api/types/ChatCompletionResponseMessage.d.ts +6 -1
- package/dist/cjs/api/types/ChatCompletionTool.d.ts +6 -0
- package/dist/cjs/api/types/ChatCompletionTool.js +3 -0
- package/dist/cjs/api/types/Choice.d.ts +1 -0
- package/dist/cjs/api/types/ChoiceDelta.d.ts +9 -0
- package/dist/cjs/api/types/ChoiceDelta.js +2 -0
- package/dist/cjs/api/types/ChoiceDeltaToolCall.d.ts +10 -0
- package/dist/cjs/api/types/ChoiceDeltaToolCall.js +2 -0
- package/dist/cjs/api/types/ChunkChoice.d.ts +7 -0
- package/dist/cjs/api/types/ChunkChoice.js +2 -0
- package/dist/cjs/api/types/CompletionUsage.d.ts +2 -0
- package/dist/cjs/api/types/CreateChatCompletionResponse.d.ts +2 -0
- package/dist/cjs/api/types/FunctionCall.d.ts +6 -0
- package/dist/cjs/api/types/FunctionCall.js +3 -0
- package/dist/cjs/api/types/FunctionDefinition.d.ts +8 -0
- package/dist/cjs/api/types/FunctionDefinition.js +3 -0
- package/dist/cjs/api/types/SarvamModelIds.d.ts +8 -1
- package/dist/cjs/api/types/SarvamModelIds.js +8 -0
- package/dist/cjs/api/types/ToolChoiceOption.d.ts +2 -0
- package/dist/cjs/api/types/ToolChoiceOption.js +3 -0
- package/dist/cjs/api/types/index.d.ts +8 -0
- package/dist/cjs/api/types/index.js +8 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.mjs +2 -2
- package/dist/esm/api/resources/chat/client/Client.d.mts +43 -8
- package/dist/esm/api/resources/chat/client/Client.mjs +151 -40
- package/dist/esm/api/resources/chat/client/requests/ChatCompletionsRequest.d.mts +12 -4
- package/dist/esm/api/types/ChatCompletionChunk.d.mts +15 -0
- package/dist/esm/api/types/ChatCompletionChunk.mjs +1 -0
- package/dist/esm/api/types/ChatCompletionMessageToolCall.d.mts +8 -0
- package/dist/esm/api/types/ChatCompletionMessageToolCall.mjs +2 -0
- package/dist/esm/api/types/ChatCompletionNamedToolChoice.d.mts +6 -0
- package/dist/esm/api/types/ChatCompletionNamedToolChoice.mjs +2 -0
- package/dist/esm/api/types/ChatCompletionNamedToolChoiceFunction.d.mts +4 -0
- package/dist/esm/api/types/ChatCompletionNamedToolChoiceFunction.mjs +2 -0
- package/dist/esm/api/types/ChatCompletionRequestAssistantMessage.d.mts +4 -1
- package/dist/esm/api/types/ChatCompletionRequestMessage.d.mts +4 -1
- package/dist/esm/api/types/ChatCompletionRequestToolMessage.d.mts +6 -0
- package/dist/esm/api/types/ChatCompletionRequestToolMessage.mjs +2 -0
- package/dist/esm/api/types/ChatCompletionResponseMessage.d.mts +6 -1
- package/dist/esm/api/types/ChatCompletionTool.d.mts +6 -0
- package/dist/esm/api/types/ChatCompletionTool.mjs +2 -0
- package/dist/esm/api/types/Choice.d.mts +1 -0
- package/dist/esm/api/types/ChoiceDelta.d.mts +9 -0
- package/dist/esm/api/types/ChoiceDelta.mjs +1 -0
- package/dist/esm/api/types/ChoiceDeltaToolCall.d.mts +10 -0
- package/dist/esm/api/types/ChoiceDeltaToolCall.mjs +1 -0
- package/dist/esm/api/types/ChunkChoice.d.mts +7 -0
- package/dist/esm/api/types/ChunkChoice.mjs +1 -0
- package/dist/esm/api/types/CompletionUsage.d.mts +2 -0
- package/dist/esm/api/types/CreateChatCompletionResponse.d.mts +2 -0
- package/dist/esm/api/types/FunctionCall.d.mts +6 -0
- package/dist/esm/api/types/FunctionCall.mjs +2 -0
- package/dist/esm/api/types/FunctionDefinition.d.mts +8 -0
- package/dist/esm/api/types/FunctionDefinition.mjs +2 -0
- package/dist/esm/api/types/SarvamModelIds.d.mts +8 -1
- package/dist/esm/api/types/SarvamModelIds.mjs +7 -1
- package/dist/esm/api/types/ToolChoiceOption.d.mts +2 -0
- package/dist/esm/api/types/ToolChoiceOption.mjs +2 -0
- package/dist/esm/api/types/index.d.mts +8 -0
- package/dist/esm/api/types/index.mjs +8 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +1 -1
- package/reference.md +3 -17
package/dist/cjs/BaseClient.js
CHANGED
|
@@ -43,8 +43,8 @@ function normalizeClientOptions(options) {
|
|
|
43
43
|
const headers = (0, headers_js_1.mergeHeaders)({
|
|
44
44
|
"X-Fern-Language": "JavaScript",
|
|
45
45
|
"X-Fern-SDK-Name": "sarvamai",
|
|
46
|
-
"X-Fern-SDK-Version": "1.1.
|
|
47
|
-
"User-Agent": "sarvamai/1.1.
|
|
46
|
+
"X-Fern-SDK-Version": "1.1.5-alpha.2",
|
|
47
|
+
"User-Agent": "sarvamai/1.1.5-alpha.2",
|
|
48
48
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
49
49
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
50
50
|
}, options === null || options === void 0 ? void 0 : options.headers);
|
|
@@ -2,6 +2,7 @@ import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClie
|
|
|
2
2
|
import { type NormalizedClientOptionsWithAuth } from "../../../../BaseClient.js";
|
|
3
3
|
import * as core from "../../../../core/index.js";
|
|
4
4
|
import * as SarvamAI from "../../../index.js";
|
|
5
|
+
import type { ChatCompletionChunk } from "../../../types/ChatCompletionChunk.js";
|
|
5
6
|
export declare namespace ChatClient {
|
|
6
7
|
interface Options extends BaseClientOptions {
|
|
7
8
|
}
|
|
@@ -12,7 +13,7 @@ export declare class ChatClient {
|
|
|
12
13
|
protected readonly _options: NormalizedClientOptionsWithAuth<ChatClient.Options>;
|
|
13
14
|
constructor(options?: ChatClient.Options);
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
+
* Create a chat completion. Supports both streaming and non-streaming modes.
|
|
16
17
|
*
|
|
17
18
|
* @param {SarvamAI.ChatCompletionsRequest} request
|
|
18
19
|
* @param {ChatClient.RequestOptions} requestOptions - Request-specific configuration.
|
|
@@ -24,13 +25,47 @@ export declare class ChatClient {
|
|
|
24
25
|
* @throws {@link SarvamAI.InternalServerError}
|
|
25
26
|
*
|
|
26
27
|
* @example
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
28
|
+
* // Non-streaming
|
|
29
|
+
* const response = await client.chat.completions({
|
|
30
|
+
* messages: [{ role: "user", content: "Hello" }],
|
|
31
|
+
* model: "sarvam-m"
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // Streaming
|
|
36
|
+
* const stream = await client.chat.completions({
|
|
37
|
+
* messages: [{ role: "user", content: "Hello" }],
|
|
38
|
+
* model: "sarvam-m",
|
|
39
|
+
* stream: true
|
|
40
|
+
* });
|
|
41
|
+
* for await (const chunk of stream) {
|
|
42
|
+
* process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* // Tool calling
|
|
47
|
+
* const response = await client.chat.completions({
|
|
48
|
+
* messages: [{ role: "user", content: "What is the weather?" }],
|
|
49
|
+
* model: "sarvam-m",
|
|
50
|
+
* tools: [{
|
|
51
|
+
* type: "function",
|
|
52
|
+
* function: {
|
|
53
|
+
* name: "get_weather",
|
|
54
|
+
* description: "Get the weather",
|
|
55
|
+
* parameters: { type: "object", properties: { location: { type: "string" } } }
|
|
56
|
+
* }
|
|
57
|
+
* }]
|
|
58
|
+
* });
|
|
33
59
|
*/
|
|
34
|
-
completions(request: SarvamAI.ChatCompletionsRequest
|
|
60
|
+
completions(request: SarvamAI.ChatCompletionsRequest & {
|
|
61
|
+
stream: true;
|
|
62
|
+
}, requestOptions?: ChatClient.RequestOptions): Promise<AsyncIterable<ChatCompletionChunk>>;
|
|
63
|
+
completions(request: SarvamAI.ChatCompletionsRequest & {
|
|
64
|
+
stream?: false | undefined;
|
|
65
|
+
}, requestOptions?: ChatClient.RequestOptions): core.HttpResponsePromise<SarvamAI.CreateChatCompletionResponse>;
|
|
66
|
+
completions(request: SarvamAI.ChatCompletionsRequest, requestOptions?: ChatClient.RequestOptions): core.HttpResponsePromise<SarvamAI.CreateChatCompletionResponse> | Promise<AsyncIterable<ChatCompletionChunk>>;
|
|
35
67
|
private __completions;
|
|
68
|
+
private __completionsStream;
|
|
69
|
+
private _parseSSEStream;
|
|
70
|
+
private _throwStatusCodeError;
|
|
36
71
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// This file was auto-generated by Fern from our API Definition.
|
|
3
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
3
|
if (k2 === undefined) k2 = k;
|
|
5
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -42,10 +41,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
42
41
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
42
|
});
|
|
44
43
|
};
|
|
44
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
45
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
46
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
47
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
48
|
+
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
49
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
50
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
51
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
52
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
53
|
+
function fulfill(value) { resume("next", value); }
|
|
54
|
+
function reject(value) { resume("throw", value); }
|
|
55
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
56
|
+
};
|
|
45
57
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
58
|
exports.ChatClient = void 0;
|
|
47
59
|
const BaseClient_js_1 = require("../../../../BaseClient.js");
|
|
48
60
|
const headers_js_1 = require("../../../../core/headers.js");
|
|
61
|
+
const RawResponse_js_1 = require("../../../../core/fetcher/RawResponse.js");
|
|
49
62
|
const core = __importStar(require("../../../../core/index.js"));
|
|
50
63
|
const environments = __importStar(require("../../../../environments.js"));
|
|
51
64
|
const errors = __importStar(require("../../../../errors/index.js"));
|
|
@@ -54,27 +67,10 @@ class ChatClient {
|
|
|
54
67
|
constructor(options = {}) {
|
|
55
68
|
this._options = (0, BaseClient_js_1.normalizeClientOptionsWithAuth)(options);
|
|
56
69
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Calls Sarvam LLM API to get the chat completion. Supported model(s): `sarvam-m`.
|
|
59
|
-
*
|
|
60
|
-
* @param {SarvamAI.ChatCompletionsRequest} request
|
|
61
|
-
* @param {ChatClient.RequestOptions} requestOptions - Request-specific configuration.
|
|
62
|
-
*
|
|
63
|
-
* @throws {@link SarvamAI.BadRequestError}
|
|
64
|
-
* @throws {@link SarvamAI.ForbiddenError}
|
|
65
|
-
* @throws {@link SarvamAI.UnprocessableEntityError}
|
|
66
|
-
* @throws {@link SarvamAI.TooManyRequestsError}
|
|
67
|
-
* @throws {@link SarvamAI.InternalServerError}
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* await client.chat.completions({
|
|
71
|
-
* messages: [{
|
|
72
|
-
* role: "assistant",
|
|
73
|
-
* content: "content"
|
|
74
|
-
* }]
|
|
75
|
-
* })
|
|
76
|
-
*/
|
|
77
70
|
completions(request, requestOptions) {
|
|
71
|
+
if (request.stream === true) {
|
|
72
|
+
return this.__completionsStream(request, requestOptions);
|
|
73
|
+
}
|
|
78
74
|
return core.HttpResponsePromise.fromPromise(this.__completions(request, requestOptions));
|
|
79
75
|
}
|
|
80
76
|
__completions(request, requestOptions) {
|
|
@@ -89,7 +85,7 @@ class ChatClient {
|
|
|
89
85
|
contentType: "application/json",
|
|
90
86
|
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
|
|
91
87
|
requestType: "json",
|
|
92
|
-
body:
|
|
88
|
+
body: request,
|
|
93
89
|
timeoutMs: ((_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.timeoutInSeconds) !== null && _f !== void 0 ? _f : 60) * 1000,
|
|
94
90
|
maxRetries: (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.maxRetries,
|
|
95
91
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
@@ -103,24 +99,7 @@ class ChatClient {
|
|
|
103
99
|
};
|
|
104
100
|
}
|
|
105
101
|
if (_response.error.reason === "status-code") {
|
|
106
|
-
|
|
107
|
-
case 400:
|
|
108
|
-
throw new SarvamAI.BadRequestError(_response.error.body, _response.rawResponse);
|
|
109
|
-
case 403:
|
|
110
|
-
throw new SarvamAI.ForbiddenError(_response.error.body, _response.rawResponse);
|
|
111
|
-
case 422:
|
|
112
|
-
throw new SarvamAI.UnprocessableEntityError(_response.error.body, _response.rawResponse);
|
|
113
|
-
case 429:
|
|
114
|
-
throw new SarvamAI.TooManyRequestsError(_response.error.body, _response.rawResponse);
|
|
115
|
-
case 500:
|
|
116
|
-
throw new SarvamAI.InternalServerError(_response.error.body, _response.rawResponse);
|
|
117
|
-
default:
|
|
118
|
-
throw new errors.SarvamAIError({
|
|
119
|
-
statusCode: _response.error.statusCode,
|
|
120
|
-
body: _response.error.body,
|
|
121
|
-
rawResponse: _response.rawResponse,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
102
|
+
this._throwStatusCodeError(_response.error.statusCode, _response.error.body, _response.rawResponse);
|
|
124
103
|
}
|
|
125
104
|
switch (_response.error.reason) {
|
|
126
105
|
case "non-json":
|
|
@@ -144,5 +123,137 @@ class ChatClient {
|
|
|
144
123
|
}
|
|
145
124
|
});
|
|
146
125
|
}
|
|
126
|
+
__completionsStream(request, requestOptions) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
var _a, _b, _c, _d, _e;
|
|
129
|
+
const _authRequest = yield this._options.authProvider.getAuthRequest();
|
|
130
|
+
const _headers = {};
|
|
131
|
+
if (_authRequest.headers) {
|
|
132
|
+
for (const [key, value] of Object.entries(_authRequest.headers)) {
|
|
133
|
+
if (value != null) {
|
|
134
|
+
_headers[key] = String(value);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if ((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers) {
|
|
139
|
+
for (const [key, value] of Object.entries(this._options.headers)) {
|
|
140
|
+
if (value != null) {
|
|
141
|
+
_headers[key] = String(value);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers) {
|
|
146
|
+
for (const [key, value] of Object.entries(requestOptions.headers)) {
|
|
147
|
+
if (value != null) {
|
|
148
|
+
_headers[key] = String(value);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
_headers["Content-Type"] = "application/json";
|
|
153
|
+
_headers["Accept"] = "text/event-stream";
|
|
154
|
+
const baseUrl = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : ((_c = (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.SarvamAIEnvironment.Production).base;
|
|
155
|
+
const url = core.url.join(baseUrl, "v1/chat/completions");
|
|
156
|
+
const fetchFn = (_e = (_d = this._options) === null || _d === void 0 ? void 0 : _d.fetch) !== null && _e !== void 0 ? _e : (typeof fetch !== "undefined" ? fetch : undefined);
|
|
157
|
+
if (!fetchFn) {
|
|
158
|
+
throw new Error("No fetch function available. Please provide a fetch function in client options.");
|
|
159
|
+
}
|
|
160
|
+
const response = yield fetchFn(url, {
|
|
161
|
+
method: "POST",
|
|
162
|
+
headers: _headers,
|
|
163
|
+
body: JSON.stringify(request),
|
|
164
|
+
signal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
165
|
+
});
|
|
166
|
+
if (!response.ok) {
|
|
167
|
+
let errorBody;
|
|
168
|
+
try {
|
|
169
|
+
errorBody = yield response.json();
|
|
170
|
+
}
|
|
171
|
+
catch (_f) {
|
|
172
|
+
errorBody = yield response.text();
|
|
173
|
+
}
|
|
174
|
+
this._throwStatusCodeError(response.status, errorBody, (0, RawResponse_js_1.toRawResponse)(response));
|
|
175
|
+
}
|
|
176
|
+
if (!response.body) {
|
|
177
|
+
throw new errors.SarvamAIError({
|
|
178
|
+
message: "Response body is null for streaming request.",
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return this._parseSSEStream(response.body);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
_parseSSEStream(body) {
|
|
185
|
+
return __asyncGenerator(this, arguments, function* _parseSSEStream_1() {
|
|
186
|
+
var _a;
|
|
187
|
+
const reader = body.getReader();
|
|
188
|
+
const decoder = new TextDecoder();
|
|
189
|
+
let buffer = "";
|
|
190
|
+
try {
|
|
191
|
+
while (true) {
|
|
192
|
+
const { done, value } = yield __await(reader.read());
|
|
193
|
+
if (done)
|
|
194
|
+
break;
|
|
195
|
+
buffer += decoder.decode(value, { stream: true });
|
|
196
|
+
const lines = buffer.split("\n");
|
|
197
|
+
buffer = (_a = lines.pop()) !== null && _a !== void 0 ? _a : "";
|
|
198
|
+
for (const line of lines) {
|
|
199
|
+
const trimmed = line.trim();
|
|
200
|
+
if (!trimmed)
|
|
201
|
+
continue;
|
|
202
|
+
if (trimmed.startsWith("data: ")) {
|
|
203
|
+
const dataStr = trimmed.slice(6);
|
|
204
|
+
if (dataStr.trim() === "[DONE]") {
|
|
205
|
+
return yield __await(void 0);
|
|
206
|
+
}
|
|
207
|
+
try {
|
|
208
|
+
const chunk = JSON.parse(dataStr);
|
|
209
|
+
yield yield __await(chunk);
|
|
210
|
+
}
|
|
211
|
+
catch (_b) {
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (buffer.trim()) {
|
|
218
|
+
const trimmed = buffer.trim();
|
|
219
|
+
if (trimmed.startsWith("data: ")) {
|
|
220
|
+
const dataStr = trimmed.slice(6);
|
|
221
|
+
if (dataStr.trim() !== "[DONE]") {
|
|
222
|
+
try {
|
|
223
|
+
const chunk = JSON.parse(dataStr);
|
|
224
|
+
yield yield __await(chunk);
|
|
225
|
+
}
|
|
226
|
+
catch (_c) {
|
|
227
|
+
// ignore parse errors
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
finally {
|
|
234
|
+
reader.releaseLock();
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
_throwStatusCodeError(statusCode, body, rawResponse) {
|
|
239
|
+
switch (statusCode) {
|
|
240
|
+
case 400:
|
|
241
|
+
throw new SarvamAI.BadRequestError(body, rawResponse);
|
|
242
|
+
case 403:
|
|
243
|
+
throw new SarvamAI.ForbiddenError(body, rawResponse);
|
|
244
|
+
case 422:
|
|
245
|
+
throw new SarvamAI.UnprocessableEntityError(body, rawResponse);
|
|
246
|
+
case 429:
|
|
247
|
+
throw new SarvamAI.TooManyRequestsError(body, rawResponse);
|
|
248
|
+
case 500:
|
|
249
|
+
throw new SarvamAI.InternalServerError(body, rawResponse);
|
|
250
|
+
default:
|
|
251
|
+
throw new errors.SarvamAIError({
|
|
252
|
+
statusCode,
|
|
253
|
+
body,
|
|
254
|
+
rawResponse,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
147
258
|
}
|
|
148
259
|
exports.ChatClient = ChatClient;
|
|
@@ -3,14 +3,16 @@ import type * as SarvamAI from "../../../../index.js";
|
|
|
3
3
|
* @example
|
|
4
4
|
* {
|
|
5
5
|
* messages: [{
|
|
6
|
-
* role: "assistant"
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* role: "assistant"
|
|
7
|
+
* }],
|
|
8
|
+
* model: "sarvam-m"
|
|
9
9
|
* }
|
|
10
10
|
*/
|
|
11
11
|
export interface ChatCompletionsRequest {
|
|
12
12
|
/** A list of messages comprising the conversation so far. */
|
|
13
13
|
messages: SarvamAI.ChatCompletionRequestMessage[];
|
|
14
|
+
/** Model ID used to generate the response, like `sarvam-m`. */
|
|
15
|
+
model: SarvamAI.SarvamModelIds;
|
|
14
16
|
/**
|
|
15
17
|
* What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
|
|
16
18
|
* We generally recommend altering this or `top_p` but not both.
|
|
@@ -25,6 +27,7 @@ export interface ChatCompletionsRequest {
|
|
|
25
27
|
* We generally recommend altering this or `temperature` but not both.
|
|
26
28
|
*/
|
|
27
29
|
top_p?: number;
|
|
30
|
+
/** The effort to use for reasoning */
|
|
28
31
|
reasoning_effort?: SarvamAI.ReasoningEffort;
|
|
29
32
|
/** The maximum number of tokens that can be generated in the chat completion. */
|
|
30
33
|
max_tokens?: number;
|
|
@@ -39,6 +42,7 @@ export interface ChatCompletionsRequest {
|
|
|
39
42
|
/**
|
|
40
43
|
* This feature is in Beta.
|
|
41
44
|
* If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result.
|
|
45
|
+
* Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.
|
|
42
46
|
*/
|
|
43
47
|
seed?: number;
|
|
44
48
|
/**
|
|
@@ -53,6 +57,10 @@ export interface ChatCompletionsRequest {
|
|
|
53
57
|
* to talk about new topics.
|
|
54
58
|
*/
|
|
55
59
|
presence_penalty?: number;
|
|
56
|
-
/** If
|
|
60
|
+
/** If set to true, the model response will be wiki grounded. */
|
|
57
61
|
wiki_grounding?: boolean;
|
|
62
|
+
/** A list of tools the model may call. Currently, only functions are supported as a tool. */
|
|
63
|
+
tools?: SarvamAI.ChatCompletionTool[];
|
|
64
|
+
/** Controls which (if any) tool is called by the model. */
|
|
65
|
+
tool_choice?: SarvamAI.ToolChoiceOption;
|
|
58
66
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ChunkChoice } from "./ChunkChoice.js";
|
|
2
|
+
export interface ChatCompletionChunk {
|
|
3
|
+
id: string;
|
|
4
|
+
choices: ChunkChoice[];
|
|
5
|
+
created: number;
|
|
6
|
+
model: string;
|
|
7
|
+
object: "chat.completion.chunk";
|
|
8
|
+
service_tier?: string | null;
|
|
9
|
+
system_fingerprint?: string | null;
|
|
10
|
+
usage?: {
|
|
11
|
+
completion_tokens: number;
|
|
12
|
+
prompt_tokens: number;
|
|
13
|
+
total_tokens: number;
|
|
14
|
+
} | null;
|
|
15
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type * as SarvamAI from "../index.js";
|
|
2
|
+
export interface ChatCompletionMessageToolCall {
|
|
3
|
+
/** The ID of the tool call. */
|
|
4
|
+
id: string;
|
|
5
|
+
/** The type of the tool call, currently only `function`. */
|
|
6
|
+
type: "function";
|
|
7
|
+
function: SarvamAI.FunctionCall;
|
|
8
|
+
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import type * as SarvamAI from "../index.js";
|
|
1
2
|
export interface ChatCompletionRequestAssistantMessage {
|
|
2
3
|
/** The contents of the assistant message */
|
|
3
|
-
content
|
|
4
|
+
content?: string;
|
|
5
|
+
/** The tool calls generated by the model. */
|
|
6
|
+
tool_calls?: SarvamAI.ChatCompletionMessageToolCall[];
|
|
4
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as SarvamAI from "../index.js";
|
|
2
|
-
export type ChatCompletionRequestMessage = SarvamAI.ChatCompletionRequestMessage.Assistant | SarvamAI.ChatCompletionRequestMessage.System | SarvamAI.ChatCompletionRequestMessage.User;
|
|
2
|
+
export type ChatCompletionRequestMessage = SarvamAI.ChatCompletionRequestMessage.Assistant | SarvamAI.ChatCompletionRequestMessage.System | SarvamAI.ChatCompletionRequestMessage.Tool | SarvamAI.ChatCompletionRequestMessage.User;
|
|
3
3
|
export declare namespace ChatCompletionRequestMessage {
|
|
4
4
|
interface Assistant extends SarvamAI.ChatCompletionRequestAssistantMessage {
|
|
5
5
|
role: "assistant";
|
|
@@ -7,6 +7,9 @@ export declare namespace ChatCompletionRequestMessage {
|
|
|
7
7
|
interface System extends SarvamAI.ChatCompletionRequestSystemMessage {
|
|
8
8
|
role: "system";
|
|
9
9
|
}
|
|
10
|
+
interface Tool extends SarvamAI.ChatCompletionRequestToolMessage {
|
|
11
|
+
role: "tool";
|
|
12
|
+
}
|
|
10
13
|
interface User extends SarvamAI.ChatCompletionRequestUserMessage {
|
|
11
14
|
role: "user";
|
|
12
15
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type * as SarvamAI from "../index.js";
|
|
2
2
|
export interface ChatCompletionResponseMessage {
|
|
3
3
|
/** The contents of the message. */
|
|
4
|
-
content
|
|
4
|
+
content?: string;
|
|
5
|
+
refusal?: string;
|
|
6
|
+
/** The contents of the reasoning message. */
|
|
7
|
+
reasoning_content?: string;
|
|
5
8
|
/** The role of the author of this message. */
|
|
6
9
|
role: SarvamAI.Role;
|
|
10
|
+
/** The tool calls generated by the model. */
|
|
11
|
+
tool_calls?: SarvamAI.ChatCompletionMessageToolCall[];
|
|
7
12
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ChoiceDeltaToolCall } from "./ChoiceDeltaToolCall.js";
|
|
2
|
+
export interface ChoiceDelta {
|
|
3
|
+
content?: string | null;
|
|
4
|
+
refusal?: string | null;
|
|
5
|
+
reasoning_content?: string | null;
|
|
6
|
+
role?: string | null;
|
|
7
|
+
function_call?: Record<string, unknown> | null;
|
|
8
|
+
tool_calls?: ChoiceDeltaToolCall[] | null;
|
|
9
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface FunctionDefinition {
|
|
2
|
+
/** The name of the function to be called. */
|
|
3
|
+
name: string;
|
|
4
|
+
/** A description of what the function does. */
|
|
5
|
+
description?: string;
|
|
6
|
+
/** The parameters the function accepts, described as a JSON Schema object. */
|
|
7
|
+
parameters?: Record<string, unknown>;
|
|
8
|
+
}
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare const SarvamModelIds: {
|
|
2
|
+
readonly SarvamM: "sarvam-m";
|
|
3
|
+
readonly Gemma4B: "gemma-4b";
|
|
4
|
+
readonly Gemma12B: "gemma-12b";
|
|
5
|
+
readonly Sarvam30B: "sarvam-30b";
|
|
6
|
+
readonly Sarvam100B: "sarvam-100b";
|
|
7
|
+
};
|
|
8
|
+
export type SarvamModelIds = (typeof SarvamModelIds)[keyof typeof SarvamModelIds];
|
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// This file was auto-generated by Fern from our API Definition.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SarvamModelIds = void 0;
|
|
5
|
+
exports.SarvamModelIds = {
|
|
6
|
+
SarvamM: "sarvam-m",
|
|
7
|
+
Gemma4B: "gemma-4b",
|
|
8
|
+
Gemma12B: "gemma-12b",
|
|
9
|
+
Sarvam30B: "sarvam-30b",
|
|
10
|
+
Sarvam100B: "sarvam-100b",
|
|
11
|
+
};
|