Skip to content

Commit 2a2c546

Browse files
edenreichGitHub Actions Bot
and
GitHub Actions Bot
authored
feat: Add reasoning_content to streaming deltas if they exists (#5)
* refactor: Update type exports and add type generation task Signed-off-by: Eden Reich <[email protected]> * chore: Update .gitattributes to mark generated types as linguist-generated Signed-off-by: Eden Reich <[email protected]> * chore: Remove unnecessary line from .gitattributes Signed-off-by: Eden Reich <[email protected]> * fix: Update release configuration to correctly match release candidate branches Signed-off-by: Eden Reich <[email protected]> * fix: Correct regex pattern for release candidate branches in configuration Signed-off-by: Eden Reich <[email protected]> * chore(release): 🔖 0.3.5-rc.1 [skip ci] ## [0.3.5-rc.1](v0.3.4...v0.3.5-rc.1) (2025-03-31) ### ♻️ Improvements * Update type exports and add type generation task ([919679e](919679e)) ### 🐛 Bug Fixes * Correct regex pattern for release candidate branches in configuration ([33db013](33db013)) * Update release configuration to correctly match release candidate branches ([03d91e1](03d91e1)) ### 🔧 Miscellaneous * Remove unnecessary line from .gitattributes ([66407b4](66407b4)) * Update .gitattributes to mark generated types as linguist-generated ([67f3d68](67f3d68)) * feat: Add reasoning_content field to chunk message in OpenAPI specification Signed-off-by: Eden Reich <[email protected]> * chore(release): 🔖 0.4.0-rc.1 [skip ci] ## [0.4.0-rc.1](v0.3.5-rc.1...v0.4.0-rc.1) (2025-03-31) ### ✨ Features * Add reasoning_content field to chunk message in OpenAPI specification ([4de08ed](4de08ed)) --------- Signed-off-by: Eden Reich <[email protected]> Co-authored-by: GitHub Actions Bot <205380857+inference-gateway-semantic-bot[bot]@users.noreply.github.com>
1 parent bb43984 commit 2a2c546

File tree

10 files changed

+867
-223
lines changed

10 files changed

+867
-223
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.devcontainer/** linguist-vendored=true
2+
src/types/generated/** linguist-generated=true

CHANGELOG.md

+22
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [0.4.0-rc.1](https://github.com/inference-gateway/typescript-sdk/compare/v0.3.5-rc.1...v0.4.0-rc.1) (2025-03-31)
6+
7+
### ✨ Features
8+
9+
* Add reasoning_content field to chunk message in OpenAPI specification ([4de08ed](https://github.com/inference-gateway/typescript-sdk/commit/4de08ed46f6078f77838bd9c4bae5e46eb12476c))
10+
11+
## [0.3.5-rc.1](https://github.com/inference-gateway/typescript-sdk/compare/v0.3.4...v0.3.5-rc.1) (2025-03-31)
12+
13+
### ♻️ Improvements
14+
15+
* Update type exports and add type generation task ([919679e](https://github.com/inference-gateway/typescript-sdk/commit/919679eac8142e25b5abcefd63ae00bc187f2a67))
16+
17+
### 🐛 Bug Fixes
18+
19+
* Correct regex pattern for release candidate branches in configuration ([33db013](https://github.com/inference-gateway/typescript-sdk/commit/33db013392c8a1a15cc5a3bebb0f4c6d58a73d41))
20+
* Update release configuration to correctly match release candidate branches ([03d91e1](https://github.com/inference-gateway/typescript-sdk/commit/03d91e1d94d1fc11e50a535ba131ef2ca089653e))
21+
22+
### 🔧 Miscellaneous
23+
24+
* Remove unnecessary line from .gitattributes ([66407b4](https://github.com/inference-gateway/typescript-sdk/commit/66407b4cba0bf96af457dbb66818f48da3a4abda))
25+
* Update .gitattributes to mark generated types as linguist-generated ([67f3d68](https://github.com/inference-gateway/typescript-sdk/commit/67f3d682ba1e131f9e416c45e097c76dfeec4bf6))
26+
527
## [0.3.4](https://github.com/inference-gateway/typescript-sdk/compare/v0.3.3...v0.3.4) (2025-03-31)
628

729
### ♻️ Improvements

Taskfile.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
version: "3"
2+
version: '3'
33

44
tasks:
55
oas-download:
@@ -21,3 +21,9 @@ tasks:
2121
desc: Run tests
2222
cmds:
2323
- npm run test
24+
25+
generate-types:
26+
desc: Generate TypeScript types from OpenAPI specification
27+
cmds:
28+
- npx openapi-typescript openapi.yaml --enum --enum-values --dedupe-enums=true --root-types -o src/types/generated/index.ts
29+
- npx prettier --write src/types/generated/index.ts

openapi.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,9 @@ components:
904904
content:
905905
type: string
906906
description: The contents of the chunk message.
907+
reasoning_content:
908+
type: string
909+
description: The reasoning content of the chunk message.
907910
tool_calls:
908911
type: array
909912
items:

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@inference-gateway/sdk",
3-
"version": "0.3.4",
3+
"version": "0.4.0-rc.1",
44
"description": "An SDK written in Typescript for the [Inference Gateway](https://github.com/inference-gateway/inference-gateway).",
55
"main": "dist/src/index.js",
66
"types": "dist/src/index.d.ts",

src/client.ts

+34-24
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
import {
2-
Error as ApiError,
3-
ChatCompletionMessageToolCall,
4-
ChatCompletionRequest,
5-
ChatCompletionResponse,
6-
ChatCompletionStreamCallbacks,
7-
ChatCompletionStreamResponse,
8-
ListModelsResponse,
1+
import type {
92
Provider,
10-
} from './types';
3+
SchemaChatCompletionMessageToolCall,
4+
SchemaCreateChatCompletionRequest,
5+
SchemaCreateChatCompletionResponse,
6+
SchemaCreateChatCompletionStreamResponse,
7+
SchemaError,
8+
SchemaListModelsResponse,
9+
} from './types/generated';
10+
import { ChatCompletionToolType } from './types/generated';
11+
12+
interface ChatCompletionStreamCallbacks {
13+
onOpen?: () => void;
14+
onChunk?: (chunk: SchemaCreateChatCompletionStreamResponse) => void;
15+
onContent?: (content: string) => void;
16+
onTool?: (toolCall: SchemaChatCompletionMessageToolCall) => void;
17+
onFinish?: (
18+
response: SchemaCreateChatCompletionStreamResponse | null
19+
) => void;
20+
onError?: (error: SchemaError) => void;
21+
}
1122

1223
export interface ClientOptions {
1324
baseURL?: string;
@@ -90,7 +101,7 @@ export class InferenceGatewayClient {
90101
});
91102

92103
if (!response.ok) {
93-
const error = (await response.json()) as ApiError;
104+
const error: SchemaError = await response.json();
94105
throw new Error(
95106
error.error || `HTTP error! status: ${response.status}`
96107
);
@@ -105,12 +116,12 @@ export class InferenceGatewayClient {
105116
/**
106117
* Lists the currently available models.
107118
*/
108-
async listModels(provider?: Provider): Promise<ListModelsResponse> {
119+
async listModels(provider?: Provider): Promise<SchemaListModelsResponse> {
109120
const query: Record<string, string> = {};
110121
if (provider) {
111122
query.provider = provider;
112123
}
113-
return this.request<ListModelsResponse>(
124+
return this.request<SchemaListModelsResponse>(
114125
'/models',
115126
{ method: 'GET' },
116127
query
@@ -121,14 +132,14 @@ export class InferenceGatewayClient {
121132
* Creates a chat completion.
122133
*/
123134
async createChatCompletion(
124-
request: ChatCompletionRequest,
135+
request: SchemaCreateChatCompletionRequest,
125136
provider?: Provider
126-
): Promise<ChatCompletionResponse> {
137+
): Promise<SchemaCreateChatCompletionResponse> {
127138
const query: Record<string, string> = {};
128139
if (provider) {
129140
query.provider = provider;
130141
}
131-
return this.request<ChatCompletionResponse>(
142+
return this.request<SchemaCreateChatCompletionResponse>(
132143
'/chat/completions',
133144
{
134145
method: 'POST',
@@ -142,7 +153,7 @@ export class InferenceGatewayClient {
142153
* Creates a streaming chat completion.
143154
*/
144155
async streamChatCompletion(
145-
request: ChatCompletionRequest,
156+
request: SchemaCreateChatCompletionRequest,
146157
callbacks: ChatCompletionStreamCallbacks,
147158
provider?: Provider
148159
): Promise<void> {
@@ -186,7 +197,7 @@ export class InferenceGatewayClient {
186197
});
187198

188199
if (!response.ok) {
189-
const error = (await response.json()) as ApiError;
200+
const error: SchemaError = await response.json();
190201
throw new Error(
191202
error.error || `HTTP error! status: ${response.status}`
192203
);
@@ -215,14 +226,13 @@ export class InferenceGatewayClient {
215226
const data = line.slice(5).trim();
216227

217228
if (data === '[DONE]') {
218-
callbacks.onFinish?.(
219-
null as unknown as ChatCompletionStreamResponse
220-
);
229+
callbacks.onFinish?.(null);
221230
return;
222231
}
223232

224233
try {
225-
const chunk = JSON.parse(data) as ChatCompletionStreamResponse;
234+
const chunk: SchemaCreateChatCompletionStreamResponse =
235+
JSON.parse(data);
226236
callbacks.onChunk?.(chunk);
227237

228238
const content = chunk.choices[0]?.delta?.content;
@@ -232,9 +242,9 @@ export class InferenceGatewayClient {
232242

233243
const toolCalls = chunk.choices[0]?.delta?.tool_calls;
234244
if (toolCalls && toolCalls.length > 0) {
235-
const toolCall: ChatCompletionMessageToolCall = {
245+
const toolCall: SchemaChatCompletionMessageToolCall = {
236246
id: toolCalls[0].id || '',
237-
type: 'function',
247+
type: ChatCompletionToolType.function,
238248
function: {
239249
name: toolCalls[0].function?.name || '',
240250
arguments: toolCalls[0].function?.arguments || '',
@@ -249,7 +259,7 @@ export class InferenceGatewayClient {
249259
}
250260
}
251261
} catch (error) {
252-
const apiError: ApiError = {
262+
const apiError: SchemaError = {
253263
error: (error as Error).message || 'Unknown error',
254264
};
255265
callbacks.onError?.(apiError);

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export * from './client';
2-
export * from './types';
2+
export * from './types/generated';

0 commit comments

Comments
 (0)