@agentica/core 0.12.20 → 0.13.0
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/README.md +50 -47
- package/lib/Agentica.d.ts +9 -9
- package/lib/Agentica.js +23 -16
- package/lib/Agentica.js.map +1 -1
- package/lib/chatgpt/ChatGptAgent.d.ts +7 -7
- package/lib/chatgpt/ChatGptAgent.js +17 -12
- package/lib/chatgpt/ChatGptAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptCallFunctionAgent.d.ts +7 -6
- package/lib/chatgpt/ChatGptCallFunctionAgent.js +121 -81
- package/lib/chatgpt/ChatGptCallFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptCancelFunctionAgent.d.ts +9 -7
- package/lib/chatgpt/ChatGptCancelFunctionAgent.js +177 -145
- package/lib/chatgpt/ChatGptCancelFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptCompletionMessageUtil.d.ts +13 -8
- package/lib/chatgpt/ChatGptCompletionMessageUtil.js +499 -489
- package/lib/chatgpt/ChatGptCompletionMessageUtil.js.map +1 -1
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.d.ts +7 -6
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.js +33 -32
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptHistoryDecoder.d.ts +7 -6
- package/lib/chatgpt/ChatGptHistoryDecoder.js +60 -56
- package/lib/chatgpt/ChatGptHistoryDecoder.js.map +1 -1
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.d.ts +7 -6
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.js +121 -116
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptSelectFunctionAgent.d.ts +20 -5
- package/lib/chatgpt/ChatGptSelectFunctionAgent.js +183 -150
- package/lib/chatgpt/ChatGptSelectFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptUsageAggregator.d.ts +9 -6
- package/lib/chatgpt/ChatGptUsageAggregator.js +46 -41
- package/lib/chatgpt/ChatGptUsageAggregator.js.map +1 -1
- package/lib/context/AgenticaCancelPrompt.d.ts +3 -3
- package/lib/context/AgenticaCancelPrompt.js +1 -1
- package/lib/context/AgenticaCancelPrompt.js.map +1 -1
- package/lib/context/AgenticaClassOperation.d.ts +1 -1
- package/lib/context/AgenticaClassOperation.js.map +1 -1
- package/lib/context/AgenticaContext.d.ts +9 -9
- package/lib/context/AgenticaHttpOperation.d.ts +1 -1
- package/lib/context/AgenticaHttpOperation.js.map +1 -1
- package/lib/context/AgenticaOperation.d.ts +4 -4
- package/lib/context/AgenticaOperationBase.d.ts +1 -1
- package/lib/context/AgenticaOperationCollection.d.ts +2 -2
- package/lib/context/AgenticaOperationSelection.d.ts +3 -3
- package/lib/context/AgenticaTokenUsage.d.ts +1 -1
- package/lib/context/AgenticaTokenUsage.js.map +1 -1
- package/lib/context/internal/AgenticaTokenUsageAggregator.d.ts +11 -10
- package/lib/context/internal/AgenticaTokenUsageAggregator.js +42 -43
- package/lib/context/internal/AgenticaTokenUsageAggregator.js.map +1 -1
- package/lib/context/internal/__IChatCancelFunctionsApplication.d.ts +2 -2
- package/lib/context/internal/__IChatInitialApplication.d.ts +2 -2
- package/lib/context/internal/__IChatSelectFunctionsApplication.d.ts +2 -2
- package/lib/events/AgenticaCallEvent.d.ts +3 -3
- package/lib/events/AgenticaCancelEvent.d.ts +3 -3
- package/lib/events/AgenticaDescribeEvent.d.ts +3 -3
- package/lib/events/AgenticaDescribeEvent.js +13 -2
- package/lib/events/AgenticaDescribeEvent.js.map +1 -1
- package/lib/events/AgenticaEvent.d.ts +12 -12
- package/lib/events/AgenticaExecuteEvent.d.ts +7 -7
- package/lib/events/AgenticaInitializeEvent.d.ts +1 -1
- package/lib/events/AgenticaRequestEvent.d.ts +3 -3
- package/lib/events/AgenticaRequestEvent.js.map +1 -1
- package/lib/events/AgenticaResponseEvent.d.ts +2 -2
- package/lib/events/AgenticaResponseEvent.js.map +1 -1
- package/lib/events/AgenticaSelectEvent.d.ts +3 -3
- package/lib/events/AgenticaSelectEvent.js.map +1 -1
- package/lib/events/AgenticaTextEvent.d.ts +1 -1
- package/lib/events/AgenticaTextEvent.js +12 -1
- package/lib/events/AgenticaTextEvent.js.map +1 -1
- package/lib/functional/assertHttpLlmApplication.d.ts +4 -3
- package/lib/functional/assertHttpLlmApplication.js +9339 -9338
- package/lib/functional/assertHttpLlmApplication.js.map +1 -1
- package/lib/functional/validateHttpLlmApplication.d.ts +5 -4
- package/lib/functional/validateHttpLlmApplication.js +19 -19
- package/lib/functional/validateHttpLlmApplication.js.map +1 -1
- package/lib/index.d.ts +19 -19
- package/lib/index.js +21 -21
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +19211 -18997
- package/lib/index.mjs.map +1 -1
- package/lib/internal/AgenticaDefaultPrompt.d.ts +6 -5
- package/lib/internal/AgenticaDefaultPrompt.js +39 -19
- package/lib/internal/AgenticaDefaultPrompt.js.map +1 -1
- package/lib/internal/AgenticaOperationComposer.d.ts +11 -10
- package/lib/internal/AgenticaOperationComposer.js +60 -59
- package/lib/internal/AgenticaOperationComposer.js.map +1 -1
- package/lib/internal/AgenticaSystemPrompt.d.ts +8 -8
- package/lib/internal/AgenticaSystemPrompt.js +9 -9
- package/lib/internal/AgenticaSystemPrompt.js.map +1 -1
- package/lib/internal/AsyncQueue.d.ts +15 -0
- package/lib/internal/AsyncQueue.js +82 -0
- package/lib/internal/AsyncQueue.js.map +1 -0
- package/lib/internal/ByteArrayUtil.d.ts +1 -1
- package/lib/internal/ByteArrayUtil.js +3 -2
- package/lib/internal/ByteArrayUtil.js.map +1 -1
- package/lib/internal/MPSC.d.ts +10 -0
- package/lib/internal/MPSC.js +49 -0
- package/lib/internal/MPSC.js.map +1 -0
- package/lib/internal/Singleton.js +6 -5
- package/lib/internal/Singleton.js.map +1 -1
- package/lib/internal/StreamUtil.d.ts +16 -6
- package/lib/internal/StreamUtil.js +43 -29
- package/lib/internal/StreamUtil.js.map +1 -1
- package/lib/internal/__map_take.js +5 -5
- package/lib/internal/__map_take.js.map +1 -1
- package/lib/json/IAgenticaEventJson.d.ts +7 -7
- package/lib/json/IAgenticaOperationSelectionJson.d.ts +1 -1
- package/lib/json/IAgenticaPromptJson.d.ts +2 -2
- package/lib/prompts/AgenticaCancelPrompt.d.ts +3 -3
- package/lib/prompts/AgenticaCancelPrompt.js +1 -1
- package/lib/prompts/AgenticaCancelPrompt.js.map +1 -1
- package/lib/prompts/AgenticaDescribePrompt.d.ts +3 -3
- package/lib/prompts/AgenticaDescribePrompt.js +1 -1
- package/lib/prompts/AgenticaDescribePrompt.js.map +1 -1
- package/lib/prompts/AgenticaExecutePrompt.d.ts +5 -5
- package/lib/prompts/AgenticaExecutePrompt.js.map +1 -1
- package/lib/prompts/AgenticaPrompt.d.ts +6 -6
- package/lib/prompts/AgenticaSelectPrompt.d.ts +3 -3
- package/lib/prompts/AgenticaSelectPrompt.js +1 -1
- package/lib/prompts/AgenticaSelectPrompt.js.map +1 -1
- package/lib/prompts/AgenticaTextPrompt.d.ts +1 -1
- package/lib/structures/IAgenticaConfig.d.ts +5 -5
- package/lib/structures/IAgenticaController.d.ts +1 -1
- package/lib/structures/IAgenticaExecutor.d.ts +4 -4
- package/lib/structures/IAgenticaProps.d.ts +5 -5
- package/lib/structures/IAgenticaSystemPrompt.d.ts +4 -4
- package/lib/structures/IAgenticaVendor.d.ts +1 -1
- package/lib/transformers/AgenticaEventTransformer.d.ts +55 -37
- package/lib/transformers/AgenticaEventTransformer.js +105 -58
- package/lib/transformers/AgenticaEventTransformer.js.map +1 -1
- package/lib/transformers/AgenticaPromptTransformer.d.ts +35 -29
- package/lib/transformers/AgenticaPromptTransformer.js +74 -45
- package/lib/transformers/AgenticaPromptTransformer.js.map +1 -1
- package/package.json +20 -23
- package/prompts/cancel.md +1 -1
- package/prompts/common.md +1 -1
- package/prompts/describe.md +1 -1
- package/prompts/execute.md +1 -1
- package/prompts/initialize.md +1 -1
- package/prompts/select.md +1 -1
- package/src/Agentica.ts +41 -31
- package/src/chatgpt/ChatGptAgent.ts +63 -57
- package/src/chatgpt/ChatGptCallFunctionAgent.ts +363 -337
- package/src/chatgpt/ChatGptCancelFunctionAgent.ts +188 -164
- package/src/chatgpt/ChatGptCompletionMessageUtil.ts +136 -137
- package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +105 -101
- package/src/chatgpt/ChatGptHistoryDecoder.ts +69 -65
- package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +128 -123
- package/src/chatgpt/ChatGptSelectFunctionAgent.ts +215 -189
- package/src/chatgpt/ChatGptUsageAggregator.ts +49 -54
- package/src/context/AgenticaCancelPrompt.ts +4 -4
- package/src/context/AgenticaClassOperation.ts +5 -5
- package/src/context/AgenticaContext.ts +15 -15
- package/src/context/AgenticaHttpOperation.ts +5 -5
- package/src/context/AgenticaOperation.ts +4 -4
- package/src/context/AgenticaOperationBase.ts +1 -1
- package/src/context/AgenticaOperationCollection.ts +2 -2
- package/src/context/AgenticaOperationSelection.ts +3 -3
- package/src/context/AgenticaTokenUsage.ts +4 -3
- package/src/context/internal/AgenticaTokenUsageAggregator.ts +59 -59
- package/src/context/internal/__IChatCancelFunctionsApplication.ts +2 -2
- package/src/context/internal/__IChatInitialApplication.ts +2 -2
- package/src/context/internal/__IChatSelectFunctionsApplication.ts +2 -2
- package/src/events/AgenticaCallEvent.ts +3 -3
- package/src/events/AgenticaCancelEvent.ts +3 -3
- package/src/events/AgenticaDescribeEvent.ts +5 -5
- package/src/events/AgenticaEvent.ts +12 -12
- package/src/events/AgenticaExecuteEvent.ts +7 -7
- package/src/events/AgenticaInitializeEvent.ts +1 -1
- package/src/events/AgenticaRequestEvent.ts +3 -3
- package/src/events/AgenticaResponseEvent.ts +2 -2
- package/src/events/AgenticaSelectEvent.ts +4 -4
- package/src/events/AgenticaTextEvent.ts +2 -2
- package/src/functional/assertHttpLlmApplication.ts +9 -6
- package/src/functional/validateHttpLlmApplication.ts +14 -8
- package/src/index.ts +24 -24
- package/src/internal/AgenticaDefaultPrompt.ts +42 -28
- package/src/internal/AgenticaOperationComposer.ts +63 -61
- package/src/internal/AgenticaSystemPrompt.ts +15 -14
- package/src/internal/AsyncQueue.ts +67 -0
- package/src/internal/ByteArrayUtil.ts +2 -2
- package/src/internal/MPSC.ts +40 -0
- package/src/internal/Singleton.ts +8 -6
- package/src/internal/StreamUtil.ts +62 -53
- package/src/internal/__map_take.ts +5 -7
- package/src/json/IAgenticaEventJson.ts +7 -8
- package/src/json/IAgenticaOperationSelectionJson.ts +1 -1
- package/src/json/IAgenticaPromptJson.ts +2 -2
- package/src/prompts/AgenticaCancelPrompt.ts +4 -4
- package/src/prompts/AgenticaDescribePrompt.ts +4 -4
- package/src/prompts/AgenticaExecutePrompt.ts +6 -5
- package/src/prompts/AgenticaPrompt.ts +6 -6
- package/src/prompts/AgenticaSelectPrompt.ts +4 -4
- package/src/prompts/AgenticaTextPrompt.ts +1 -1
- package/src/structures/IAgenticaConfig.ts +5 -5
- package/src/structures/IAgenticaController.ts +14 -14
- package/src/structures/IAgenticaExecutor.ts +4 -4
- package/src/structures/IAgenticaProps.ts +5 -5
- package/src/structures/IAgenticaSystemPrompt.ts +4 -4
- package/src/structures/IAgenticaVendor.ts +1 -1
- package/src/transformers/AgenticaEventTransformer.ts +169 -136
- package/src/transformers/AgenticaPromptTransformer.ts +125 -103
- package/lib/internal/MPSCUtil.d.ts +0 -35
- package/lib/internal/MPSCUtil.js +0 -105
- package/lib/internal/MPSCUtil.js.map +0 -1
- package/src/internal/MPSCUtil.ts +0 -111
|
@@ -34,503 +34,513 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.ChatGptCompletionMessageUtil = void 0;
|
|
37
|
+
exports.transformCompletionChunk = transformCompletionChunk;
|
|
38
|
+
exports.accumulate = accumulate;
|
|
39
|
+
exports.merge = merge;
|
|
40
|
+
exports.mergeChoice = mergeChoice;
|
|
41
|
+
exports.mergeToolCalls = mergeToolCalls;
|
|
37
42
|
const __typia_transform__assertGuard = __importStar(require("typia/lib/internal/_assertGuard.js"));
|
|
38
43
|
const typia_1 = require("typia");
|
|
39
44
|
const ByteArrayUtil_1 = require("../internal/ByteArrayUtil");
|
|
40
45
|
const ChatGptUsageAggregator_1 = require("./ChatGptUsageAggregator");
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
value: input
|
|
413
|
-
}, _errorFactory))(input, "$input", true);
|
|
414
|
-
}
|
|
415
|
-
return input;
|
|
416
|
-
}; return (input, errorFactory) => __assert(JSON.parse(input), errorFactory); })()(str);
|
|
417
|
-
};
|
|
418
|
-
ChatGptCompletionMessageUtil.accumulate = (origin, chunk) => {
|
|
419
|
-
const choices = origin.choices;
|
|
420
|
-
chunk.choices.forEach((choice) => {
|
|
421
|
-
var _a, _b, _c, _d;
|
|
422
|
-
const accChoice = choices[choice.index];
|
|
423
|
-
if (accChoice) {
|
|
424
|
-
choices[choice.index] = ChatGptCompletionMessageUtil.mergeChoice(accChoice, choice);
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
choices[choice.index] = {
|
|
428
|
-
index: choice.index,
|
|
429
|
-
finish_reason: (_a = choice.finish_reason) !== null && _a !== void 0 ? _a : null,
|
|
430
|
-
logprobs: (_b = choice.logprobs) !== null && _b !== void 0 ? _b : null,
|
|
431
|
-
message: {
|
|
432
|
-
tool_calls: choice.delta.tool_calls
|
|
433
|
-
? choice.delta.tool_calls.reduce((acc, cur) => {
|
|
434
|
-
var _a, _b, _c, _d, _e;
|
|
435
|
-
acc[cur.index] = {
|
|
436
|
-
id: (_a = cur.id) !== null && _a !== void 0 ? _a : "",
|
|
437
|
-
type: "function",
|
|
438
|
-
function: {
|
|
439
|
-
name: (_c = (_b = cur.function) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : "",
|
|
440
|
-
arguments: (_e = (_d = cur.function) === null || _d === void 0 ? void 0 : _d.arguments) !== null && _e !== void 0 ? _e : "",
|
|
441
|
-
},
|
|
442
|
-
};
|
|
443
|
-
return acc;
|
|
444
|
-
}, [])
|
|
445
|
-
: undefined,
|
|
446
|
-
content: (_c = choice.delta.content) !== null && _c !== void 0 ? _c : null,
|
|
447
|
-
refusal: (_d = choice.delta.refusal) !== null && _d !== void 0 ? _d : null,
|
|
448
|
-
role: "assistant",
|
|
449
|
-
},
|
|
450
|
-
};
|
|
451
|
-
});
|
|
452
|
-
const usage = (() => {
|
|
453
|
-
if (!chunk.usage) {
|
|
454
|
-
return origin.usage;
|
|
455
|
-
}
|
|
456
|
-
if (!origin.usage) {
|
|
457
|
-
return chunk.usage;
|
|
458
|
-
}
|
|
459
|
-
return ChatGptUsageAggregator_1.ChatGptUsageAggregator.sum(origin.usage, chunk.usage);
|
|
460
|
-
})();
|
|
461
|
-
return Object.assign(Object.assign({}, origin), { choices,
|
|
462
|
-
usage });
|
|
463
|
-
};
|
|
464
|
-
ChatGptCompletionMessageUtil.merge = (chunks) => {
|
|
465
|
-
const firstChunk = chunks[0];
|
|
466
|
-
if (!firstChunk)
|
|
467
|
-
throw new Error("No chunks received");
|
|
468
|
-
return chunks.reduce(ChatGptCompletionMessageUtil.accumulate, {
|
|
469
|
-
id: firstChunk.id,
|
|
470
|
-
choices: [],
|
|
471
|
-
created: firstChunk.created,
|
|
472
|
-
model: firstChunk.model,
|
|
473
|
-
object: "chat.completion",
|
|
474
|
-
usage: undefined,
|
|
475
|
-
service_tier: firstChunk.service_tier,
|
|
476
|
-
system_fingerprint: firstChunk.system_fingerprint,
|
|
477
|
-
});
|
|
478
|
-
};
|
|
479
|
-
ChatGptCompletionMessageUtil.mergeChoice = (acc, cur) => {
|
|
480
|
-
var _a;
|
|
481
|
-
var _b;
|
|
482
|
-
if (!acc.finish_reason && cur.finish_reason) {
|
|
483
|
-
acc.finish_reason = cur.finish_reason;
|
|
46
|
+
function transformCompletionChunk(source) {
|
|
47
|
+
const str = source instanceof Uint8Array ? ByteArrayUtil_1.ByteArrayUtil.toUtf8(source) : source;
|
|
48
|
+
return (() => { 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 _ao0 = (input, _path, _exceptionable = true) => ("string" === typeof input.id || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
49
|
+
method: "json.assertParse",
|
|
50
|
+
path: _path + ".id",
|
|
51
|
+
expected: "string",
|
|
52
|
+
value: input.id
|
|
53
|
+
}, _errorFactory)) && ((Array.isArray(input.choices) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
54
|
+
method: "json.assertParse",
|
|
55
|
+
path: _path + ".choices",
|
|
56
|
+
expected: "Array<ChatCompletionChunk.Choice>",
|
|
57
|
+
value: input.choices
|
|
58
|
+
}, _errorFactory)) && input.choices.every((elem, _index8) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
59
|
+
method: "json.assertParse",
|
|
60
|
+
path: _path + ".choices[" + _index8 + "]",
|
|
61
|
+
expected: "ChatCompletionChunk.Choice",
|
|
62
|
+
value: elem
|
|
63
|
+
}, _errorFactory)) && _ao1(elem, _path + ".choices[" + _index8 + "]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
64
|
+
method: "json.assertParse",
|
|
65
|
+
path: _path + ".choices[" + _index8 + "]",
|
|
66
|
+
expected: "ChatCompletionChunk.Choice",
|
|
67
|
+
value: elem
|
|
68
|
+
}, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
69
|
+
method: "json.assertParse",
|
|
70
|
+
path: _path + ".choices",
|
|
71
|
+
expected: "Array<ChatCompletionChunk.Choice>",
|
|
72
|
+
value: input.choices
|
|
73
|
+
}, _errorFactory)) && ("number" === typeof input.created || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
74
|
+
method: "json.assertParse",
|
|
75
|
+
path: _path + ".created",
|
|
76
|
+
expected: "number",
|
|
77
|
+
value: input.created
|
|
78
|
+
}, _errorFactory)) && ("string" === typeof input.model || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
79
|
+
method: "json.assertParse",
|
|
80
|
+
path: _path + ".model",
|
|
81
|
+
expected: "string",
|
|
82
|
+
value: input.model
|
|
83
|
+
}, _errorFactory)) && ("chat.completion.chunk" === input.object || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
84
|
+
method: "json.assertParse",
|
|
85
|
+
path: _path + ".object",
|
|
86
|
+
expected: "\"chat.completion.chunk\"",
|
|
87
|
+
value: input.object
|
|
88
|
+
}, _errorFactory)) && (null === input.service_tier || undefined === input.service_tier || "scale" === input.service_tier || "default" === input.service_tier || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
89
|
+
method: "json.assertParse",
|
|
90
|
+
path: _path + ".service_tier",
|
|
91
|
+
expected: "(\"default\" | \"scale\" | null | undefined)",
|
|
92
|
+
value: input.service_tier
|
|
93
|
+
}, _errorFactory)) && (undefined === input.system_fingerprint || "string" === typeof input.system_fingerprint || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
94
|
+
method: "json.assertParse",
|
|
95
|
+
path: _path + ".system_fingerprint",
|
|
96
|
+
expected: "(string | undefined)",
|
|
97
|
+
value: input.system_fingerprint
|
|
98
|
+
}, _errorFactory)) && (null === input.usage || undefined === input.usage || ("object" === typeof input.usage && null !== input.usage || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
99
|
+
method: "json.assertParse",
|
|
100
|
+
path: _path + ".usage",
|
|
101
|
+
expected: "(CompletionUsage | null | undefined)",
|
|
102
|
+
value: input.usage
|
|
103
|
+
}, _errorFactory)) && _ao9(input.usage, _path + ".usage", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
104
|
+
method: "json.assertParse",
|
|
105
|
+
path: _path + ".usage",
|
|
106
|
+
expected: "(CompletionUsage | null | undefined)",
|
|
107
|
+
value: input.usage
|
|
108
|
+
}, _errorFactory)); const _ao1 = (input, _path, _exceptionable = true) => (("object" === typeof input.delta && null !== input.delta && false === Array.isArray(input.delta) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
109
|
+
method: "json.assertParse",
|
|
110
|
+
path: _path + ".delta",
|
|
111
|
+
expected: "ChatCompletionChunk.Choice.Delta",
|
|
112
|
+
value: input.delta
|
|
113
|
+
}, _errorFactory)) && _ao2(input.delta, _path + ".delta", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
114
|
+
method: "json.assertParse",
|
|
115
|
+
path: _path + ".delta",
|
|
116
|
+
expected: "ChatCompletionChunk.Choice.Delta",
|
|
117
|
+
value: input.delta
|
|
118
|
+
}, _errorFactory)) && (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 || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
119
|
+
method: "json.assertParse",
|
|
120
|
+
path: _path + ".finish_reason",
|
|
121
|
+
expected: "(\"content_filter\" | \"function_call\" | \"length\" | \"stop\" | \"tool_calls\" | null)",
|
|
122
|
+
value: input.finish_reason
|
|
123
|
+
}, _errorFactory)) && ("number" === typeof input.index || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
124
|
+
method: "json.assertParse",
|
|
125
|
+
path: _path + ".index",
|
|
126
|
+
expected: "number",
|
|
127
|
+
value: input.index
|
|
128
|
+
}, _errorFactory)) && (null === input.logprobs || undefined === input.logprobs || ("object" === typeof input.logprobs && null !== input.logprobs || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
129
|
+
method: "json.assertParse",
|
|
130
|
+
path: _path + ".logprobs",
|
|
131
|
+
expected: "(ChatCompletionChunk.Choice.Logprobs | null | undefined)",
|
|
132
|
+
value: input.logprobs
|
|
133
|
+
}, _errorFactory)) && _ao6(input.logprobs, _path + ".logprobs", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
134
|
+
method: "json.assertParse",
|
|
135
|
+
path: _path + ".logprobs",
|
|
136
|
+
expected: "(ChatCompletionChunk.Choice.Logprobs | null | undefined)",
|
|
137
|
+
value: input.logprobs
|
|
138
|
+
}, _errorFactory)); const _ao2 = (input, _path, _exceptionable = true) => (null === input.content || undefined === input.content || "string" === typeof input.content || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
139
|
+
method: "json.assertParse",
|
|
140
|
+
path: _path + ".content",
|
|
141
|
+
expected: "(null | string | undefined)",
|
|
142
|
+
value: input.content
|
|
143
|
+
}, _errorFactory)) && (undefined === input.function_call || ("object" === typeof input.function_call && null !== input.function_call && false === Array.isArray(input.function_call) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
144
|
+
method: "json.assertParse",
|
|
145
|
+
path: _path + ".function_call",
|
|
146
|
+
expected: "(ChatCompletionChunk.Choice.Delta.FunctionCall | undefined)",
|
|
147
|
+
value: input.function_call
|
|
148
|
+
}, _errorFactory)) && _ao3(input.function_call, _path + ".function_call", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
149
|
+
method: "json.assertParse",
|
|
150
|
+
path: _path + ".function_call",
|
|
151
|
+
expected: "(ChatCompletionChunk.Choice.Delta.FunctionCall | undefined)",
|
|
152
|
+
value: input.function_call
|
|
153
|
+
}, _errorFactory)) && (null === input.refusal || undefined === input.refusal || "string" === typeof input.refusal || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
154
|
+
method: "json.assertParse",
|
|
155
|
+
path: _path + ".refusal",
|
|
156
|
+
expected: "(null | string | undefined)",
|
|
157
|
+
value: input.refusal
|
|
158
|
+
}, _errorFactory)) && (undefined === input.role || "assistant" === input.role || "user" === input.role || "developer" === input.role || "system" === input.role || "tool" === input.role || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
159
|
+
method: "json.assertParse",
|
|
160
|
+
path: _path + ".role",
|
|
161
|
+
expected: "(\"assistant\" | \"developer\" | \"system\" | \"tool\" | \"user\" | undefined)",
|
|
162
|
+
value: input.role
|
|
163
|
+
}, _errorFactory)) && (undefined === input.tool_calls || (Array.isArray(input.tool_calls) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
164
|
+
method: "json.assertParse",
|
|
165
|
+
path: _path + ".tool_calls",
|
|
166
|
+
expected: "(Array<ChatCompletionChunk.Choice.Delta.ToolCall> | undefined)",
|
|
167
|
+
value: input.tool_calls
|
|
168
|
+
}, _errorFactory)) && input.tool_calls.every((elem, _index9) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
169
|
+
method: "json.assertParse",
|
|
170
|
+
path: _path + ".tool_calls[" + _index9 + "]",
|
|
171
|
+
expected: "ChatCompletionChunk.Choice.Delta.ToolCall",
|
|
172
|
+
value: elem
|
|
173
|
+
}, _errorFactory)) && _ao4(elem, _path + ".tool_calls[" + _index9 + "]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
174
|
+
method: "json.assertParse",
|
|
175
|
+
path: _path + ".tool_calls[" + _index9 + "]",
|
|
176
|
+
expected: "ChatCompletionChunk.Choice.Delta.ToolCall",
|
|
177
|
+
value: elem
|
|
178
|
+
}, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
179
|
+
method: "json.assertParse",
|
|
180
|
+
path: _path + ".tool_calls",
|
|
181
|
+
expected: "(Array<ChatCompletionChunk.Choice.Delta.ToolCall> | undefined)",
|
|
182
|
+
value: input.tool_calls
|
|
183
|
+
}, _errorFactory)); const _ao3 = (input, _path, _exceptionable = true) => (undefined === input.arguments || "string" === typeof input.arguments || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
184
|
+
method: "json.assertParse",
|
|
185
|
+
path: _path + ".arguments",
|
|
186
|
+
expected: "(string | undefined)",
|
|
187
|
+
value: input.arguments
|
|
188
|
+
}, _errorFactory)) && (undefined === input.name || "string" === typeof input.name || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
189
|
+
method: "json.assertParse",
|
|
190
|
+
path: _path + ".name",
|
|
191
|
+
expected: "(string | undefined)",
|
|
192
|
+
value: input.name
|
|
193
|
+
}, _errorFactory)); const _ao4 = (input, _path, _exceptionable = true) => ("number" === typeof input.index || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
194
|
+
method: "json.assertParse",
|
|
195
|
+
path: _path + ".index",
|
|
196
|
+
expected: "number",
|
|
197
|
+
value: input.index
|
|
198
|
+
}, _errorFactory)) && (undefined === input.id || "string" === typeof input.id || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
199
|
+
method: "json.assertParse",
|
|
200
|
+
path: _path + ".id",
|
|
201
|
+
expected: "(string | undefined)",
|
|
202
|
+
value: input.id
|
|
203
|
+
}, _errorFactory)) && (undefined === input["function"] || ("object" === typeof input["function"] && null !== input["function"] && false === Array.isArray(input["function"]) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
204
|
+
method: "json.assertParse",
|
|
205
|
+
path: _path + "[\"function\"]",
|
|
206
|
+
expected: "(ChatCompletionChunk.Choice.Delta.ToolCall.Function | undefined)",
|
|
207
|
+
value: input["function"]
|
|
208
|
+
}, _errorFactory)) && _ao5(input["function"], _path + "[\"function\"]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
209
|
+
method: "json.assertParse",
|
|
210
|
+
path: _path + "[\"function\"]",
|
|
211
|
+
expected: "(ChatCompletionChunk.Choice.Delta.ToolCall.Function | undefined)",
|
|
212
|
+
value: input["function"]
|
|
213
|
+
}, _errorFactory)) && (undefined === input.type || "function" === input.type || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
214
|
+
method: "json.assertParse",
|
|
215
|
+
path: _path + ".type",
|
|
216
|
+
expected: "(\"function\" | undefined)",
|
|
217
|
+
value: input.type
|
|
218
|
+
}, _errorFactory)); const _ao5 = (input, _path, _exceptionable = true) => (undefined === input.arguments || "string" === typeof input.arguments || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
219
|
+
method: "json.assertParse",
|
|
220
|
+
path: _path + ".arguments",
|
|
221
|
+
expected: "(string | undefined)",
|
|
222
|
+
value: input.arguments
|
|
223
|
+
}, _errorFactory)) && (undefined === input.name || "string" === typeof input.name || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
224
|
+
method: "json.assertParse",
|
|
225
|
+
path: _path + ".name",
|
|
226
|
+
expected: "(string | undefined)",
|
|
227
|
+
value: input.name
|
|
228
|
+
}, _errorFactory)); const _ao6 = (input, _path, _exceptionable = true) => (null === input.content || (Array.isArray(input.content) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
229
|
+
method: "json.assertParse",
|
|
230
|
+
path: _path + ".content",
|
|
231
|
+
expected: "(Array<ChatCompletionTokenLogprob> | null)",
|
|
232
|
+
value: input.content
|
|
233
|
+
}, _errorFactory)) && input.content.every((elem, _index10) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
234
|
+
method: "json.assertParse",
|
|
235
|
+
path: _path + ".content[" + _index10 + "]",
|
|
236
|
+
expected: "ChatCompletionTokenLogprob",
|
|
237
|
+
value: elem
|
|
238
|
+
}, _errorFactory)) && _ao7(elem, _path + ".content[" + _index10 + "]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
239
|
+
method: "json.assertParse",
|
|
240
|
+
path: _path + ".content[" + _index10 + "]",
|
|
241
|
+
expected: "ChatCompletionTokenLogprob",
|
|
242
|
+
value: elem
|
|
243
|
+
}, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
244
|
+
method: "json.assertParse",
|
|
245
|
+
path: _path + ".content",
|
|
246
|
+
expected: "(Array<ChatCompletionTokenLogprob> | null)",
|
|
247
|
+
value: input.content
|
|
248
|
+
}, _errorFactory)) && (null === input.refusal || (Array.isArray(input.refusal) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
249
|
+
method: "json.assertParse",
|
|
250
|
+
path: _path + ".refusal",
|
|
251
|
+
expected: "(Array<ChatCompletionTokenLogprob> | null)",
|
|
252
|
+
value: input.refusal
|
|
253
|
+
}, _errorFactory)) && input.refusal.every((elem, _index11) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
254
|
+
method: "json.assertParse",
|
|
255
|
+
path: _path + ".refusal[" + _index11 + "]",
|
|
256
|
+
expected: "ChatCompletionTokenLogprob",
|
|
257
|
+
value: elem
|
|
258
|
+
}, _errorFactory)) && _ao7(elem, _path + ".refusal[" + _index11 + "]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
259
|
+
method: "json.assertParse",
|
|
260
|
+
path: _path + ".refusal[" + _index11 + "]",
|
|
261
|
+
expected: "ChatCompletionTokenLogprob",
|
|
262
|
+
value: elem
|
|
263
|
+
}, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
264
|
+
method: "json.assertParse",
|
|
265
|
+
path: _path + ".refusal",
|
|
266
|
+
expected: "(Array<ChatCompletionTokenLogprob> | null)",
|
|
267
|
+
value: input.refusal
|
|
268
|
+
}, _errorFactory)); const _ao7 = (input, _path, _exceptionable = true) => ("string" === typeof input.token || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
269
|
+
method: "json.assertParse",
|
|
270
|
+
path: _path + ".token",
|
|
271
|
+
expected: "string",
|
|
272
|
+
value: input.token
|
|
273
|
+
}, _errorFactory)) && (null === input.bytes || (Array.isArray(input.bytes) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
274
|
+
method: "json.assertParse",
|
|
275
|
+
path: _path + ".bytes",
|
|
276
|
+
expected: "(Array<number> | null)",
|
|
277
|
+
value: input.bytes
|
|
278
|
+
}, _errorFactory)) && input.bytes.every((elem, _index12) => "number" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
279
|
+
method: "json.assertParse",
|
|
280
|
+
path: _path + ".bytes[" + _index12 + "]",
|
|
281
|
+
expected: "number",
|
|
282
|
+
value: elem
|
|
283
|
+
}, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
284
|
+
method: "json.assertParse",
|
|
285
|
+
path: _path + ".bytes",
|
|
286
|
+
expected: "(Array<number> | null)",
|
|
287
|
+
value: input.bytes
|
|
288
|
+
}, _errorFactory)) && ("number" === typeof input.logprob || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
289
|
+
method: "json.assertParse",
|
|
290
|
+
path: _path + ".logprob",
|
|
291
|
+
expected: "number",
|
|
292
|
+
value: input.logprob
|
|
293
|
+
}, _errorFactory)) && ((Array.isArray(input.top_logprobs) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
294
|
+
method: "json.assertParse",
|
|
295
|
+
path: _path + ".top_logprobs",
|
|
296
|
+
expected: "Array<ChatCompletionTokenLogprob.TopLogprob>",
|
|
297
|
+
value: input.top_logprobs
|
|
298
|
+
}, _errorFactory)) && input.top_logprobs.every((elem, _index13) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
299
|
+
method: "json.assertParse",
|
|
300
|
+
path: _path + ".top_logprobs[" + _index13 + "]",
|
|
301
|
+
expected: "ChatCompletionTokenLogprob.TopLogprob",
|
|
302
|
+
value: elem
|
|
303
|
+
}, _errorFactory)) && _ao8(elem, _path + ".top_logprobs[" + _index13 + "]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
304
|
+
method: "json.assertParse",
|
|
305
|
+
path: _path + ".top_logprobs[" + _index13 + "]",
|
|
306
|
+
expected: "ChatCompletionTokenLogprob.TopLogprob",
|
|
307
|
+
value: elem
|
|
308
|
+
}, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
309
|
+
method: "json.assertParse",
|
|
310
|
+
path: _path + ".top_logprobs",
|
|
311
|
+
expected: "Array<ChatCompletionTokenLogprob.TopLogprob>",
|
|
312
|
+
value: input.top_logprobs
|
|
313
|
+
}, _errorFactory)); const _ao8 = (input, _path, _exceptionable = true) => ("string" === typeof input.token || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
314
|
+
method: "json.assertParse",
|
|
315
|
+
path: _path + ".token",
|
|
316
|
+
expected: "string",
|
|
317
|
+
value: input.token
|
|
318
|
+
}, _errorFactory)) && (null === input.bytes || (Array.isArray(input.bytes) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
319
|
+
method: "json.assertParse",
|
|
320
|
+
path: _path + ".bytes",
|
|
321
|
+
expected: "(Array<number> | null)",
|
|
322
|
+
value: input.bytes
|
|
323
|
+
}, _errorFactory)) && input.bytes.every((elem, _index14) => "number" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
324
|
+
method: "json.assertParse",
|
|
325
|
+
path: _path + ".bytes[" + _index14 + "]",
|
|
326
|
+
expected: "number",
|
|
327
|
+
value: elem
|
|
328
|
+
}, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
329
|
+
method: "json.assertParse",
|
|
330
|
+
path: _path + ".bytes",
|
|
331
|
+
expected: "(Array<number> | null)",
|
|
332
|
+
value: input.bytes
|
|
333
|
+
}, _errorFactory)) && ("number" === typeof input.logprob || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
334
|
+
method: "json.assertParse",
|
|
335
|
+
path: _path + ".logprob",
|
|
336
|
+
expected: "number",
|
|
337
|
+
value: input.logprob
|
|
338
|
+
}, _errorFactory)); const _ao9 = (input, _path, _exceptionable = true) => ("number" === typeof input.completion_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
339
|
+
method: "json.assertParse",
|
|
340
|
+
path: _path + ".completion_tokens",
|
|
341
|
+
expected: "number",
|
|
342
|
+
value: input.completion_tokens
|
|
343
|
+
}, _errorFactory)) && ("number" === typeof input.prompt_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
344
|
+
method: "json.assertParse",
|
|
345
|
+
path: _path + ".prompt_tokens",
|
|
346
|
+
expected: "number",
|
|
347
|
+
value: input.prompt_tokens
|
|
348
|
+
}, _errorFactory)) && ("number" === typeof input.total_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
349
|
+
method: "json.assertParse",
|
|
350
|
+
path: _path + ".total_tokens",
|
|
351
|
+
expected: "number",
|
|
352
|
+
value: input.total_tokens
|
|
353
|
+
}, _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, {
|
|
354
|
+
method: "json.assertParse",
|
|
355
|
+
path: _path + ".completion_tokens_details",
|
|
356
|
+
expected: "(CompletionUsage.CompletionTokensDetails | undefined)",
|
|
357
|
+
value: input.completion_tokens_details
|
|
358
|
+
}, _errorFactory)) && _ao10(input.completion_tokens_details, _path + ".completion_tokens_details", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
359
|
+
method: "json.assertParse",
|
|
360
|
+
path: _path + ".completion_tokens_details",
|
|
361
|
+
expected: "(CompletionUsage.CompletionTokensDetails | undefined)",
|
|
362
|
+
value: input.completion_tokens_details
|
|
363
|
+
}, _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, {
|
|
364
|
+
method: "json.assertParse",
|
|
365
|
+
path: _path + ".prompt_tokens_details",
|
|
366
|
+
expected: "(CompletionUsage.PromptTokensDetails | undefined)",
|
|
367
|
+
value: input.prompt_tokens_details
|
|
368
|
+
}, _errorFactory)) && _ao11(input.prompt_tokens_details, _path + ".prompt_tokens_details", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
369
|
+
method: "json.assertParse",
|
|
370
|
+
path: _path + ".prompt_tokens_details",
|
|
371
|
+
expected: "(CompletionUsage.PromptTokensDetails | undefined)",
|
|
372
|
+
value: input.prompt_tokens_details
|
|
373
|
+
}, _errorFactory)); const _ao10 = (input, _path, _exceptionable = true) => (undefined === input.accepted_prediction_tokens || "number" === typeof input.accepted_prediction_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
374
|
+
method: "json.assertParse",
|
|
375
|
+
path: _path + ".accepted_prediction_tokens",
|
|
376
|
+
expected: "(number | undefined)",
|
|
377
|
+
value: input.accepted_prediction_tokens
|
|
378
|
+
}, _errorFactory)) && (undefined === input.audio_tokens || "number" === typeof input.audio_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
379
|
+
method: "json.assertParse",
|
|
380
|
+
path: _path + ".audio_tokens",
|
|
381
|
+
expected: "(number | undefined)",
|
|
382
|
+
value: input.audio_tokens
|
|
383
|
+
}, _errorFactory)) && (undefined === input.reasoning_tokens || "number" === typeof input.reasoning_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
384
|
+
method: "json.assertParse",
|
|
385
|
+
path: _path + ".reasoning_tokens",
|
|
386
|
+
expected: "(number | undefined)",
|
|
387
|
+
value: input.reasoning_tokens
|
|
388
|
+
}, _errorFactory)) && (undefined === input.rejected_prediction_tokens || "number" === typeof input.rejected_prediction_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
389
|
+
method: "json.assertParse",
|
|
390
|
+
path: _path + ".rejected_prediction_tokens",
|
|
391
|
+
expected: "(number | undefined)",
|
|
392
|
+
value: input.rejected_prediction_tokens
|
|
393
|
+
}, _errorFactory)); const _ao11 = (input, _path, _exceptionable = true) => (undefined === input.audio_tokens || "number" === typeof input.audio_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
394
|
+
method: "json.assertParse",
|
|
395
|
+
path: _path + ".audio_tokens",
|
|
396
|
+
expected: "(number | undefined)",
|
|
397
|
+
value: input.audio_tokens
|
|
398
|
+
}, _errorFactory)) && (undefined === input.cached_tokens || "number" === typeof input.cached_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
399
|
+
method: "json.assertParse",
|
|
400
|
+
path: _path + ".cached_tokens",
|
|
401
|
+
expected: "(number | undefined)",
|
|
402
|
+
value: input.cached_tokens
|
|
403
|
+
}, _errorFactory)); const __is = input => "object" === typeof input && null !== input && _io0(input); let _errorFactory; const __assert = (input, errorFactory) => {
|
|
404
|
+
if (false === __is(input)) {
|
|
405
|
+
_errorFactory = errorFactory;
|
|
406
|
+
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || __typia_transform__assertGuard._assertGuard(true, {
|
|
407
|
+
method: "json.assertParse",
|
|
408
|
+
path: _path + "",
|
|
409
|
+
expected: "ChatCompletionChunk & { usage: CompletionUsage | null | undefined; }",
|
|
410
|
+
value: input
|
|
411
|
+
}, _errorFactory)) && _ao0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
|
|
412
|
+
method: "json.assertParse",
|
|
413
|
+
path: _path + "",
|
|
414
|
+
expected: "ChatCompletionChunk & { usage: CompletionUsage | null | undefined; }",
|
|
415
|
+
value: input
|
|
416
|
+
}, _errorFactory))(input, "$input", true);
|
|
484
417
|
}
|
|
485
|
-
|
|
486
|
-
|
|
418
|
+
return input;
|
|
419
|
+
}; return (input, errorFactory) => __assert(JSON.parse(input), errorFactory); })()(str);
|
|
420
|
+
}
|
|
421
|
+
function accumulate(origin, chunk) {
|
|
422
|
+
const choices = origin.choices;
|
|
423
|
+
chunk.choices.forEach((choice) => {
|
|
424
|
+
var _a, _b, _c, _d;
|
|
425
|
+
const accChoice = choices[choice.index];
|
|
426
|
+
if (accChoice != null) {
|
|
427
|
+
choices[choice.index] = mergeChoice(accChoice, choice);
|
|
428
|
+
return;
|
|
487
429
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
430
|
+
choices[choice.index] = {
|
|
431
|
+
index: choice.index,
|
|
432
|
+
finish_reason: (_a = choice.finish_reason) !== null && _a !== void 0 ? _a : null,
|
|
433
|
+
logprobs: (_b = choice.logprobs) !== null && _b !== void 0 ? _b : null,
|
|
434
|
+
message: {
|
|
435
|
+
tool_calls: choice.delta.tool_calls !== undefined
|
|
436
|
+
? choice.delta.tool_calls.reduce((acc, cur) => {
|
|
437
|
+
var _a, _b, _c, _d, _e;
|
|
438
|
+
acc[cur.index] = {
|
|
439
|
+
id: (_a = cur.id) !== null && _a !== void 0 ? _a : "",
|
|
440
|
+
type: "function",
|
|
441
|
+
function: {
|
|
442
|
+
name: (_c = (_b = cur.function) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : "",
|
|
443
|
+
arguments: (_e = (_d = cur.function) === null || _d === void 0 ? void 0 : _d.arguments) !== null && _e !== void 0 ? _e : "",
|
|
444
|
+
},
|
|
445
|
+
};
|
|
446
|
+
return acc;
|
|
447
|
+
}, [])
|
|
448
|
+
: undefined,
|
|
449
|
+
content: (_c = choice.delta.content) !== null && _c !== void 0 ? _c : null,
|
|
450
|
+
refusal: (_d = choice.delta.refusal) !== null && _d !== void 0 ? _d : null,
|
|
451
|
+
role: "assistant",
|
|
452
|
+
},
|
|
453
|
+
};
|
|
454
|
+
});
|
|
455
|
+
const usage = (() => {
|
|
456
|
+
if (chunk.usage == null) {
|
|
457
|
+
return origin.usage;
|
|
495
458
|
}
|
|
496
|
-
if (
|
|
497
|
-
|
|
498
|
-
acc.message.refusal = cur.delta.refusal;
|
|
499
|
-
}
|
|
500
|
-
else {
|
|
501
|
-
acc.message.refusal += cur.delta.refusal;
|
|
502
|
-
}
|
|
459
|
+
if (origin.usage == null) {
|
|
460
|
+
return chunk.usage;
|
|
503
461
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
462
|
+
return ChatGptUsageAggregator_1.ChatGptUsageAggregator.sum(origin.usage, chunk.usage);
|
|
463
|
+
})();
|
|
464
|
+
return Object.assign(Object.assign({}, origin), { choices,
|
|
465
|
+
usage });
|
|
466
|
+
}
|
|
467
|
+
function merge(chunks) {
|
|
468
|
+
const firstChunk = chunks[0];
|
|
469
|
+
if (firstChunk === undefined) {
|
|
470
|
+
throw new Error("No chunks received");
|
|
471
|
+
}
|
|
472
|
+
return chunks.reduce(accumulate, {
|
|
473
|
+
id: firstChunk.id,
|
|
474
|
+
choices: [],
|
|
475
|
+
created: firstChunk.created,
|
|
476
|
+
model: firstChunk.model,
|
|
477
|
+
object: "chat.completion",
|
|
478
|
+
usage: undefined,
|
|
479
|
+
service_tier: firstChunk.service_tier,
|
|
480
|
+
system_fingerprint: firstChunk.system_fingerprint,
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
function mergeChoice(acc, cur) {
|
|
484
|
+
var _a;
|
|
485
|
+
var _b;
|
|
486
|
+
if (acc.finish_reason == null && cur.finish_reason != null) {
|
|
487
|
+
acc.finish_reason = cur.finish_reason;
|
|
488
|
+
}
|
|
489
|
+
if (acc.logprobs == null && cur.logprobs != null) {
|
|
490
|
+
acc.logprobs = cur.logprobs;
|
|
491
|
+
}
|
|
492
|
+
if (cur.delta.content != null) {
|
|
493
|
+
if (acc.message.content == null) {
|
|
494
|
+
acc.message.content = cur.delta.content;
|
|
523
495
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
ChatGptCompletionMessageUtil.mergeToolCalls = (acc, cur) => {
|
|
527
|
-
var _a, _b, _c;
|
|
528
|
-
if (cur.function) {
|
|
529
|
-
acc.function.arguments += (_a = cur.function.arguments) !== null && _a !== void 0 ? _a : "";
|
|
530
|
-
acc.function.name += (_b = cur.function.name) !== null && _b !== void 0 ? _b : "";
|
|
496
|
+
else {
|
|
497
|
+
acc.message.content += cur.delta.content;
|
|
531
498
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
499
|
+
}
|
|
500
|
+
if (cur.delta.refusal != null) {
|
|
501
|
+
if (acc.message.refusal == null) {
|
|
502
|
+
acc.message.refusal = cur.delta.refusal;
|
|
503
|
+
}
|
|
504
|
+
else {
|
|
505
|
+
acc.message.refusal += cur.delta.refusal;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
if (cur.delta.tool_calls != null) {
|
|
509
|
+
(_a = (_b = acc.message).tool_calls) !== null && _a !== void 0 ? _a : (_b.tool_calls = []);
|
|
510
|
+
const toolCalls = acc.message.tool_calls;
|
|
511
|
+
cur.delta.tool_calls.forEach((toolCall) => {
|
|
512
|
+
var _a, _b, _c, _d, _e;
|
|
513
|
+
const existingToolCall = toolCalls[toolCall.index];
|
|
514
|
+
if (existingToolCall != null) {
|
|
515
|
+
toolCalls[toolCall.index] = mergeToolCalls(existingToolCall, toolCall);
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
toolCalls[toolCall.index] = {
|
|
519
|
+
id: (_a = toolCall.id) !== null && _a !== void 0 ? _a : "",
|
|
520
|
+
type: "function",
|
|
521
|
+
function: {
|
|
522
|
+
name: (_c = (_b = toolCall.function) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : "",
|
|
523
|
+
arguments: (_e = (_d = toolCall.function) === null || _d === void 0 ? void 0 : _d.arguments) !== null && _e !== void 0 ? _e : "",
|
|
524
|
+
},
|
|
525
|
+
};
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
return acc;
|
|
529
|
+
}
|
|
530
|
+
function mergeToolCalls(acc, cur) {
|
|
531
|
+
var _a, _b, _c;
|
|
532
|
+
if (cur.function != null) {
|
|
533
|
+
acc.function.arguments += (_a = cur.function.arguments) !== null && _a !== void 0 ? _a : "";
|
|
534
|
+
acc.function.name += (_b = cur.function.name) !== null && _b !== void 0 ? _b : "";
|
|
535
|
+
}
|
|
536
|
+
acc.id += (_c = cur.id) !== null && _c !== void 0 ? _c : "";
|
|
537
|
+
return acc;
|
|
538
|
+
}
|
|
539
|
+
exports.ChatGptCompletionMessageUtil = {
|
|
540
|
+
transformCompletionChunk,
|
|
541
|
+
accumulate,
|
|
542
|
+
merge,
|
|
543
|
+
mergeChoice,
|
|
544
|
+
mergeToolCalls,
|
|
545
|
+
};
|
|
536
546
|
//# sourceMappingURL=ChatGptCompletionMessageUtil.js.map
|