@agentica/core 0.16.4 → 0.16.7
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/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +128 -193
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/call.js +13 -18
- package/lib/orchestrate/call.js.map +1 -1
- package/lib/orchestrate/cancel.js +3 -2
- package/lib/orchestrate/cancel.js.map +1 -1
- package/lib/orchestrate/execute.js +0 -7
- package/lib/orchestrate/execute.js.map +1 -1
- package/lib/orchestrate/internal/cancelFunction.js +13 -24
- package/lib/orchestrate/internal/cancelFunction.js.map +1 -1
- package/lib/utils/ChatGptCompletionMessageUtil.js +316 -368
- package/lib/utils/ChatGptCompletionMessageUtil.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/orchestrate/call.ts +15 -22
- package/src/orchestrate/cancel.ts +3 -2
- package/src/orchestrate/execute.ts +0 -7
- package/src/orchestrate/internal/cancelFunction.ts +4 -4
- package/src/utils/ChatGptCompletionMessageUtil.ts +7 -5
|
@@ -32,386 +32,334 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
35
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
39
|
exports.ChatGptCompletionMessageUtil = void 0;
|
|
37
|
-
const
|
|
38
|
-
const typia_1 = require("typia");
|
|
40
|
+
const __typia_transform__validateReport = __importStar(require("typia/lib/internal/_validateReport.js"));
|
|
41
|
+
const typia_1 = __importDefault(require("typia"));
|
|
39
42
|
const ByteArrayUtil_1 = require("./ByteArrayUtil");
|
|
40
43
|
const ChatGptTokenUsageAggregator_1 = require("./ChatGptTokenUsageAggregator");
|
|
41
44
|
function transformCompletionChunk(source) {
|
|
42
45
|
const str = source instanceof Uint8Array ? ByteArrayUtil_1.ByteArrayUtil.toUtf8(source) : source;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
method: "json.assertParse",
|
|
330
|
-
path: _path + ".logprob",
|
|
331
|
-
expected: "number",
|
|
332
|
-
value: input.logprob
|
|
333
|
-
}, _errorFactory)); const _ao9 = (input, _path, _exceptionable = true) => ("number" === typeof input.completion_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
334
|
-
method: "json.assertParse",
|
|
335
|
-
path: _path + ".completion_tokens",
|
|
336
|
-
expected: "number",
|
|
337
|
-
value: input.completion_tokens
|
|
338
|
-
}, _errorFactory)) && ("number" === typeof input.prompt_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
339
|
-
method: "json.assertParse",
|
|
340
|
-
path: _path + ".prompt_tokens",
|
|
341
|
-
expected: "number",
|
|
342
|
-
value: input.prompt_tokens
|
|
343
|
-
}, _errorFactory)) && ("number" === typeof input.total_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
344
|
-
method: "json.assertParse",
|
|
345
|
-
path: _path + ".total_tokens",
|
|
346
|
-
expected: "number",
|
|
347
|
-
value: input.total_tokens
|
|
348
|
-
}, _errorFactory)) && (undefined === input.completion_tokens_details || ("object" === typeof input.completion_tokens_details && null !== input.completion_tokens_details && false === Array.isArray(input.completion_tokens_details) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
349
|
-
method: "json.assertParse",
|
|
350
|
-
path: _path + ".completion_tokens_details",
|
|
351
|
-
expected: "(CompletionUsage.CompletionTokensDetails | undefined)",
|
|
352
|
-
value: input.completion_tokens_details
|
|
353
|
-
}, _errorFactory)) && _ao10(input.completion_tokens_details, _path + ".completion_tokens_details", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
354
|
-
method: "json.assertParse",
|
|
355
|
-
path: _path + ".completion_tokens_details",
|
|
356
|
-
expected: "(CompletionUsage.CompletionTokensDetails | undefined)",
|
|
357
|
-
value: input.completion_tokens_details
|
|
358
|
-
}, _errorFactory)) && (undefined === input.prompt_tokens_details || ("object" === typeof input.prompt_tokens_details && null !== input.prompt_tokens_details && false === Array.isArray(input.prompt_tokens_details) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
359
|
-
method: "json.assertParse",
|
|
360
|
-
path: _path + ".prompt_tokens_details",
|
|
361
|
-
expected: "(CompletionUsage.PromptTokensDetails | undefined)",
|
|
362
|
-
value: input.prompt_tokens_details
|
|
363
|
-
}, _errorFactory)) && _ao11(input.prompt_tokens_details, _path + ".prompt_tokens_details", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
364
|
-
method: "json.assertParse",
|
|
365
|
-
path: _path + ".prompt_tokens_details",
|
|
366
|
-
expected: "(CompletionUsage.PromptTokensDetails | undefined)",
|
|
367
|
-
value: input.prompt_tokens_details
|
|
368
|
-
}, _errorFactory)); const _ao10 = (input, _path, _exceptionable = true) => (undefined === input.accepted_prediction_tokens || "number" === typeof input.accepted_prediction_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
369
|
-
method: "json.assertParse",
|
|
370
|
-
path: _path + ".accepted_prediction_tokens",
|
|
371
|
-
expected: "(number | undefined)",
|
|
372
|
-
value: input.accepted_prediction_tokens
|
|
373
|
-
}, _errorFactory)) && (undefined === input.audio_tokens || "number" === typeof input.audio_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
374
|
-
method: "json.assertParse",
|
|
375
|
-
path: _path + ".audio_tokens",
|
|
376
|
-
expected: "(number | undefined)",
|
|
377
|
-
value: input.audio_tokens
|
|
378
|
-
}, _errorFactory)) && (undefined === input.reasoning_tokens || "number" === typeof input.reasoning_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
379
|
-
method: "json.assertParse",
|
|
380
|
-
path: _path + ".reasoning_tokens",
|
|
381
|
-
expected: "(number | undefined)",
|
|
382
|
-
value: input.reasoning_tokens
|
|
383
|
-
}, _errorFactory)) && (undefined === input.rejected_prediction_tokens || "number" === typeof input.rejected_prediction_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
384
|
-
method: "json.assertParse",
|
|
385
|
-
path: _path + ".rejected_prediction_tokens",
|
|
386
|
-
expected: "(number | undefined)",
|
|
387
|
-
value: input.rejected_prediction_tokens
|
|
388
|
-
}, _errorFactory)); const _ao11 = (input, _path, _exceptionable = true) => (undefined === input.audio_tokens || "number" === typeof input.audio_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
389
|
-
method: "json.assertParse",
|
|
390
|
-
path: _path + ".audio_tokens",
|
|
391
|
-
expected: "(number | undefined)",
|
|
392
|
-
value: input.audio_tokens
|
|
393
|
-
}, _errorFactory)) && (undefined === input.cached_tokens || "number" === typeof input.cached_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
394
|
-
method: "json.assertParse",
|
|
395
|
-
path: _path + ".cached_tokens",
|
|
396
|
-
expected: "(number | undefined)",
|
|
397
|
-
value: input.cached_tokens
|
|
398
|
-
}, _errorFactory)); const __is = input => "object" === typeof input && null !== input && _io0(input); let _errorFactory; const __assert = (input, errorFactory) => {
|
|
46
|
+
const result = JSON.parse(str);
|
|
47
|
+
const valid = (() => { const _io0 = input => "string" === typeof input.id && (Array.isArray(input.choices) && input.choices.every(elem => "object" === typeof elem && null !== elem && _io1(elem))) && "number" === typeof input.created && "string" === typeof input.model && "chat.completion.chunk" === input.object && (null === input.service_tier || undefined === input.service_tier || "scale" === input.service_tier || "default" === input.service_tier) && (undefined === input.system_fingerprint || "string" === typeof input.system_fingerprint) && (null === input.usage || undefined === input.usage || "object" === typeof input.usage && null !== input.usage && _io9(input.usage)); const _io1 = input => "object" === typeof input.delta && null !== input.delta && false === Array.isArray(input.delta) && _io2(input.delta) && (null === input.finish_reason || "function_call" === input.finish_reason || "stop" === input.finish_reason || "length" === input.finish_reason || "tool_calls" === input.finish_reason || "content_filter" === input.finish_reason) && "number" === typeof input.index && (null === input.logprobs || undefined === input.logprobs || "object" === typeof input.logprobs && null !== input.logprobs && _io6(input.logprobs)); const _io2 = input => (null === input.content || undefined === input.content || "string" === typeof input.content) && (undefined === input.function_call || "object" === typeof input.function_call && null !== input.function_call && false === Array.isArray(input.function_call) && _io3(input.function_call)) && (null === input.refusal || undefined === input.refusal || "string" === typeof input.refusal) && (undefined === input.role || "assistant" === input.role || "user" === input.role || "developer" === input.role || "system" === input.role || "tool" === input.role) && (undefined === input.tool_calls || Array.isArray(input.tool_calls) && input.tool_calls.every(elem => "object" === typeof elem && null !== elem && _io4(elem))); const _io3 = input => (undefined === input.arguments || "string" === typeof input.arguments) && (undefined === input.name || "string" === typeof input.name); const _io4 = input => "number" === typeof input.index && (undefined === input.id || "string" === typeof input.id) && (undefined === input["function"] || "object" === typeof input["function"] && null !== input["function"] && false === Array.isArray(input["function"]) && _io5(input["function"])) && (undefined === input.type || "function" === input.type); const _io5 = input => (undefined === input.arguments || "string" === typeof input.arguments) && (undefined === input.name || "string" === typeof input.name); const _io6 = input => (null === input.content || Array.isArray(input.content) && input.content.every(elem => "object" === typeof elem && null !== elem && _io7(elem))) && (null === input.refusal || Array.isArray(input.refusal) && input.refusal.every(elem => "object" === typeof elem && null !== elem && _io7(elem))); const _io7 = input => "string" === typeof input.token && (null === input.bytes || Array.isArray(input.bytes) && input.bytes.every(elem => "number" === typeof elem)) && "number" === typeof input.logprob && (Array.isArray(input.top_logprobs) && input.top_logprobs.every(elem => "object" === typeof elem && null !== elem && _io8(elem))); const _io8 = input => "string" === typeof input.token && (null === input.bytes || Array.isArray(input.bytes) && input.bytes.every(elem => "number" === typeof elem)) && "number" === typeof input.logprob; const _io9 = input => "number" === typeof input.completion_tokens && "number" === typeof input.prompt_tokens && "number" === typeof input.total_tokens && (undefined === input.completion_tokens_details || "object" === typeof input.completion_tokens_details && null !== input.completion_tokens_details && false === Array.isArray(input.completion_tokens_details) && _io10(input.completion_tokens_details)) && (undefined === input.prompt_tokens_details || "object" === typeof input.prompt_tokens_details && null !== input.prompt_tokens_details && false === Array.isArray(input.prompt_tokens_details) && _io11(input.prompt_tokens_details)); const _io10 = input => (undefined === input.accepted_prediction_tokens || "number" === typeof input.accepted_prediction_tokens) && (undefined === input.audio_tokens || "number" === typeof input.audio_tokens) && (undefined === input.reasoning_tokens || "number" === typeof input.reasoning_tokens) && (undefined === input.rejected_prediction_tokens || "number" === typeof input.rejected_prediction_tokens); const _io11 = input => (undefined === input.audio_tokens || "number" === typeof input.audio_tokens) && (undefined === input.cached_tokens || "number" === typeof input.cached_tokens); const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.id || _report(_exceptionable, {
|
|
48
|
+
path: _path + ".id",
|
|
49
|
+
expected: "string",
|
|
50
|
+
value: input.id
|
|
51
|
+
}), (Array.isArray(input.choices) || _report(_exceptionable, {
|
|
52
|
+
path: _path + ".choices",
|
|
53
|
+
expected: "Array<ChatCompletionChunk.Choice>",
|
|
54
|
+
value: input.choices
|
|
55
|
+
})) && input.choices.map((elem, _index8) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
|
|
56
|
+
path: _path + ".choices[" + _index8 + "]",
|
|
57
|
+
expected: "ChatCompletionChunk.Choice",
|
|
58
|
+
value: elem
|
|
59
|
+
})) && _vo1(elem, _path + ".choices[" + _index8 + "]", true && _exceptionable) || _report(_exceptionable, {
|
|
60
|
+
path: _path + ".choices[" + _index8 + "]",
|
|
61
|
+
expected: "ChatCompletionChunk.Choice",
|
|
62
|
+
value: elem
|
|
63
|
+
})).every(flag => flag) || _report(_exceptionable, {
|
|
64
|
+
path: _path + ".choices",
|
|
65
|
+
expected: "Array<ChatCompletionChunk.Choice>",
|
|
66
|
+
value: input.choices
|
|
67
|
+
}), "number" === typeof input.created || _report(_exceptionable, {
|
|
68
|
+
path: _path + ".created",
|
|
69
|
+
expected: "number",
|
|
70
|
+
value: input.created
|
|
71
|
+
}), "string" === typeof input.model || _report(_exceptionable, {
|
|
72
|
+
path: _path + ".model",
|
|
73
|
+
expected: "string",
|
|
74
|
+
value: input.model
|
|
75
|
+
}), "chat.completion.chunk" === input.object || _report(_exceptionable, {
|
|
76
|
+
path: _path + ".object",
|
|
77
|
+
expected: "\"chat.completion.chunk\"",
|
|
78
|
+
value: input.object
|
|
79
|
+
}), null === input.service_tier || undefined === input.service_tier || "scale" === input.service_tier || "default" === input.service_tier || _report(_exceptionable, {
|
|
80
|
+
path: _path + ".service_tier",
|
|
81
|
+
expected: "(\"default\" | \"scale\" | null | undefined)",
|
|
82
|
+
value: input.service_tier
|
|
83
|
+
}), undefined === input.system_fingerprint || "string" === typeof input.system_fingerprint || _report(_exceptionable, {
|
|
84
|
+
path: _path + ".system_fingerprint",
|
|
85
|
+
expected: "(string | undefined)",
|
|
86
|
+
value: input.system_fingerprint
|
|
87
|
+
}), null === input.usage || undefined === input.usage || ("object" === typeof input.usage && null !== input.usage || _report(_exceptionable, {
|
|
88
|
+
path: _path + ".usage",
|
|
89
|
+
expected: "(CompletionUsage | null | undefined)",
|
|
90
|
+
value: input.usage
|
|
91
|
+
})) && _vo9(input.usage, _path + ".usage", true && _exceptionable) || _report(_exceptionable, {
|
|
92
|
+
path: _path + ".usage",
|
|
93
|
+
expected: "(CompletionUsage | null | undefined)",
|
|
94
|
+
value: input.usage
|
|
95
|
+
})].every(flag => flag); const _vo1 = (input, _path, _exceptionable = true) => [("object" === typeof input.delta && null !== input.delta && false === Array.isArray(input.delta) || _report(_exceptionable, {
|
|
96
|
+
path: _path + ".delta",
|
|
97
|
+
expected: "ChatCompletionChunk.Choice.Delta",
|
|
98
|
+
value: input.delta
|
|
99
|
+
})) && _vo2(input.delta, _path + ".delta", true && _exceptionable) || _report(_exceptionable, {
|
|
100
|
+
path: _path + ".delta",
|
|
101
|
+
expected: "ChatCompletionChunk.Choice.Delta",
|
|
102
|
+
value: input.delta
|
|
103
|
+
}), null === input.finish_reason || "function_call" === input.finish_reason || "stop" === input.finish_reason || "length" === input.finish_reason || "tool_calls" === input.finish_reason || "content_filter" === input.finish_reason || _report(_exceptionable, {
|
|
104
|
+
path: _path + ".finish_reason",
|
|
105
|
+
expected: "(\"content_filter\" | \"function_call\" | \"length\" | \"stop\" | \"tool_calls\" | null)",
|
|
106
|
+
value: input.finish_reason
|
|
107
|
+
}), "number" === typeof input.index || _report(_exceptionable, {
|
|
108
|
+
path: _path + ".index",
|
|
109
|
+
expected: "number",
|
|
110
|
+
value: input.index
|
|
111
|
+
}), null === input.logprobs || undefined === input.logprobs || ("object" === typeof input.logprobs && null !== input.logprobs || _report(_exceptionable, {
|
|
112
|
+
path: _path + ".logprobs",
|
|
113
|
+
expected: "(ChatCompletionChunk.Choice.Logprobs | null | undefined)",
|
|
114
|
+
value: input.logprobs
|
|
115
|
+
})) && _vo6(input.logprobs, _path + ".logprobs", true && _exceptionable) || _report(_exceptionable, {
|
|
116
|
+
path: _path + ".logprobs",
|
|
117
|
+
expected: "(ChatCompletionChunk.Choice.Logprobs | null | undefined)",
|
|
118
|
+
value: input.logprobs
|
|
119
|
+
})].every(flag => flag); const _vo2 = (input, _path, _exceptionable = true) => [null === input.content || undefined === input.content || "string" === typeof input.content || _report(_exceptionable, {
|
|
120
|
+
path: _path + ".content",
|
|
121
|
+
expected: "(null | string | undefined)",
|
|
122
|
+
value: input.content
|
|
123
|
+
}), undefined === input.function_call || ("object" === typeof input.function_call && null !== input.function_call && false === Array.isArray(input.function_call) || _report(_exceptionable, {
|
|
124
|
+
path: _path + ".function_call",
|
|
125
|
+
expected: "(ChatCompletionChunk.Choice.Delta.FunctionCall | undefined)",
|
|
126
|
+
value: input.function_call
|
|
127
|
+
})) && _vo3(input.function_call, _path + ".function_call", true && _exceptionable) || _report(_exceptionable, {
|
|
128
|
+
path: _path + ".function_call",
|
|
129
|
+
expected: "(ChatCompletionChunk.Choice.Delta.FunctionCall | undefined)",
|
|
130
|
+
value: input.function_call
|
|
131
|
+
}), null === input.refusal || undefined === input.refusal || "string" === typeof input.refusal || _report(_exceptionable, {
|
|
132
|
+
path: _path + ".refusal",
|
|
133
|
+
expected: "(null | string | undefined)",
|
|
134
|
+
value: input.refusal
|
|
135
|
+
}), undefined === input.role || "assistant" === input.role || "user" === input.role || "developer" === input.role || "system" === input.role || "tool" === input.role || _report(_exceptionable, {
|
|
136
|
+
path: _path + ".role",
|
|
137
|
+
expected: "(\"assistant\" | \"developer\" | \"system\" | \"tool\" | \"user\" | undefined)",
|
|
138
|
+
value: input.role
|
|
139
|
+
}), undefined === input.tool_calls || (Array.isArray(input.tool_calls) || _report(_exceptionable, {
|
|
140
|
+
path: _path + ".tool_calls",
|
|
141
|
+
expected: "(Array<ChatCompletionChunk.Choice.Delta.ToolCall> | undefined)",
|
|
142
|
+
value: input.tool_calls
|
|
143
|
+
})) && input.tool_calls.map((elem, _index9) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
|
|
144
|
+
path: _path + ".tool_calls[" + _index9 + "]",
|
|
145
|
+
expected: "ChatCompletionChunk.Choice.Delta.ToolCall",
|
|
146
|
+
value: elem
|
|
147
|
+
})) && _vo4(elem, _path + ".tool_calls[" + _index9 + "]", true && _exceptionable) || _report(_exceptionable, {
|
|
148
|
+
path: _path + ".tool_calls[" + _index9 + "]",
|
|
149
|
+
expected: "ChatCompletionChunk.Choice.Delta.ToolCall",
|
|
150
|
+
value: elem
|
|
151
|
+
})).every(flag => flag) || _report(_exceptionable, {
|
|
152
|
+
path: _path + ".tool_calls",
|
|
153
|
+
expected: "(Array<ChatCompletionChunk.Choice.Delta.ToolCall> | undefined)",
|
|
154
|
+
value: input.tool_calls
|
|
155
|
+
})].every(flag => flag); const _vo3 = (input, _path, _exceptionable = true) => [undefined === input.arguments || "string" === typeof input.arguments || _report(_exceptionable, {
|
|
156
|
+
path: _path + ".arguments",
|
|
157
|
+
expected: "(string | undefined)",
|
|
158
|
+
value: input.arguments
|
|
159
|
+
}), undefined === input.name || "string" === typeof input.name || _report(_exceptionable, {
|
|
160
|
+
path: _path + ".name",
|
|
161
|
+
expected: "(string | undefined)",
|
|
162
|
+
value: input.name
|
|
163
|
+
})].every(flag => flag); const _vo4 = (input, _path, _exceptionable = true) => ["number" === typeof input.index || _report(_exceptionable, {
|
|
164
|
+
path: _path + ".index",
|
|
165
|
+
expected: "number",
|
|
166
|
+
value: input.index
|
|
167
|
+
}), undefined === input.id || "string" === typeof input.id || _report(_exceptionable, {
|
|
168
|
+
path: _path + ".id",
|
|
169
|
+
expected: "(string | undefined)",
|
|
170
|
+
value: input.id
|
|
171
|
+
}), undefined === input["function"] || ("object" === typeof input["function"] && null !== input["function"] && false === Array.isArray(input["function"]) || _report(_exceptionable, {
|
|
172
|
+
path: _path + "[\"function\"]",
|
|
173
|
+
expected: "(ChatCompletionChunk.Choice.Delta.ToolCall.Function | undefined)",
|
|
174
|
+
value: input["function"]
|
|
175
|
+
})) && _vo5(input["function"], _path + "[\"function\"]", true && _exceptionable) || _report(_exceptionable, {
|
|
176
|
+
path: _path + "[\"function\"]",
|
|
177
|
+
expected: "(ChatCompletionChunk.Choice.Delta.ToolCall.Function | undefined)",
|
|
178
|
+
value: input["function"]
|
|
179
|
+
}), undefined === input.type || "function" === input.type || _report(_exceptionable, {
|
|
180
|
+
path: _path + ".type",
|
|
181
|
+
expected: "(\"function\" | undefined)",
|
|
182
|
+
value: input.type
|
|
183
|
+
})].every(flag => flag); const _vo5 = (input, _path, _exceptionable = true) => [undefined === input.arguments || "string" === typeof input.arguments || _report(_exceptionable, {
|
|
184
|
+
path: _path + ".arguments",
|
|
185
|
+
expected: "(string | undefined)",
|
|
186
|
+
value: input.arguments
|
|
187
|
+
}), undefined === input.name || "string" === typeof input.name || _report(_exceptionable, {
|
|
188
|
+
path: _path + ".name",
|
|
189
|
+
expected: "(string | undefined)",
|
|
190
|
+
value: input.name
|
|
191
|
+
})].every(flag => flag); const _vo6 = (input, _path, _exceptionable = true) => [null === input.content || (Array.isArray(input.content) || _report(_exceptionable, {
|
|
192
|
+
path: _path + ".content",
|
|
193
|
+
expected: "(Array<ChatCompletionTokenLogprob> | null)",
|
|
194
|
+
value: input.content
|
|
195
|
+
})) && input.content.map((elem, _index10) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
|
|
196
|
+
path: _path + ".content[" + _index10 + "]",
|
|
197
|
+
expected: "ChatCompletionTokenLogprob",
|
|
198
|
+
value: elem
|
|
199
|
+
})) && _vo7(elem, _path + ".content[" + _index10 + "]", true && _exceptionable) || _report(_exceptionable, {
|
|
200
|
+
path: _path + ".content[" + _index10 + "]",
|
|
201
|
+
expected: "ChatCompletionTokenLogprob",
|
|
202
|
+
value: elem
|
|
203
|
+
})).every(flag => flag) || _report(_exceptionable, {
|
|
204
|
+
path: _path + ".content",
|
|
205
|
+
expected: "(Array<ChatCompletionTokenLogprob> | null)",
|
|
206
|
+
value: input.content
|
|
207
|
+
}), null === input.refusal || (Array.isArray(input.refusal) || _report(_exceptionable, {
|
|
208
|
+
path: _path + ".refusal",
|
|
209
|
+
expected: "(Array<ChatCompletionTokenLogprob> | null)",
|
|
210
|
+
value: input.refusal
|
|
211
|
+
})) && input.refusal.map((elem, _index11) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
|
|
212
|
+
path: _path + ".refusal[" + _index11 + "]",
|
|
213
|
+
expected: "ChatCompletionTokenLogprob",
|
|
214
|
+
value: elem
|
|
215
|
+
})) && _vo7(elem, _path + ".refusal[" + _index11 + "]", true && _exceptionable) || _report(_exceptionable, {
|
|
216
|
+
path: _path + ".refusal[" + _index11 + "]",
|
|
217
|
+
expected: "ChatCompletionTokenLogprob",
|
|
218
|
+
value: elem
|
|
219
|
+
})).every(flag => flag) || _report(_exceptionable, {
|
|
220
|
+
path: _path + ".refusal",
|
|
221
|
+
expected: "(Array<ChatCompletionTokenLogprob> | null)",
|
|
222
|
+
value: input.refusal
|
|
223
|
+
})].every(flag => flag); const _vo7 = (input, _path, _exceptionable = true) => ["string" === typeof input.token || _report(_exceptionable, {
|
|
224
|
+
path: _path + ".token",
|
|
225
|
+
expected: "string",
|
|
226
|
+
value: input.token
|
|
227
|
+
}), null === input.bytes || (Array.isArray(input.bytes) || _report(_exceptionable, {
|
|
228
|
+
path: _path + ".bytes",
|
|
229
|
+
expected: "(Array<number> | null)",
|
|
230
|
+
value: input.bytes
|
|
231
|
+
})) && input.bytes.map((elem, _index12) => "number" === typeof elem || _report(_exceptionable, {
|
|
232
|
+
path: _path + ".bytes[" + _index12 + "]",
|
|
233
|
+
expected: "number",
|
|
234
|
+
value: elem
|
|
235
|
+
})).every(flag => flag) || _report(_exceptionable, {
|
|
236
|
+
path: _path + ".bytes",
|
|
237
|
+
expected: "(Array<number> | null)",
|
|
238
|
+
value: input.bytes
|
|
239
|
+
}), "number" === typeof input.logprob || _report(_exceptionable, {
|
|
240
|
+
path: _path + ".logprob",
|
|
241
|
+
expected: "number",
|
|
242
|
+
value: input.logprob
|
|
243
|
+
}), (Array.isArray(input.top_logprobs) || _report(_exceptionable, {
|
|
244
|
+
path: _path + ".top_logprobs",
|
|
245
|
+
expected: "Array<ChatCompletionTokenLogprob.TopLogprob>",
|
|
246
|
+
value: input.top_logprobs
|
|
247
|
+
})) && input.top_logprobs.map((elem, _index13) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
|
|
248
|
+
path: _path + ".top_logprobs[" + _index13 + "]",
|
|
249
|
+
expected: "ChatCompletionTokenLogprob.TopLogprob",
|
|
250
|
+
value: elem
|
|
251
|
+
})) && _vo8(elem, _path + ".top_logprobs[" + _index13 + "]", true && _exceptionable) || _report(_exceptionable, {
|
|
252
|
+
path: _path + ".top_logprobs[" + _index13 + "]",
|
|
253
|
+
expected: "ChatCompletionTokenLogprob.TopLogprob",
|
|
254
|
+
value: elem
|
|
255
|
+
})).every(flag => flag) || _report(_exceptionable, {
|
|
256
|
+
path: _path + ".top_logprobs",
|
|
257
|
+
expected: "Array<ChatCompletionTokenLogprob.TopLogprob>",
|
|
258
|
+
value: input.top_logprobs
|
|
259
|
+
})].every(flag => flag); const _vo8 = (input, _path, _exceptionable = true) => ["string" === typeof input.token || _report(_exceptionable, {
|
|
260
|
+
path: _path + ".token",
|
|
261
|
+
expected: "string",
|
|
262
|
+
value: input.token
|
|
263
|
+
}), null === input.bytes || (Array.isArray(input.bytes) || _report(_exceptionable, {
|
|
264
|
+
path: _path + ".bytes",
|
|
265
|
+
expected: "(Array<number> | null)",
|
|
266
|
+
value: input.bytes
|
|
267
|
+
})) && input.bytes.map((elem, _index14) => "number" === typeof elem || _report(_exceptionable, {
|
|
268
|
+
path: _path + ".bytes[" + _index14 + "]",
|
|
269
|
+
expected: "number",
|
|
270
|
+
value: elem
|
|
271
|
+
})).every(flag => flag) || _report(_exceptionable, {
|
|
272
|
+
path: _path + ".bytes",
|
|
273
|
+
expected: "(Array<number> | null)",
|
|
274
|
+
value: input.bytes
|
|
275
|
+
}), "number" === typeof input.logprob || _report(_exceptionable, {
|
|
276
|
+
path: _path + ".logprob",
|
|
277
|
+
expected: "number",
|
|
278
|
+
value: input.logprob
|
|
279
|
+
})].every(flag => flag); const _vo9 = (input, _path, _exceptionable = true) => ["number" === typeof input.completion_tokens || _report(_exceptionable, {
|
|
280
|
+
path: _path + ".completion_tokens",
|
|
281
|
+
expected: "number",
|
|
282
|
+
value: input.completion_tokens
|
|
283
|
+
}), "number" === typeof input.prompt_tokens || _report(_exceptionable, {
|
|
284
|
+
path: _path + ".prompt_tokens",
|
|
285
|
+
expected: "number",
|
|
286
|
+
value: input.prompt_tokens
|
|
287
|
+
}), "number" === typeof input.total_tokens || _report(_exceptionable, {
|
|
288
|
+
path: _path + ".total_tokens",
|
|
289
|
+
expected: "number",
|
|
290
|
+
value: input.total_tokens
|
|
291
|
+
}), undefined === input.completion_tokens_details || ("object" === typeof input.completion_tokens_details && null !== input.completion_tokens_details && false === Array.isArray(input.completion_tokens_details) || _report(_exceptionable, {
|
|
292
|
+
path: _path + ".completion_tokens_details",
|
|
293
|
+
expected: "(CompletionUsage.CompletionTokensDetails | undefined)",
|
|
294
|
+
value: input.completion_tokens_details
|
|
295
|
+
})) && _vo10(input.completion_tokens_details, _path + ".completion_tokens_details", true && _exceptionable) || _report(_exceptionable, {
|
|
296
|
+
path: _path + ".completion_tokens_details",
|
|
297
|
+
expected: "(CompletionUsage.CompletionTokensDetails | undefined)",
|
|
298
|
+
value: input.completion_tokens_details
|
|
299
|
+
}), undefined === input.prompt_tokens_details || ("object" === typeof input.prompt_tokens_details && null !== input.prompt_tokens_details && false === Array.isArray(input.prompt_tokens_details) || _report(_exceptionable, {
|
|
300
|
+
path: _path + ".prompt_tokens_details",
|
|
301
|
+
expected: "(CompletionUsage.PromptTokensDetails | undefined)",
|
|
302
|
+
value: input.prompt_tokens_details
|
|
303
|
+
})) && _vo11(input.prompt_tokens_details, _path + ".prompt_tokens_details", true && _exceptionable) || _report(_exceptionable, {
|
|
304
|
+
path: _path + ".prompt_tokens_details",
|
|
305
|
+
expected: "(CompletionUsage.PromptTokensDetails | undefined)",
|
|
306
|
+
value: input.prompt_tokens_details
|
|
307
|
+
})].every(flag => flag); const _vo10 = (input, _path, _exceptionable = true) => [undefined === input.accepted_prediction_tokens || "number" === typeof input.accepted_prediction_tokens || _report(_exceptionable, {
|
|
308
|
+
path: _path + ".accepted_prediction_tokens",
|
|
309
|
+
expected: "(number | undefined)",
|
|
310
|
+
value: input.accepted_prediction_tokens
|
|
311
|
+
}), undefined === input.audio_tokens || "number" === typeof input.audio_tokens || _report(_exceptionable, {
|
|
312
|
+
path: _path + ".audio_tokens",
|
|
313
|
+
expected: "(number | undefined)",
|
|
314
|
+
value: input.audio_tokens
|
|
315
|
+
}), undefined === input.reasoning_tokens || "number" === typeof input.reasoning_tokens || _report(_exceptionable, {
|
|
316
|
+
path: _path + ".reasoning_tokens",
|
|
317
|
+
expected: "(number | undefined)",
|
|
318
|
+
value: input.reasoning_tokens
|
|
319
|
+
}), undefined === input.rejected_prediction_tokens || "number" === typeof input.rejected_prediction_tokens || _report(_exceptionable, {
|
|
320
|
+
path: _path + ".rejected_prediction_tokens",
|
|
321
|
+
expected: "(number | undefined)",
|
|
322
|
+
value: input.rejected_prediction_tokens
|
|
323
|
+
})].every(flag => flag); const _vo11 = (input, _path, _exceptionable = true) => [undefined === input.audio_tokens || "number" === typeof input.audio_tokens || _report(_exceptionable, {
|
|
324
|
+
path: _path + ".audio_tokens",
|
|
325
|
+
expected: "(number | undefined)",
|
|
326
|
+
value: input.audio_tokens
|
|
327
|
+
}), undefined === input.cached_tokens || "number" === typeof input.cached_tokens || _report(_exceptionable, {
|
|
328
|
+
path: _path + ".cached_tokens",
|
|
329
|
+
expected: "(number | undefined)",
|
|
330
|
+
value: input.cached_tokens
|
|
331
|
+
})].every(flag => flag); const __is = input => "object" === typeof input && null !== input && _io0(input); let errors; let _report; return input => {
|
|
399
332
|
if (false === __is(input)) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
333
|
+
errors = [];
|
|
334
|
+
_report = __typia_transform__validateReport._validateReport(errors);
|
|
335
|
+
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
|
|
403
336
|
path: _path + "",
|
|
404
|
-
expected: "ChatCompletionChunk
|
|
337
|
+
expected: "ChatCompletionChunk",
|
|
405
338
|
value: input
|
|
406
|
-
}
|
|
407
|
-
method: "json.assertParse",
|
|
339
|
+
})) && _vo0(input, _path + "", true) || _report(true, {
|
|
408
340
|
path: _path + "",
|
|
409
|
-
expected: "ChatCompletionChunk
|
|
341
|
+
expected: "ChatCompletionChunk",
|
|
410
342
|
value: input
|
|
411
|
-
}
|
|
343
|
+
}))(input, "$input", true);
|
|
344
|
+
const success = 0 === errors.length;
|
|
345
|
+
return success ? {
|
|
346
|
+
success,
|
|
347
|
+
data: input
|
|
348
|
+
} : {
|
|
349
|
+
success,
|
|
350
|
+
errors,
|
|
351
|
+
data: input
|
|
352
|
+
};
|
|
412
353
|
}
|
|
413
|
-
return
|
|
414
|
-
|
|
354
|
+
return {
|
|
355
|
+
success: true,
|
|
356
|
+
data: input
|
|
357
|
+
};
|
|
358
|
+
}; })()(result);
|
|
359
|
+
if (valid.success === false) {
|
|
360
|
+
console.error("Invalid ChatCompletionChunk", valid.errors);
|
|
361
|
+
}
|
|
362
|
+
return result;
|
|
415
363
|
}
|
|
416
364
|
function accumulate(origin, chunk) {
|
|
417
365
|
const choices = origin.choices;
|