@inference-gateway/sdk 0.3.4 → 0.4.0-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 CHANGED
@@ -2,6 +2,28 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
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
+
5
27
  ## [0.3.4](https://github.com/inference-gateway/typescript-sdk/compare/v0.3.3...v0.3.4) (2025-03-31)
6
28
 
7
29
  ### ♻️ Improvements
@@ -1,4 +1,12 @@
1
- import { ChatCompletionRequest, ChatCompletionResponse, ChatCompletionStreamCallbacks, ListModelsResponse, Provider } from './types';
1
+ import type { Provider, SchemaChatCompletionMessageToolCall, SchemaCreateChatCompletionRequest, SchemaCreateChatCompletionResponse, SchemaCreateChatCompletionStreamResponse, SchemaError, SchemaListModelsResponse } from './types/generated';
2
+ interface ChatCompletionStreamCallbacks {
3
+ onOpen?: () => void;
4
+ onChunk?: (chunk: SchemaCreateChatCompletionStreamResponse) => void;
5
+ onContent?: (content: string) => void;
6
+ onTool?: (toolCall: SchemaChatCompletionMessageToolCall) => void;
7
+ onFinish?: (response: SchemaCreateChatCompletionStreamResponse | null) => void;
8
+ onError?: (error: SchemaError) => void;
9
+ }
2
10
  export interface ClientOptions {
3
11
  baseURL?: string;
4
12
  apiKey?: string;
@@ -26,15 +34,15 @@ export declare class InferenceGatewayClient {
26
34
  /**
27
35
  * Lists the currently available models.
28
36
  */
29
- listModels(provider?: Provider): Promise<ListModelsResponse>;
37
+ listModels(provider?: Provider): Promise<SchemaListModelsResponse>;
30
38
  /**
31
39
  * Creates a chat completion.
32
40
  */
33
- createChatCompletion(request: ChatCompletionRequest, provider?: Provider): Promise<ChatCompletionResponse>;
41
+ createChatCompletion(request: SchemaCreateChatCompletionRequest, provider?: Provider): Promise<SchemaCreateChatCompletionResponse>;
34
42
  /**
35
43
  * Creates a streaming chat completion.
36
44
  */
37
- streamChatCompletion(request: ChatCompletionRequest, callbacks: ChatCompletionStreamCallbacks, provider?: Provider): Promise<void>;
45
+ streamChatCompletion(request: SchemaCreateChatCompletionRequest, callbacks: ChatCompletionStreamCallbacks, provider?: Provider): Promise<void>;
38
46
  /**
39
47
  * Proxy a request to a specific provider.
40
48
  */
@@ -44,3 +52,4 @@ export declare class InferenceGatewayClient {
44
52
  */
45
53
  healthCheck(): Promise<boolean>;
46
54
  }
55
+ export {};
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InferenceGatewayClient = void 0;
4
+ const generated_1 = require("./types/generated");
4
5
  class InferenceGatewayClient {
5
6
  baseURL;
6
7
  apiKey;
@@ -57,7 +58,7 @@ class InferenceGatewayClient {
57
58
  signal: controller.signal,
58
59
  });
59
60
  if (!response.ok) {
60
- const error = (await response.json());
61
+ const error = await response.json();
61
62
  throw new Error(error.error || `HTTP error! status: ${response.status}`);
62
63
  }
63
64
  return response.json();
@@ -123,7 +124,7 @@ class InferenceGatewayClient {
123
124
  signal: controller.signal,
124
125
  });
125
126
  if (!response.ok) {
126
- const error = (await response.json());
127
+ const error = await response.json();
127
128
  throw new Error(error.error || `HTTP error! status: ${response.status}`);
128
129
  }
129
130
  if (!response.body) {
@@ -158,7 +159,7 @@ class InferenceGatewayClient {
158
159
  if (toolCalls && toolCalls.length > 0) {
159
160
  const toolCall = {
160
161
  id: toolCalls[0].id || '',
161
- type: 'function',
162
+ type: generated_1.ChatCompletionToolType.function,
162
163
  function: {
163
164
  name: toolCalls[0].function?.name || '',
164
165
  arguments: toolCalls[0].function?.arguments || '',
@@ -1,2 +1,2 @@
1
1
  export * from './client';
2
- export * from './types';
2
+ export * from './types/generated';
package/dist/src/index.js CHANGED
@@ -15,4 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./client"), exports);
18
- __exportStar(require("./types"), exports);
18
+ __exportStar(require("./types/generated"), exports);
@@ -0,0 +1,743 @@
1
+ /**
2
+ * This file was auto-generated by openapi-typescript.
3
+ * Do not make direct changes to the file.
4
+ */
5
+ export interface paths {
6
+ '/models': {
7
+ parameters: {
8
+ query?: never;
9
+ header?: never;
10
+ path?: never;
11
+ cookie?: never;
12
+ };
13
+ /**
14
+ * Lists the currently available models, and provides basic information about each one such as the owner and availability.
15
+ * @description Lists the currently available models, and provides basic information
16
+ * about each one such as the owner and availability.
17
+ *
18
+ */
19
+ get: operations['listModels'];
20
+ put?: never;
21
+ post?: never;
22
+ delete?: never;
23
+ options?: never;
24
+ head?: never;
25
+ patch?: never;
26
+ trace?: never;
27
+ };
28
+ '/chat/completions': {
29
+ parameters: {
30
+ query?: never;
31
+ header?: never;
32
+ path?: never;
33
+ cookie?: never;
34
+ };
35
+ get?: never;
36
+ put?: never;
37
+ /**
38
+ * Create a chat completion
39
+ * @description Generates a chat completion based on the provided input.
40
+ * The completion can be streamed to the client as it is generated.
41
+ *
42
+ */
43
+ post: operations['createChatCompletion'];
44
+ delete?: never;
45
+ options?: never;
46
+ head?: never;
47
+ patch?: never;
48
+ trace?: never;
49
+ };
50
+ '/proxy/{provider}/{path}': {
51
+ parameters: {
52
+ query?: never;
53
+ header?: never;
54
+ path: {
55
+ provider: components['schemas']['Provider'];
56
+ /** @description The remaining path to proxy to the provider */
57
+ path: string;
58
+ };
59
+ cookie?: never;
60
+ };
61
+ /**
62
+ * Proxy GET request to provider
63
+ * @description Proxy GET request to provider
64
+ * The request body depends on the specific provider and endpoint being called.
65
+ * If you decide to use this approach, please follow the provider-specific documentations.
66
+ *
67
+ */
68
+ get: operations['proxyGet'];
69
+ /**
70
+ * Proxy PUT request to provider
71
+ * @description Proxy PUT request to provider
72
+ * The request body depends on the specific provider and endpoint being called.
73
+ * If you decide to use this approach, please follow the provider-specific documentations.
74
+ *
75
+ */
76
+ put: operations['proxyPut'];
77
+ /**
78
+ * Proxy POST request to provider
79
+ * @description Proxy POST request to provider
80
+ * The request body depends on the specific provider and endpoint being called.
81
+ * If you decide to use this approach, please follow the provider-specific documentations.
82
+ *
83
+ */
84
+ post: operations['proxyPost'];
85
+ /**
86
+ * Proxy DELETE request to provider
87
+ * @description Proxy DELETE request to provider
88
+ * The request body depends on the specific provider and endpoint being called.
89
+ * If you decide to use this approach, please follow the provider-specific documentations.
90
+ *
91
+ */
92
+ delete: operations['proxyDelete'];
93
+ options?: never;
94
+ head?: never;
95
+ /**
96
+ * Proxy PATCH request to provider
97
+ * @description Proxy PATCH request to provider
98
+ * The request body depends on the specific provider and endpoint being called.
99
+ * If you decide to use this approach, please follow the provider-specific documentations.
100
+ *
101
+ */
102
+ patch: operations['proxyPatch'];
103
+ trace?: never;
104
+ };
105
+ '/health': {
106
+ parameters: {
107
+ query?: never;
108
+ header?: never;
109
+ path?: never;
110
+ cookie?: never;
111
+ };
112
+ /**
113
+ * Health check
114
+ * @description Health check endpoint
115
+ * Returns a 200 status code if the service is healthy
116
+ *
117
+ */
118
+ get: operations['healthCheck'];
119
+ put?: never;
120
+ post?: never;
121
+ delete?: never;
122
+ options?: never;
123
+ head?: never;
124
+ patch?: never;
125
+ trace?: never;
126
+ };
127
+ }
128
+ export type webhooks = Record<string, never>;
129
+ export interface components {
130
+ schemas: {
131
+ /** @enum {string} */
132
+ Provider: Provider;
133
+ /** @description Provider-specific response format. Examples:
134
+ *
135
+ * OpenAI GET /v1/models?provider=openai response:
136
+ * ```json
137
+ * {
138
+ * "provider": "openai",
139
+ * "object": "list",
140
+ * "data": [
141
+ * {
142
+ * "id": "gpt-4",
143
+ * "object": "model",
144
+ * "created": 1687882410,
145
+ * "owned_by": "openai",
146
+ * "served_by": "openai"
147
+ * }
148
+ * ]
149
+ * }
150
+ * ```
151
+ *
152
+ * Anthropic GET /v1/models?provider=anthropic response:
153
+ * ```json
154
+ * {
155
+ * "provider": "anthropic",
156
+ * "object": "list",
157
+ * "data": [
158
+ * {
159
+ * "id": "gpt-4",
160
+ * "object": "model",
161
+ * "created": 1687882410,
162
+ * "owned_by": "openai",
163
+ * "served_by": "openai"
164
+ * }
165
+ * ]
166
+ * }
167
+ * ```
168
+ * */
169
+ ProviderSpecificResponse: Record<string, never>;
170
+ /**
171
+ * @description Authentication type for providers
172
+ * @enum {string}
173
+ */
174
+ ProviderAuthType: ProviderAuthType;
175
+ SSEvent: {
176
+ /** @enum {string} */
177
+ event?: SSEventEvent;
178
+ /** Format: byte */
179
+ data?: string;
180
+ retry?: number;
181
+ };
182
+ Endpoints: {
183
+ models?: string;
184
+ chat?: string;
185
+ };
186
+ Error: {
187
+ error?: string;
188
+ };
189
+ /**
190
+ * @description Role of the message sender
191
+ * @enum {string}
192
+ */
193
+ MessageRole: MessageRole;
194
+ /** @description Message structure for provider requests */
195
+ Message: {
196
+ role: components['schemas']['MessageRole'];
197
+ content: string;
198
+ tool_calls?: components['schemas']['ChatCompletionMessageToolCall'][];
199
+ tool_call_id?: string;
200
+ reasoning?: string;
201
+ reasoning_content?: string;
202
+ };
203
+ /** @description Common model information */
204
+ Model: {
205
+ id?: string;
206
+ object?: string;
207
+ /** Format: int64 */
208
+ created?: number;
209
+ owned_by?: string;
210
+ served_by?: components['schemas']['Provider'];
211
+ };
212
+ /** @description Response structure for listing models */
213
+ ListModelsResponse: {
214
+ provider?: components['schemas']['Provider'];
215
+ object?: string;
216
+ /** @default [] */
217
+ data: components['schemas']['Model'][];
218
+ };
219
+ FunctionObject: {
220
+ /** @description A description of what the function does, used by the model to choose when and how to call the function. */
221
+ description?: string;
222
+ /** @description The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64. */
223
+ name: string;
224
+ parameters?: components['schemas']['FunctionParameters'];
225
+ /**
226
+ * @description Whether to enable strict schema adherence when generating the function call. If set to true, the model will follow the exact schema defined in the `parameters` field. Only a subset of JSON Schema is supported when `strict` is `true`. Learn more about Structured Outputs in the [function calling guide](docs/guides/function-calling).
227
+ * @default false
228
+ */
229
+ strict: boolean;
230
+ };
231
+ ChatCompletionTool: {
232
+ type: components['schemas']['ChatCompletionToolType'];
233
+ function: components['schemas']['FunctionObject'];
234
+ };
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
+ * Omitting `parameters` defines a function with an empty parameter list. */
237
+ FunctionParameters: {
238
+ /** @description The type of the parameters. Currently, only `object` is supported. */
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[];
244
+ };
245
+ /**
246
+ * @description The type of the tool. Currently, only `function` is supported.
247
+ * @enum {string}
248
+ */
249
+ ChatCompletionToolType: ChatCompletionToolType;
250
+ /** @description Usage statistics for the completion request. */
251
+ CompletionUsage: {
252
+ /**
253
+ * Format: int64
254
+ * @description Number of tokens in the generated completion.
255
+ * @default 0
256
+ */
257
+ completion_tokens: number;
258
+ /**
259
+ * Format: int64
260
+ * @description Number of tokens in the prompt.
261
+ * @default 0
262
+ */
263
+ prompt_tokens: number;
264
+ /**
265
+ * Format: int64
266
+ * @description Total number of tokens used in the request (prompt + completion).
267
+ * @default 0
268
+ */
269
+ total_tokens: number;
270
+ };
271
+ /** @description Options for streaming response. Only set this when you set `stream: true`.
272
+ * */
273
+ ChatCompletionStreamOptions: {
274
+ /**
275
+ * @description If set, an additional chunk will be streamed before the `data: [DONE]` message. The `usage` field on this chunk shows the token usage statistics for the entire request, and the `choices` field will always be an empty array. All other chunks will also include a `usage` field, but with a null value.
276
+ *
277
+ * @default true
278
+ */
279
+ include_usage: boolean;
280
+ };
281
+ CreateChatCompletionRequest: {
282
+ /** @description Model ID to use */
283
+ model: string;
284
+ /** @description A list of messages comprising the conversation so far.
285
+ * */
286
+ messages: components['schemas']['Message'][];
287
+ /** @description An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.
288
+ * */
289
+ max_tokens?: number;
290
+ /**
291
+ * @description If set to true, the model response data will be streamed to the client as it is generated using [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).
292
+ *
293
+ * @default false
294
+ */
295
+ stream: boolean;
296
+ stream_options?: components['schemas']['ChatCompletionStreamOptions'];
297
+ /** @description A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported.
298
+ * */
299
+ tools?: components['schemas']['ChatCompletionTool'][];
300
+ };
301
+ /** @description The function that the model called. */
302
+ ChatCompletionMessageToolCallFunction: {
303
+ /** @description The name of the function to call. */
304
+ name: string;
305
+ /** @description The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function. */
306
+ arguments: string;
307
+ };
308
+ ChatCompletionMessageToolCall: {
309
+ /** @description The ID of the tool call. */
310
+ id: string;
311
+ type: components['schemas']['ChatCompletionToolType'];
312
+ function: components['schemas']['ChatCompletionMessageToolCallFunction'];
313
+ };
314
+ ChatCompletionChoice: {
315
+ /**
316
+ * @description The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence,
317
+ * `length` if the maximum number of tokens specified in the request was reached,
318
+ * `content_filter` if content was omitted due to a flag from our content filters,
319
+ * `tool_calls` if the model called a tool.
320
+ *
321
+ * @enum {string}
322
+ */
323
+ finish_reason: ChatCompletionChoiceFinish_reason;
324
+ /** @description The index of the choice in the list of choices. */
325
+ index: number;
326
+ message: components['schemas']['Message'];
327
+ };
328
+ ChatCompletionStreamChoice: {
329
+ delta: components['schemas']['ChatCompletionStreamResponseDelta'];
330
+ /** @description Log probability information for the choice. */
331
+ logprobs?: {
332
+ /** @description A list of message content tokens with log probability information. */
333
+ content: components['schemas']['ChatCompletionTokenLogprob'][];
334
+ /** @description A list of message refusal tokens with log probability information. */
335
+ refusal: components['schemas']['ChatCompletionTokenLogprob'][];
336
+ };
337
+ finish_reason: components['schemas']['FinishReason'];
338
+ /** @description The index of the choice in the list of choices. */
339
+ index: number;
340
+ };
341
+ /** @description Represents a chat completion response returned by model, based on the provided input. */
342
+ CreateChatCompletionResponse: {
343
+ /** @description A unique identifier for the chat completion. */
344
+ id: string;
345
+ /** @description A list of chat completion choices. Can be more than one if `n` is greater than 1. */
346
+ choices: components['schemas']['ChatCompletionChoice'][];
347
+ /** @description The Unix timestamp (in seconds) of when the chat completion was created. */
348
+ created: number;
349
+ /** @description The model used for the chat completion. */
350
+ model: string;
351
+ /** @description The object type, which is always `chat.completion`. */
352
+ object: string;
353
+ usage?: components['schemas']['CompletionUsage'];
354
+ };
355
+ /** @description A chat completion delta generated by streamed model responses. */
356
+ ChatCompletionStreamResponseDelta: {
357
+ /** @description The contents of the chunk message. */
358
+ content?: string;
359
+ /** @description The reasoning content of the chunk message. */
360
+ reasoning_content?: string;
361
+ tool_calls?: components['schemas']['ChatCompletionMessageToolCallChunk'][];
362
+ role?: components['schemas']['MessageRole'];
363
+ /** @description The refusal message generated by the model. */
364
+ refusal?: string;
365
+ };
366
+ ChatCompletionMessageToolCallChunk: {
367
+ index: number;
368
+ /** @description The ID of the tool call. */
369
+ id?: string;
370
+ /** @description The type of the tool. Currently, only `function` is supported. */
371
+ type?: string;
372
+ function?: {
373
+ /** @description The name of the function to call. */
374
+ name?: string;
375
+ /** @description The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function. */
376
+ arguments?: string;
377
+ };
378
+ };
379
+ ChatCompletionTokenLogprob: {
380
+ /** @description The token. */
381
+ token: string;
382
+ /** @description The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value `-9999.0` is used to signify that the token is very unlikely. */
383
+ logprob: number;
384
+ /** @description A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be `null` if there is no bytes representation for the token. */
385
+ bytes: number[];
386
+ /** @description List of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested `top_logprobs` returned. */
387
+ top_logprobs: {
388
+ /** @description The token. */
389
+ token: string;
390
+ /** @description The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value `-9999.0` is used to signify that the token is very unlikely. */
391
+ logprob: number;
392
+ /** @description A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be `null` if there is no bytes representation for the token. */
393
+ bytes: number[];
394
+ }[];
395
+ };
396
+ /**
397
+ * @description The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence,
398
+ * `length` if the maximum number of tokens specified in the request was reached,
399
+ * `content_filter` if content was omitted due to a flag from our content filters,
400
+ * `tool_calls` if the model called a tool.
401
+ *
402
+ * @enum {string}
403
+ */
404
+ FinishReason: ChatCompletionChoiceFinish_reason;
405
+ /** @description Represents a streamed chunk of a chat completion response returned
406
+ * by the model, based on the provided input.
407
+ * */
408
+ CreateChatCompletionStreamResponse: {
409
+ /** @description A unique identifier for the chat completion. Each chunk has the same ID. */
410
+ id: string;
411
+ /** @description A list of chat completion choices. Can contain more than one elements if `n` is greater than 1. Can also be empty for the
412
+ * last chunk if you set `stream_options: {"include_usage": true}`.
413
+ * */
414
+ choices: components['schemas']['ChatCompletionStreamChoice'][];
415
+ /** @description The Unix timestamp (in seconds) of when the chat completion was created. Each chunk has the same timestamp. */
416
+ created: number;
417
+ /** @description The model to generate the completion. */
418
+ model: string;
419
+ /** @description This fingerprint represents the backend configuration that the model runs with.
420
+ * Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism.
421
+ * */
422
+ system_fingerprint?: string;
423
+ /** @description The object type, which is always `chat.completion.chunk`. */
424
+ object: string;
425
+ usage?: components['schemas']['CompletionUsage'];
426
+ };
427
+ Config: unknown;
428
+ };
429
+ responses: {
430
+ /** @description Bad request */
431
+ BadRequest: {
432
+ headers: {
433
+ [name: string]: unknown;
434
+ };
435
+ content: {
436
+ 'application/json': components['schemas']['Error'];
437
+ };
438
+ };
439
+ /** @description Unauthorized */
440
+ Unauthorized: {
441
+ headers: {
442
+ [name: string]: unknown;
443
+ };
444
+ content: {
445
+ 'application/json': components['schemas']['Error'];
446
+ };
447
+ };
448
+ /** @description Internal server error */
449
+ InternalError: {
450
+ headers: {
451
+ [name: string]: unknown;
452
+ };
453
+ content: {
454
+ 'application/json': components['schemas']['Error'];
455
+ };
456
+ };
457
+ /** @description ProviderResponse depends on the specific provider and endpoint being called
458
+ * If you decide to use this approach, please follow the provider-specific documentations.
459
+ * */
460
+ ProviderResponse: {
461
+ headers: {
462
+ [name: string]: unknown;
463
+ };
464
+ content: {
465
+ 'application/json': components['schemas']['ProviderSpecificResponse'];
466
+ };
467
+ };
468
+ };
469
+ parameters: never;
470
+ requestBodies: {
471
+ /** @description ProviderRequest depends on the specific provider and endpoint being called
472
+ * If you decide to use this approach, please follow the provider-specific documentations.
473
+ * */
474
+ ProviderRequest: {
475
+ content: {
476
+ 'application/json': {
477
+ model?: string;
478
+ messages?: {
479
+ role?: string;
480
+ content?: string;
481
+ }[];
482
+ /**
483
+ * Format: float
484
+ * @default 0.7
485
+ */
486
+ temperature?: number;
487
+ };
488
+ };
489
+ };
490
+ /** @description ProviderRequest depends on the specific provider and endpoint being called
491
+ * If you decide to use this approach, please follow the provider-specific documentations.
492
+ * */
493
+ CreateChatCompletionRequest: {
494
+ content: {
495
+ 'application/json': components['schemas']['CreateChatCompletionRequest'];
496
+ };
497
+ };
498
+ };
499
+ headers: never;
500
+ pathItems: never;
501
+ }
502
+ export type SchemaProvider = components['schemas']['Provider'];
503
+ export type SchemaProviderSpecificResponse = components['schemas']['ProviderSpecificResponse'];
504
+ export type SchemaProviderAuthType = components['schemas']['ProviderAuthType'];
505
+ export type SchemaSsEvent = components['schemas']['SSEvent'];
506
+ export type SchemaEndpoints = components['schemas']['Endpoints'];
507
+ export type SchemaError = components['schemas']['Error'];
508
+ export type SchemaMessageRole = components['schemas']['MessageRole'];
509
+ export type SchemaMessage = components['schemas']['Message'];
510
+ export type SchemaModel = components['schemas']['Model'];
511
+ export type SchemaListModelsResponse = components['schemas']['ListModelsResponse'];
512
+ export type SchemaFunctionObject = components['schemas']['FunctionObject'];
513
+ export type SchemaChatCompletionTool = components['schemas']['ChatCompletionTool'];
514
+ export type SchemaFunctionParameters = components['schemas']['FunctionParameters'];
515
+ export type SchemaChatCompletionToolType = components['schemas']['ChatCompletionToolType'];
516
+ export type SchemaCompletionUsage = components['schemas']['CompletionUsage'];
517
+ export type SchemaChatCompletionStreamOptions = components['schemas']['ChatCompletionStreamOptions'];
518
+ export type SchemaCreateChatCompletionRequest = components['schemas']['CreateChatCompletionRequest'];
519
+ export type SchemaChatCompletionMessageToolCallFunction = components['schemas']['ChatCompletionMessageToolCallFunction'];
520
+ export type SchemaChatCompletionMessageToolCall = components['schemas']['ChatCompletionMessageToolCall'];
521
+ export type SchemaChatCompletionChoice = components['schemas']['ChatCompletionChoice'];
522
+ export type SchemaChatCompletionStreamChoice = components['schemas']['ChatCompletionStreamChoice'];
523
+ export type SchemaCreateChatCompletionResponse = components['schemas']['CreateChatCompletionResponse'];
524
+ export type SchemaChatCompletionStreamResponseDelta = components['schemas']['ChatCompletionStreamResponseDelta'];
525
+ export type SchemaChatCompletionMessageToolCallChunk = components['schemas']['ChatCompletionMessageToolCallChunk'];
526
+ export type SchemaChatCompletionTokenLogprob = components['schemas']['ChatCompletionTokenLogprob'];
527
+ export type SchemaFinishReason = components['schemas']['FinishReason'];
528
+ export type SchemaCreateChatCompletionStreamResponse = components['schemas']['CreateChatCompletionStreamResponse'];
529
+ export type SchemaConfig = components['schemas']['Config'];
530
+ export type ResponseBadRequest = components['responses']['BadRequest'];
531
+ export type ResponseUnauthorized = components['responses']['Unauthorized'];
532
+ export type ResponseInternalError = components['responses']['InternalError'];
533
+ export type ResponseProviderResponse = components['responses']['ProviderResponse'];
534
+ export type RequestBodyProviderRequest = components['requestBodies']['ProviderRequest'];
535
+ export type RequestBodyCreateChatCompletionRequest = components['requestBodies']['CreateChatCompletionRequest'];
536
+ export type $defs = Record<string, never>;
537
+ export interface operations {
538
+ listModels: {
539
+ parameters: {
540
+ query?: {
541
+ /** @description Specific provider to query (optional) */
542
+ provider?: components['schemas']['Provider'];
543
+ };
544
+ header?: never;
545
+ path?: never;
546
+ cookie?: never;
547
+ };
548
+ requestBody?: never;
549
+ responses: {
550
+ /** @description List of available models */
551
+ 200: {
552
+ headers: {
553
+ [name: string]: unknown;
554
+ };
555
+ content: {
556
+ 'application/json': components['schemas']['ListModelsResponse'];
557
+ };
558
+ };
559
+ 401: components['responses']['Unauthorized'];
560
+ 500: components['responses']['InternalError'];
561
+ };
562
+ };
563
+ createChatCompletion: {
564
+ parameters: {
565
+ query?: {
566
+ /** @description Specific provider to use (default determined by model) */
567
+ provider?: components['schemas']['Provider'];
568
+ };
569
+ header?: never;
570
+ path?: never;
571
+ cookie?: never;
572
+ };
573
+ requestBody: components['requestBodies']['CreateChatCompletionRequest'];
574
+ responses: {
575
+ /** @description Successful response */
576
+ 200: {
577
+ headers: {
578
+ [name: string]: unknown;
579
+ };
580
+ content: {
581
+ 'application/json': components['schemas']['CreateChatCompletionResponse'];
582
+ 'text/event-stream': components['schemas']['SSEvent'];
583
+ };
584
+ };
585
+ 400: components['responses']['BadRequest'];
586
+ 401: components['responses']['Unauthorized'];
587
+ 500: components['responses']['InternalError'];
588
+ };
589
+ };
590
+ proxyGet: {
591
+ parameters: {
592
+ query?: never;
593
+ header?: never;
594
+ path: {
595
+ provider: components['schemas']['Provider'];
596
+ /** @description The remaining path to proxy to the provider */
597
+ path: string;
598
+ };
599
+ cookie?: never;
600
+ };
601
+ requestBody?: never;
602
+ responses: {
603
+ 200: components['responses']['ProviderResponse'];
604
+ 400: components['responses']['BadRequest'];
605
+ 401: components['responses']['Unauthorized'];
606
+ 500: components['responses']['InternalError'];
607
+ };
608
+ };
609
+ proxyPut: {
610
+ parameters: {
611
+ query?: never;
612
+ header?: never;
613
+ path: {
614
+ provider: components['schemas']['Provider'];
615
+ /** @description The remaining path to proxy to the provider */
616
+ path: string;
617
+ };
618
+ cookie?: never;
619
+ };
620
+ requestBody: components['requestBodies']['ProviderRequest'];
621
+ responses: {
622
+ 200: components['responses']['ProviderResponse'];
623
+ 400: components['responses']['BadRequest'];
624
+ 401: components['responses']['Unauthorized'];
625
+ 500: components['responses']['InternalError'];
626
+ };
627
+ };
628
+ proxyPost: {
629
+ parameters: {
630
+ query?: never;
631
+ header?: never;
632
+ path: {
633
+ provider: components['schemas']['Provider'];
634
+ /** @description The remaining path to proxy to the provider */
635
+ path: string;
636
+ };
637
+ cookie?: never;
638
+ };
639
+ requestBody: components['requestBodies']['ProviderRequest'];
640
+ responses: {
641
+ 200: components['responses']['ProviderResponse'];
642
+ 400: components['responses']['BadRequest'];
643
+ 401: components['responses']['Unauthorized'];
644
+ 500: components['responses']['InternalError'];
645
+ };
646
+ };
647
+ proxyDelete: {
648
+ parameters: {
649
+ query?: never;
650
+ header?: never;
651
+ path: {
652
+ provider: components['schemas']['Provider'];
653
+ /** @description The remaining path to proxy to the provider */
654
+ path: string;
655
+ };
656
+ cookie?: never;
657
+ };
658
+ requestBody?: never;
659
+ responses: {
660
+ 200: components['responses']['ProviderResponse'];
661
+ 400: components['responses']['BadRequest'];
662
+ 401: components['responses']['Unauthorized'];
663
+ 500: components['responses']['InternalError'];
664
+ };
665
+ };
666
+ proxyPatch: {
667
+ parameters: {
668
+ query?: never;
669
+ header?: never;
670
+ path: {
671
+ provider: components['schemas']['Provider'];
672
+ /** @description The remaining path to proxy to the provider */
673
+ path: string;
674
+ };
675
+ cookie?: never;
676
+ };
677
+ requestBody: components['requestBodies']['ProviderRequest'];
678
+ responses: {
679
+ 200: components['responses']['ProviderResponse'];
680
+ 400: components['responses']['BadRequest'];
681
+ 401: components['responses']['Unauthorized'];
682
+ 500: components['responses']['InternalError'];
683
+ };
684
+ };
685
+ healthCheck: {
686
+ parameters: {
687
+ query?: never;
688
+ header?: never;
689
+ path?: never;
690
+ cookie?: never;
691
+ };
692
+ requestBody?: never;
693
+ responses: {
694
+ /** @description Health check successful */
695
+ 200: {
696
+ headers: {
697
+ [name: string]: unknown;
698
+ };
699
+ content?: never;
700
+ };
701
+ };
702
+ };
703
+ }
704
+ export declare enum Provider {
705
+ ollama = "ollama",
706
+ groq = "groq",
707
+ openai = "openai",
708
+ cloudflare = "cloudflare",
709
+ cohere = "cohere",
710
+ anthropic = "anthropic",
711
+ deepseek = "deepseek"
712
+ }
713
+ export declare enum ProviderAuthType {
714
+ bearer = "bearer",
715
+ xheader = "xheader",
716
+ query = "query",
717
+ none = "none"
718
+ }
719
+ export declare enum SSEventEvent {
720
+ message_start = "message-start",
721
+ stream_start = "stream-start",
722
+ content_start = "content-start",
723
+ content_delta = "content-delta",
724
+ content_end = "content-end",
725
+ message_end = "message-end",
726
+ stream_end = "stream-end"
727
+ }
728
+ export declare enum MessageRole {
729
+ system = "system",
730
+ user = "user",
731
+ assistant = "assistant",
732
+ tool = "tool"
733
+ }
734
+ export declare enum ChatCompletionToolType {
735
+ function = "function"
736
+ }
737
+ export declare enum ChatCompletionChoiceFinish_reason {
738
+ stop = "stop",
739
+ length = "length",
740
+ tool_calls = "tool_calls",
741
+ content_filter = "content_filter",
742
+ function_call = "function_call"
743
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ /**
3
+ * This file was auto-generated by openapi-typescript.
4
+ * Do not make direct changes to the file.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ChatCompletionChoiceFinish_reason = exports.ChatCompletionToolType = exports.MessageRole = exports.SSEventEvent = exports.ProviderAuthType = exports.Provider = void 0;
8
+ var Provider;
9
+ (function (Provider) {
10
+ Provider["ollama"] = "ollama";
11
+ Provider["groq"] = "groq";
12
+ Provider["openai"] = "openai";
13
+ Provider["cloudflare"] = "cloudflare";
14
+ Provider["cohere"] = "cohere";
15
+ Provider["anthropic"] = "anthropic";
16
+ Provider["deepseek"] = "deepseek";
17
+ })(Provider || (exports.Provider = Provider = {}));
18
+ var ProviderAuthType;
19
+ (function (ProviderAuthType) {
20
+ ProviderAuthType["bearer"] = "bearer";
21
+ ProviderAuthType["xheader"] = "xheader";
22
+ ProviderAuthType["query"] = "query";
23
+ ProviderAuthType["none"] = "none";
24
+ })(ProviderAuthType || (exports.ProviderAuthType = ProviderAuthType = {}));
25
+ var SSEventEvent;
26
+ (function (SSEventEvent) {
27
+ SSEventEvent["message_start"] = "message-start";
28
+ SSEventEvent["stream_start"] = "stream-start";
29
+ SSEventEvent["content_start"] = "content-start";
30
+ SSEventEvent["content_delta"] = "content-delta";
31
+ SSEventEvent["content_end"] = "content-end";
32
+ SSEventEvent["message_end"] = "message-end";
33
+ SSEventEvent["stream_end"] = "stream-end";
34
+ })(SSEventEvent || (exports.SSEventEvent = SSEventEvent = {}));
35
+ var MessageRole;
36
+ (function (MessageRole) {
37
+ MessageRole["system"] = "system";
38
+ MessageRole["user"] = "user";
39
+ MessageRole["assistant"] = "assistant";
40
+ MessageRole["tool"] = "tool";
41
+ })(MessageRole || (exports.MessageRole = MessageRole = {}));
42
+ var ChatCompletionToolType;
43
+ (function (ChatCompletionToolType) {
44
+ ChatCompletionToolType["function"] = "function";
45
+ })(ChatCompletionToolType || (exports.ChatCompletionToolType = ChatCompletionToolType = {}));
46
+ var ChatCompletionChoiceFinish_reason;
47
+ (function (ChatCompletionChoiceFinish_reason) {
48
+ ChatCompletionChoiceFinish_reason["stop"] = "stop";
49
+ ChatCompletionChoiceFinish_reason["length"] = "length";
50
+ ChatCompletionChoiceFinish_reason["tool_calls"] = "tool_calls";
51
+ ChatCompletionChoiceFinish_reason["content_filter"] = "content_filter";
52
+ ChatCompletionChoiceFinish_reason["function_call"] = "function_call";
53
+ })(ChatCompletionChoiceFinish_reason || (exports.ChatCompletionChoiceFinish_reason = ChatCompletionChoiceFinish_reason = {}));
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const client_1 = require("@/client");
4
- const types_1 = require("@/types");
4
+ const generated_1 = require("@/types/generated");
5
5
  const web_1 = require("node:stream/web");
6
6
  const node_util_1 = require("node:util");
7
7
  describe('InferenceGatewayClient', () => {
@@ -26,12 +26,14 @@ describe('InferenceGatewayClient', () => {
26
26
  object: 'model',
27
27
  created: 1686935002,
28
28
  owned_by: 'openai',
29
+ served_by: generated_1.Provider.openai,
29
30
  },
30
31
  {
31
32
  id: 'llama-3.3-70b-versatile',
32
33
  object: 'model',
33
34
  created: 1723651281,
34
35
  owned_by: 'groq',
36
+ served_by: generated_1.Provider.groq,
35
37
  },
36
38
  ],
37
39
  };
@@ -62,7 +64,7 @@ describe('InferenceGatewayClient', () => {
62
64
  ok: true,
63
65
  json: () => Promise.resolve(mockResponse),
64
66
  });
65
- const result = await client.listModels(types_1.Provider.OpenAI);
67
+ const result = await client.listModels(generated_1.Provider.openai);
66
68
  expect(result).toEqual(mockResponse);
67
69
  expect(mockFetch).toHaveBeenCalledWith('http://localhost:8080/v1/models?provider=openai', expect.objectContaining({
68
70
  method: 'GET',
@@ -76,7 +78,7 @@ describe('InferenceGatewayClient', () => {
76
78
  status: 404,
77
79
  json: () => Promise.resolve({ error: errorMessage }),
78
80
  });
79
- await expect(client.listModels(types_1.Provider.OpenAI)).rejects.toThrow(errorMessage);
81
+ await expect(client.listModels(generated_1.Provider.openai)).rejects.toThrow(errorMessage);
80
82
  });
81
83
  });
82
84
  describe('createChatCompletion', () => {
@@ -84,9 +86,10 @@ describe('InferenceGatewayClient', () => {
84
86
  const mockRequest = {
85
87
  model: 'gpt-4o',
86
88
  messages: [
87
- { role: types_1.MessageRole.System, content: 'You are a helpful assistant' },
88
- { role: types_1.MessageRole.User, content: 'Hello' },
89
+ { role: generated_1.MessageRole.system, content: 'You are a helpful assistant' },
90
+ { role: generated_1.MessageRole.user, content: 'Hello' },
89
91
  ],
92
+ stream: false,
90
93
  };
91
94
  const mockResponse = {
92
95
  id: 'chatcmpl-123',
@@ -97,10 +100,10 @@ describe('InferenceGatewayClient', () => {
97
100
  {
98
101
  index: 0,
99
102
  message: {
100
- role: types_1.MessageRole.Assistant,
103
+ role: generated_1.MessageRole.assistant,
101
104
  content: 'Hello! How can I help you today?',
102
105
  },
103
- finish_reason: 'stop',
106
+ finish_reason: generated_1.ChatCompletionChoiceFinish_reason.stop,
104
107
  },
105
108
  ],
106
109
  usage: {
@@ -123,7 +126,8 @@ describe('InferenceGatewayClient', () => {
123
126
  it('should create a chat completion with a specific provider', async () => {
124
127
  const mockRequest = {
125
128
  model: 'claude-3-opus-20240229',
126
- messages: [{ role: types_1.MessageRole.User, content: 'Hello' }],
129
+ messages: [{ role: generated_1.MessageRole.user, content: 'Hello' }],
130
+ stream: false,
127
131
  };
128
132
  const mockResponse = {
129
133
  id: 'chatcmpl-456',
@@ -134,10 +138,10 @@ describe('InferenceGatewayClient', () => {
134
138
  {
135
139
  index: 0,
136
140
  message: {
137
- role: types_1.MessageRole.Assistant,
141
+ role: generated_1.MessageRole.assistant,
138
142
  content: 'Hello! How can I assist you today?',
139
143
  },
140
- finish_reason: 'stop',
144
+ finish_reason: generated_1.ChatCompletionChoiceFinish_reason.stop,
141
145
  },
142
146
  ],
143
147
  usage: {
@@ -150,7 +154,7 @@ describe('InferenceGatewayClient', () => {
150
154
  ok: true,
151
155
  json: () => Promise.resolve(mockResponse),
152
156
  });
153
- const result = await client.createChatCompletion(mockRequest, types_1.Provider.Anthropic);
157
+ const result = await client.createChatCompletion(mockRequest, generated_1.Provider.anthropic);
154
158
  expect(result).toEqual(mockResponse);
155
159
  expect(mockFetch).toHaveBeenCalledWith('http://localhost:8080/v1/chat/completions?provider=anthropic', expect.objectContaining({
156
160
  method: 'POST',
@@ -162,7 +166,8 @@ describe('InferenceGatewayClient', () => {
162
166
  it('should handle streaming chat completions', async () => {
163
167
  const mockRequest = {
164
168
  model: 'gpt-4o',
165
- messages: [{ role: types_1.MessageRole.User, content: 'Hello' }],
169
+ messages: [{ role: generated_1.MessageRole.user, content: 'Hello' }],
170
+ stream: true,
166
171
  };
167
172
  const mockStream = new web_1.TransformStream();
168
173
  const writer = mockStream.writable.getWriter();
@@ -179,7 +184,6 @@ describe('InferenceGatewayClient', () => {
179
184
  onError: jest.fn(),
180
185
  };
181
186
  const streamPromise = client.streamChatCompletion(mockRequest, callbacks);
182
- // Simulate SSE events
183
187
  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' +
184
188
  'data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}\n\n' +
185
189
  'data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}\n\n' +
@@ -205,28 +209,20 @@ describe('InferenceGatewayClient', () => {
205
209
  model: 'gpt-4o',
206
210
  messages: [
207
211
  {
208
- role: types_1.MessageRole.User,
212
+ role: generated_1.MessageRole.user,
209
213
  content: 'What is the weather in San Francisco?',
210
214
  },
211
215
  ],
212
216
  tools: [
213
217
  {
214
- type: 'function',
218
+ type: generated_1.ChatCompletionToolType.function,
215
219
  function: {
216
220
  name: 'get_weather',
217
- parameters: {
218
- type: 'object',
219
- properties: {
220
- location: {
221
- type: 'string',
222
- description: 'The city and state, e.g. San Francisco, CA',
223
- },
224
- },
225
- required: ['location'],
226
- },
221
+ strict: true,
227
222
  },
228
223
  },
229
224
  ],
225
+ stream: true,
230
226
  };
231
227
  const mockStream = new web_1.TransformStream();
232
228
  const writer = mockStream.writable.getWriter();
@@ -254,13 +250,14 @@ describe('InferenceGatewayClient', () => {
254
250
  await streamPromise;
255
251
  expect(callbacks.onOpen).toHaveBeenCalledTimes(1);
256
252
  expect(callbacks.onChunk).toHaveBeenCalledTimes(6);
257
- expect(callbacks.onTool).toHaveBeenCalledTimes(4); // Called for each chunk with tool_calls
253
+ expect(callbacks.onTool).toHaveBeenCalledTimes(4);
258
254
  expect(callbacks.onFinish).toHaveBeenCalledTimes(1);
259
255
  });
260
256
  it('should handle errors in streaming chat completions', async () => {
261
257
  const mockRequest = {
262
258
  model: 'gpt-4o',
263
- messages: [{ role: types_1.MessageRole.User, content: 'Hello' }],
259
+ messages: [{ role: generated_1.MessageRole.user, content: 'Hello' }],
260
+ stream: true,
264
261
  };
265
262
  mockFetch.mockResolvedValueOnce({
266
263
  ok: false,
@@ -281,7 +278,7 @@ describe('InferenceGatewayClient', () => {
281
278
  ok: true,
282
279
  json: () => Promise.resolve(mockResponse),
283
280
  });
284
- const result = await client.proxy(types_1.Provider.OpenAI, 'embeddings', {
281
+ const result = await client.proxy(generated_1.Provider.openai, 'embeddings', {
285
282
  method: 'POST',
286
283
  body: JSON.stringify({
287
284
  model: 'text-embedding-ada-002',
@@ -325,7 +322,6 @@ describe('InferenceGatewayClient', () => {
325
322
  });
326
323
  expect(newClient).toBeInstanceOf(client_1.InferenceGatewayClient);
327
324
  expect(newClient).not.toBe(originalClient);
328
- // We can't directly test private properties, but we can test behavior
329
325
  mockFetch.mockResolvedValueOnce({
330
326
  ok: true,
331
327
  json: () => Promise.resolve({}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inference-gateway/sdk",
3
- "version": "0.3.4",
3
+ "version": "0.4.0-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",
@@ -1,130 +0,0 @@
1
- export declare enum Provider {
2
- Ollama = "ollama",
3
- Groq = "groq",
4
- OpenAI = "openai",
5
- Cloudflare = "cloudflare",
6
- Cohere = "cohere",
7
- Anthropic = "anthropic",
8
- DeepSeek = "deepseek"
9
- }
10
- export declare enum MessageRole {
11
- System = "system",
12
- User = "user",
13
- Assistant = "assistant",
14
- Tool = "tool"
15
- }
16
- export interface Message {
17
- role: MessageRole;
18
- content: string;
19
- reasoning_content?: string;
20
- reasoning?: string;
21
- tool_calls?: ChatCompletionMessageToolCall[];
22
- tool_call_id?: string;
23
- }
24
- export interface Model {
25
- id: string;
26
- object: string;
27
- created: number;
28
- owned_by: string;
29
- }
30
- export interface ListModelsResponse {
31
- object: string;
32
- data: Model[];
33
- }
34
- export interface ChatCompletionMessageToolCallFunction {
35
- name: string;
36
- arguments: string;
37
- }
38
- export interface ChatCompletionMessageToolCall {
39
- id: string;
40
- type: 'function';
41
- function: ChatCompletionMessageToolCallFunction;
42
- }
43
- export interface ChatCompletionMessageToolCallChunk {
44
- index: number;
45
- id?: string;
46
- type?: string;
47
- function?: {
48
- name?: string;
49
- arguments?: string;
50
- };
51
- }
52
- export interface FunctionParameters {
53
- type: string;
54
- properties?: Record<string, unknown>;
55
- required?: string[];
56
- }
57
- export interface FunctionObject {
58
- description?: string;
59
- name: string;
60
- parameters: FunctionParameters;
61
- strict?: boolean;
62
- }
63
- export interface ChatCompletionTool {
64
- type: 'function';
65
- function: FunctionObject;
66
- }
67
- export interface ChatCompletionRequest {
68
- model: string;
69
- messages: Message[];
70
- max_tokens?: number;
71
- stream?: boolean;
72
- stream_options?: ChatCompletionStreamOptions;
73
- tools?: ChatCompletionTool[];
74
- temperature?: number;
75
- top_p?: number;
76
- top_k?: number;
77
- }
78
- export interface ChatCompletionStreamOptions {
79
- include_usage?: boolean;
80
- }
81
- export interface ChatCompletionChoice {
82
- finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call';
83
- index: number;
84
- message: Message;
85
- logprobs?: Record<string, unknown>;
86
- }
87
- export interface CompletionUsage {
88
- prompt_tokens: number;
89
- completion_tokens: number;
90
- total_tokens: number;
91
- }
92
- export interface ChatCompletionResponse {
93
- id: string;
94
- choices: ChatCompletionChoice[];
95
- created: number;
96
- model: string;
97
- object: string;
98
- usage?: CompletionUsage;
99
- }
100
- export interface ChatCompletionStreamChoice {
101
- delta: ChatCompletionStreamResponseDelta;
102
- finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call' | null;
103
- index: number;
104
- logprobs?: Record<string, unknown>;
105
- }
106
- export interface ChatCompletionStreamResponseDelta {
107
- content?: string;
108
- tool_calls?: ChatCompletionMessageToolCallChunk[];
109
- role?: MessageRole;
110
- refusal?: string;
111
- }
112
- export interface ChatCompletionStreamResponse {
113
- id: string;
114
- choices: ChatCompletionStreamChoice[];
115
- created: number;
116
- model: string;
117
- object: string;
118
- usage?: CompletionUsage;
119
- }
120
- export interface ChatCompletionStreamCallbacks {
121
- onOpen?: () => void;
122
- onChunk?: (chunk: ChatCompletionStreamResponse) => void;
123
- onContent?: (content: string) => void;
124
- onTool?: (toolCall: ChatCompletionMessageToolCall) => void;
125
- onFinish?: (response: ChatCompletionStreamResponse) => void;
126
- onError?: (error: Error) => void;
127
- }
128
- export interface Error {
129
- error: string;
130
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MessageRole = exports.Provider = void 0;
4
- var Provider;
5
- (function (Provider) {
6
- Provider["Ollama"] = "ollama";
7
- Provider["Groq"] = "groq";
8
- Provider["OpenAI"] = "openai";
9
- Provider["Cloudflare"] = "cloudflare";
10
- Provider["Cohere"] = "cohere";
11
- Provider["Anthropic"] = "anthropic";
12
- Provider["DeepSeek"] = "deepseek";
13
- })(Provider || (exports.Provider = Provider = {}));
14
- var MessageRole;
15
- (function (MessageRole) {
16
- MessageRole["System"] = "system";
17
- MessageRole["User"] = "user";
18
- MessageRole["Assistant"] = "assistant";
19
- MessageRole["Tool"] = "tool";
20
- })(MessageRole || (exports.MessageRole = MessageRole = {}));