@inference-gateway/sdk 0.6.0 → 0.6.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/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [0.6.1](https://github.com/inference-gateway/typescript-sdk/compare/v0.6.0...v0.6.1) (2025-04-28)
6
+
7
+ ### ♻️ Improvements
8
+
9
+ * Remove redundant request option ([#11](https://github.com/inference-gateway/typescript-sdk/issues/11)) ([82e34e2](https://github.com/inference-gateway/typescript-sdk/commit/82e34e2ee9782fd224945bff1bd4daf2859a4f79))
10
+
5
11
  ## [0.6.0](https://github.com/inference-gateway/typescript-sdk/compare/v0.5.1...v0.6.0) (2025-04-28)
6
12
 
7
13
  ### ✨ Features
@@ -40,11 +40,16 @@ export declare class InferenceGatewayClient {
40
40
  /**
41
41
  * Creates a chat completion.
42
42
  */
43
- createChatCompletion(request: SchemaCreateChatCompletionRequest, provider?: Provider): Promise<SchemaCreateChatCompletionResponse>;
43
+ createChatCompletion(request: Omit<SchemaCreateChatCompletionRequest, 'stream'>, provider?: Provider): Promise<SchemaCreateChatCompletionResponse>;
44
44
  /**
45
45
  * Creates a streaming chat completion.
46
+ * This method always sets stream=true internally, so there's no need to specify it in the request.
47
+ *
48
+ * @param request - Chat completion request (must include at least model and messages)
49
+ * @param callbacks - Callbacks for handling streaming events
50
+ * @param provider - Optional provider to use for this request
46
51
  */
47
- streamChatCompletion(request: SchemaCreateChatCompletionRequest, callbacks: ChatCompletionStreamCallbacks, provider?: Provider): Promise<void>;
52
+ streamChatCompletion(request: Omit<SchemaCreateChatCompletionRequest, 'stream' | 'stream_options'>, callbacks: ChatCompletionStreamCallbacks, provider?: Provider): Promise<void>;
48
53
  /**
49
54
  * Proxy a request to a specific provider.
50
55
  */
@@ -87,11 +87,16 @@ class InferenceGatewayClient {
87
87
  }
88
88
  return this.request('/chat/completions', {
89
89
  method: 'POST',
90
- body: JSON.stringify(request),
90
+ body: JSON.stringify({ ...request, stream: false }),
91
91
  }, query);
92
92
  }
93
93
  /**
94
94
  * Creates a streaming chat completion.
95
+ * This method always sets stream=true internally, so there's no need to specify it in the request.
96
+ *
97
+ * @param request - Chat completion request (must include at least model and messages)
98
+ * @param callbacks - Callbacks for handling streaming events
99
+ * @param provider - Optional provider to use for this request
95
100
  */
96
101
  async streamChatCompletion(request, callbacks, provider) {
97
102
  const query = {};
@@ -120,6 +125,9 @@ class InferenceGatewayClient {
120
125
  body: JSON.stringify({
121
126
  ...request,
122
127
  stream: true,
128
+ stream_options: {
129
+ include_usage: true,
130
+ },
123
131
  }),
124
132
  signal: controller.signal,
125
133
  });
@@ -89,7 +89,6 @@ describe('InferenceGatewayClient', () => {
89
89
  { role: generated_1.MessageRole.system, content: 'You are a helpful assistant' },
90
90
  { role: generated_1.MessageRole.user, content: 'Hello' },
91
91
  ],
92
- stream: false,
93
92
  };
94
93
  const mockResponse = {
95
94
  id: 'chatcmpl-123',
@@ -120,14 +119,13 @@ describe('InferenceGatewayClient', () => {
120
119
  expect(result).toEqual(mockResponse);
121
120
  expect(mockFetch).toHaveBeenCalledWith('http://localhost:8080/v1/chat/completions', expect.objectContaining({
122
121
  method: 'POST',
123
- body: JSON.stringify(mockRequest),
122
+ body: JSON.stringify({ ...mockRequest, stream: false }),
124
123
  }));
125
124
  });
126
125
  it('should create a chat completion with a specific provider', async () => {
127
126
  const mockRequest = {
128
127
  model: 'claude-3-opus-20240229',
129
128
  messages: [{ role: generated_1.MessageRole.user, content: 'Hello' }],
130
- stream: false,
131
129
  };
132
130
  const mockResponse = {
133
131
  id: 'chatcmpl-456',
@@ -158,7 +156,7 @@ describe('InferenceGatewayClient', () => {
158
156
  expect(result).toEqual(mockResponse);
159
157
  expect(mockFetch).toHaveBeenCalledWith('http://localhost:8080/v1/chat/completions?provider=anthropic', expect.objectContaining({
160
158
  method: 'POST',
161
- body: JSON.stringify(mockRequest),
159
+ body: JSON.stringify({ ...mockRequest, stream: false }),
162
160
  }));
163
161
  });
164
162
  });
@@ -167,7 +165,6 @@ describe('InferenceGatewayClient', () => {
167
165
  const mockRequest = {
168
166
  model: 'gpt-4o',
169
167
  messages: [{ role: generated_1.MessageRole.user, content: 'Hello' }],
170
- stream: true,
171
168
  };
172
169
  const mockStream = new web_1.TransformStream();
173
170
  const writer = mockStream.writable.getWriter();
@@ -201,6 +198,9 @@ describe('InferenceGatewayClient', () => {
201
198
  body: JSON.stringify({
202
199
  ...mockRequest,
203
200
  stream: true,
201
+ stream_options: {
202
+ include_usage: true,
203
+ },
204
204
  }),
205
205
  }));
206
206
  });
@@ -208,7 +208,6 @@ describe('InferenceGatewayClient', () => {
208
208
  const mockRequest = {
209
209
  model: 'gpt-4o',
210
210
  messages: [{ role: generated_1.MessageRole.user, content: 'Hello' }],
211
- stream: true,
212
211
  };
213
212
  const mockStream = new web_1.TransformStream();
214
213
  const writer = mockStream.writable.getWriter();
@@ -253,6 +252,9 @@ describe('InferenceGatewayClient', () => {
253
252
  body: JSON.stringify({
254
253
  ...mockRequest,
255
254
  stream: true,
255
+ stream_options: {
256
+ include_usage: true,
257
+ },
256
258
  }),
257
259
  }));
258
260
  });
@@ -274,7 +276,6 @@ describe('InferenceGatewayClient', () => {
274
276
  },
275
277
  },
276
278
  ],
277
- stream: true,
278
279
  };
279
280
  const mockStream = new web_1.TransformStream();
280
281
  const writer = mockStream.writable.getWriter();
@@ -312,12 +313,21 @@ describe('InferenceGatewayClient', () => {
312
313
  },
313
314
  });
