@inference-gateway/sdk 0.4.1 → 0.5.1-rc.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 +24 -0
- package/README.md +9 -5
- package/dist/src/client.d.ts +1 -0
- package/dist/src/client.js +4 -0
- package/dist/src/types/generated/index.d.ts +2 -7
- package/dist/tests/client.test.js +54 -2
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.5.1-rc.1](https://github.com/inference-gateway/typescript-sdk/compare/v0.5.0...v0.5.1-rc.1) (2025-04-27)
|
|
6
|
+
|
|
7
|
+
### 🐛 Bug Fixes
|
|
8
|
+
|
|
9
|
+
* Update FunctionParameters schema to enforce required properties and adjust ListModelsResponse structure ([465c762](https://github.com/inference-gateway/typescript-sdk/commit/465c762f7494435183a2f88cb262d423bb21a1e3))
|
|
10
|
+
|
|
11
|
+
### 📚 Documentation
|
|
12
|
+
|
|
13
|
+
* Add required fields to Model schema and clean up application settings ([7338c28](https://github.com/inference-gateway/typescript-sdk/commit/7338c28c0b8dd67f2c0faefc758cc3344de5c9d6))
|
|
14
|
+
|
|
15
|
+
### 🔧 Miscellaneous
|
|
16
|
+
|
|
17
|
+
* **tests:** Format test ([9f121a7](https://github.com/inference-gateway/typescript-sdk/commit/9f121a742d33cd9fa2776dc5fdc5f229f898ccd0))
|
|
18
|
+
|
|
19
|
+
## [0.5.0](https://github.com/inference-gateway/typescript-sdk/compare/v0.4.1...v0.5.0) (2025-04-26)
|
|
20
|
+
|
|
21
|
+
### ✨ Features
|
|
22
|
+
|
|
23
|
+
* Add on reasoning event callback function handling in streaming chat completions ([#7](https://github.com/inference-gateway/typescript-sdk/issues/7)) ([200eb12](https://github.com/inference-gateway/typescript-sdk/commit/200eb12c5890f46d00e5c9cdaaf40a3a306b4315))
|
|
24
|
+
|
|
25
|
+
### 📦 Miscellaneous
|
|
26
|
+
|
|
27
|
+
* Add husky pre-commit hook ([#8](https://github.com/inference-gateway/typescript-sdk/issues/8)) ([5ad49a0](https://github.com/inference-gateway/typescript-sdk/commit/5ad49a083e7767a3b7293328c9cead0769324ff6))
|
|
28
|
+
|
|
5
29
|
## [0.4.1](https://github.com/inference-gateway/typescript-sdk/compare/v0.4.0...v0.4.1) (2025-04-25)
|
|
6
30
|
|
|
7
31
|
### ♻️ Improvements
|
package/README.md
CHANGED
|
@@ -155,11 +155,11 @@ const client = new InferenceGatewayClient({
|
|
|
155
155
|
try {
|
|
156
156
|
await client.streamChatCompletion(
|
|
157
157
|
{
|
|
158
|
-
model: 'gpt-4o',
|
|
158
|
+
model: 'openai/gpt-4o',
|
|
159
159
|
messages: [
|
|
160
160
|
{
|
|
161
161
|
role: MessageRole.User,
|
|
162
|
-
content:
|
|
162
|
+
content: "What's the weather in San Francisco?",
|
|
163
163
|
},
|
|
164
164
|
],
|
|
165
165
|
tools: [
|
|
@@ -186,10 +186,14 @@ try {
|
|
|
186
186
|
console.log('Tool call:', toolCall.function.name);
|
|
187
187
|
console.log('Arguments:', toolCall.function.arguments);
|
|
188
188
|
},
|
|
189
|
-
|
|
189
|
+
onReasoning: (reasoning) => {
|
|
190
|
+
console.log('Reasoning:', reasoning);
|
|
191
|
+
},
|
|
192
|
+
onContent: (content) => {
|
|
193
|
+
console.log('Content:', content);
|
|
194
|
+
},
|
|
190
195
|
onFinish: () => console.log('\nStream completed'),
|
|
191
|
-
}
|
|
192
|
-
Provider.OpenAI
|
|
196
|
+
}
|
|
193
197
|
);
|
|
194
198
|
} catch (error) {
|
|
195
199
|
console.error('Error:', error);
|
package/dist/src/client.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Provider, SchemaChatCompletionMessageToolCall, SchemaCreateChatCom
|
|
|
2
2
|
interface ChatCompletionStreamCallbacks {
|
|
3
3
|
onOpen?: () => void;
|
|
4
4
|
onChunk?: (chunk: SchemaCreateChatCompletionStreamResponse) => void;
|
|
5
|
+
onReasoning?: (reasoningContent: string) => void;
|
|
5
6
|
onContent?: (content: string) => void;
|
|
6
7
|
onTool?: (toolCall: SchemaChatCompletionMessageToolCall) => void;
|
|
7
8
|
onFinish?: (response: SchemaCreateChatCompletionStreamResponse | null) => void;
|
package/dist/src/client.js
CHANGED
|
@@ -162,6 +162,10 @@ class InferenceGatewayClient {
|
|
|
162
162
|
try {
|
|
163
163
|
const chunk = JSON.parse(data);
|
|
164
164
|
callbacks.onChunk?.(chunk);
|
|
165
|
+
const reasoning_content = chunk.choices[0]?.delta?.reasoning_content;
|
|
166
|
+
if (reasoning_content !== undefined) {
|
|
167
|
+
callbacks.onReasoning?.(reasoning_content);
|
|
168
|
+
}
|
|
165
169
|
const content = chunk.choices[0]?.delta?.content;
|
|
166
170
|
if (content) {
|
|
167
171
|
callbacks.onContent?.(content);
|
|
@@ -212,7 +212,7 @@ export interface components {
|
|
|
212
212
|
/** @description Response structure for listing models */
|
|
213
213
|
ListModelsResponse: {
|
|
214
214
|
provider?: components['schemas']['Provider'];
|
|
215
|
-
object
|
|
215
|
+
object: string;
|
|
216
216
|
/** @default [] */
|
|
217
217
|
data: components['schemas']['Model'][];
|
|
218
218
|
};
|
|
@@ -235,12 +235,7 @@ export interface components {
|
|
|
235
235
|
/** @description The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/function-calling) for examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation about the format.
|
|
236
236
|
* Omitting `parameters` defines a function with an empty parameter list. */
|
|
237
237
|
FunctionParameters: {
|
|
238
|
-
|
|
239
|
-
type?: string;
|
|
240
|
-
/** @description The properties of the parameters. */
|
|
241
|
-
properties?: Record<string, never>;
|
|
242
|
-
/** @description The required properties of the parameters. */
|
|
243
|
-
required?: string[];
|
|
238
|
+
[key: string]: unknown;
|
|
244
239
|
};
|
|
245
240
|
/**
|
|
246
241
|
* @description The type of the tool. Currently, only `function` is supported.
|
|
@@ -204,6 +204,58 @@ describe('InferenceGatewayClient', () => {
|
|
|
204
204
|
}),
|
|
205
205
|
}));
|
|
206
206
|
});
|
|
207
|
+
it('should handle streaming chat completions reasoning and content', async () => {
|
|
208
|
+
const mockRequest = {
|
|
209
|
+
model: 'gpt-4o',
|
|
210
|
+
messages: [{ role: generated_1.MessageRole.user, content: 'Hello' }],
|
|
211
|
+
stream: true,
|
|
212
|
+
};
|
|
213
|
+
const mockStream = new web_1.TransformStream();
|
|
214
|
+
const writer = mockStream.writable.getWriter();
|
|
215
|
+
const encoder = new node_util_1.TextEncoder();
|
|
216
|
+
mockFetch.mockResolvedValueOnce({
|
|
217
|
+
ok: true,
|
|
218
|
+
body: mockStream.readable,
|
|
219
|
+
});
|
|
220
|
+
const callbacks = {
|
|
221
|
+
onOpen: jest.fn(),
|
|
222
|
+
onChunk: jest.fn(),
|
|
223
|
+
onReasoning: jest.fn(),
|
|
224
|
+
onContent: jest.fn(),
|
|
225
|
+
onFinish: jest.fn(),
|
|
226
|
+
};
|
|
227
|
+
const streamPromise = client.streamChatCompletion(mockRequest, callbacks);
|
|
228
|
+
await writer.write(encoder.encode('data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}\n\n' +
|
|
229
|
+
'data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"content":"","reasoning_content":"This"},"finish_reason":null}]}\n\n' +
|
|
230
|
+
'data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"content":"","reasoning_content":" is"},"finish_reason":null}]}\n\n' +
|
|
231
|
+
'data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"content":"","reasoning_content":" a"},"finish_reason":"stop"}]}\n\n' +
|
|
232
|
+
'data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"content":"","reasoning_content":" reasoning"},"finish_reason":"stop"}]}\n\n' +
|
|
233
|
+
'data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"content":"","reasoning_content":" content"},"finish_reason":"stop"}]}\n\n' +
|
|
234
|
+
'data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}\n\n' +
|
|
235
|
+
'data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}\n\n' +
|
|
236
|
+
'data: [DONE]\n\n'));
|
|
237
|
+
await writer.close();
|
|
238
|
+
await streamPromise;
|
|
239
|
+
expect(callbacks.onOpen).toHaveBeenCalledTimes(1);
|
|
240
|
+
expect(callbacks.onChunk).toHaveBeenCalledTimes(8);
|
|
241
|
+
expect(callbacks.onReasoning).toHaveBeenCalledTimes(5);
|
|
242
|
+
expect(callbacks.onReasoning).toHaveBeenCalledWith('This');
|
|
243
|
+
expect(callbacks.onReasoning).toHaveBeenCalledWith(' is');
|
|
244
|
+
expect(callbacks.onReasoning).toHaveBeenCalledWith(' a');
|
|
245
|
+
expect(callbacks.onReasoning).toHaveBeenCalledWith(' reasoning');
|
|
246
|
+
expect(callbacks.onReasoning).toHaveBeenCalledWith(' content');
|
|
247
|
+
expect(callbacks.onContent).toHaveBeenCalledTimes(2);
|
|
248
|
+
expect(callbacks.onContent).toHaveBeenCalledWith('Hello');
|
|
249
|
+
expect(callbacks.onContent).toHaveBeenCalledWith('!');
|
|
250
|
+
expect(callbacks.onFinish).toHaveBeenCalledTimes(1);
|
|
251
|
+
expect(mockFetch).toHaveBeenCalledWith('http://localhost:8080/v1/chat/completions', expect.objectContaining({
|
|
252
|
+
method: 'POST',
|
|
253
|
+
body: JSON.stringify({
|
|
254
|
+
...mockRequest,
|
|
255
|
+
stream: true,
|
|
256
|
+
}),
|
|
257
|
+
}));
|
|
258
|
+
});
|
|
207
259
|
it('should handle tool calls in streaming chat completions', async () => {
|
|
208
260
|
const mockRequest = {
|
|
209
261
|
model: 'gpt-4o',
|
|
@@ -256,8 +308,8 @@ describe('InferenceGatewayClient', () => {
|
|
|
256
308
|
type: 'function',
|
|
257
309
|
function: {
|
|
258
310
|
name: 'get_weather',
|
|
259
|
-
arguments: '{"location":"San Francisco, CA"}'
|
|
260
|
-
}
|
|
311
|
+
arguments: '{"location":"San Francisco, CA"}',
|
|
312
|
+
},
|
|
261
313
|
});
|
|
262
314
|
expect(callbacks.onFinish).toHaveBeenCalledTimes(1);
|
|
263
315
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inference-gateway/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1-rc.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",
|
|
@@ -49,7 +49,8 @@
|
|
|
49
49
|
"build": "tsc",
|
|
50
50
|
"test": "jest",
|
|
51
51
|
"lint": "eslint src/**/*.ts",
|
|
52
|
-
"
|
|
52
|
+
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
53
|
+
"prepare": "husky"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
56
|
"@eslint/js": "^9.18.0",
|
|
@@ -59,7 +60,9 @@
|
|
|
59
60
|
"@typescript-eslint/parser": "^8.21.0",
|
|
60
61
|
"eslint": "^9.18.0",
|
|
61
62
|
"eslint-plugin-prettier": "^5.2.3",
|
|
63
|
+
"husky": "^9.1.7",
|
|
62
64
|
"jest": "^29.7.0",
|
|
65
|
+
"prettier": "^3.5.3",
|
|
63
66
|
"ts-jest": "^29.2.5",
|
|
64
67
|
"typescript": "^5.7.3"
|
|
65
68
|
},
|