314
315
  expect(callbacks.onFinish).toHaveBeenCalledTimes(1);
316
+ expect(mockFetch).toHaveBeenCalledWith('http://localhost:8080/v1/chat/completions', expect.objectContaining({
317
+ method: 'POST',
318
+ body: JSON.stringify({
319
+ ...mockRequest,
320
+ stream: true,
321
+ stream_options: {
322
+ include_usage: true,
323
+ },
324
+ }),
325
+ }));
315
326
  });
316
327
  it('should handle errors in streaming chat completions', async () => {
317
328
  const mockRequest = {
318
329
  model: 'gpt-4o',
319
330
  messages: [{ role: generated_1.MessageRole.user, content: 'Hello' }],
320
- stream: true,
321
331
  };
322
332
  mockFetch.mockResolvedValueOnce({
323
333
  ok: false,
@@ -334,10 +344,6 @@ describe('InferenceGatewayClient', () => {
334
344
  const mockRequest = {
335
345
  model: 'gpt-4o',
336
346
  messages: [{ role: generated_1.MessageRole.user, content: 'Hello' }],
337
- stream: true,
338
- stream_options: {
339
- include_usage: true,
340
- },
341
347
  };
342
348
  const mockStream = new web_1.TransformStream();
343
349
  const writer = mockStream.writable.getWriter();
@@ -379,6 +385,9 @@ describe('InferenceGatewayClient', () => {
379
385
  body: JSON.stringify({
380
386
  ...mockRequest,
381
387
  stream: true,
388
+ stream_options: {
389
+ include_usage: true,
390
+ },
382
391
  }),
383
392
  }));
384
393
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inference-gateway/sdk",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "An SDK written in Typescript for the [Inference Gateway](https://github.com/inference-gateway/inference-gateway).",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",