@agentica/core 0.15.5 → 0.15.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/README.md +0 -1
- package/lib/Agentica.js +6 -6
- package/lib/Agentica.js.map +1 -1
- package/lib/constants/AgenticaDefaultPrompt.js +4 -2
- package/lib/constants/AgenticaDefaultPrompt.js.map +1 -1
- package/lib/context/internal/AgenticaOperationComposer.d.ts +1 -1
- package/lib/context/internal/AgenticaOperationComposer.js.map +1 -1
- package/lib/context/internal/AgenticaTokenUsageAggregator.js.map +1 -1
- package/lib/events/AgenticaValidateEvent.d.ts +1 -1
- package/lib/factory/events.d.ts +3 -3
- package/lib/factory/events.js.map +1 -1
- package/lib/factory/operations.js.map +1 -1
- package/lib/factory/prompts.d.ts +6 -6
- package/lib/factory/prompts.js.map +1 -1
- package/lib/functional/assertHttpLlmApplication.js +16 -16
- package/lib/functional/assertHttpLlmApplication.js.map +1 -1
- package/lib/functional/validateHttpLlmApplication.js +13 -13
- package/lib/functional/validateHttpLlmApplication.js.map +1 -1
- package/lib/index.mjs +1714 -1714
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/call.js +2 -2
- package/lib/orchestrate/call.js.map +1 -1
- package/lib/orchestrate/cancel.d.ts +1 -1
- package/lib/orchestrate/cancel.js +2 -2
- package/lib/orchestrate/cancel.js.map +1 -1
- package/lib/orchestrate/describe.d.ts +1 -1
- package/lib/orchestrate/describe.js +3 -3
- package/lib/orchestrate/describe.js.map +1 -1
- package/lib/orchestrate/execute.js +3 -3
- package/lib/orchestrate/execute.js.map +1 -1
- package/lib/orchestrate/initialize.js +21 -21
- package/lib/orchestrate/initialize.js.map +1 -1
- package/lib/orchestrate/internal/cancelFunction.js.map +1 -1
- package/lib/orchestrate/internal/selectFunction.js +1 -1
- package/lib/orchestrate/internal/selectFunction.js.map +1 -1
- package/lib/orchestrate/select.js +4 -4
- package/lib/orchestrate/select.js.map +1 -1
- package/lib/transformers/AgenticaEventTransformer.d.ts +2 -2
- package/lib/transformers/AgenticaEventTransformer.js +1 -1
- package/lib/transformers/AgenticaEventTransformer.js.map +1 -1
- package/lib/transformers/AgenticaPromptTransformer.d.ts +3 -3
- package/lib/transformers/AgenticaPromptTransformer.js +1 -1
- package/lib/transformers/AgenticaPromptTransformer.js.map +1 -1
- package/lib/utils/ChatGptCompletionMessageUtil.js.map +1 -1
- package/package.json +1 -1
- package/src/Agentica.ts +9 -8
- package/src/constants/AgenticaDefaultPrompt.ts +6 -2
- package/src/context/AgenticaCancelPrompt.ts +2 -0
- package/src/context/AgenticaContext.ts +2 -0
- package/src/context/AgenticaOperation.ts +1 -0
- package/src/context/AgenticaOperationCollection.ts +1 -0
- package/src/context/AgenticaOperationSelection.ts +2 -0
- package/src/context/internal/AgenticaOperationComposer.ts +3 -2
- package/src/context/internal/AgenticaTokenUsageAggregator.ts +1 -0
- package/src/events/AgenticaCallEvent.ts +2 -0
- package/src/events/AgenticaCancelEvent.ts +2 -0
- package/src/events/AgenticaDescribeEvent.ts +1 -0
- package/src/events/AgenticaEvent.ts +1 -0
- package/src/events/AgenticaExecuteEvent.ts +2 -0
- package/src/events/AgenticaInitializeEvent.ts +1 -0
- package/src/events/AgenticaSelectEvent.ts +2 -0
- package/src/events/AgenticaTextEvent.ts +1 -0
- package/src/events/AgenticaValidateEvent.ts +3 -1
- package/src/factory/events.ts +6 -5
- package/src/factory/operations.ts +1 -0
- package/src/factory/prompts.ts +7 -6
- package/src/functional/assertHttpLlmApplication.ts +1 -0
- package/src/functional/validateHttpLlmApplication.ts +1 -0
- package/src/json/IAgenticaEventJson.ts +2 -0
- package/src/orchestrate/call.ts +12 -10
- package/src/orchestrate/cancel.ts +9 -7
- package/src/orchestrate/describe.ts +5 -4
- package/src/orchestrate/execute.ts +4 -3
- package/src/orchestrate/initialize.ts +6 -5
- package/src/orchestrate/internal/cancelFunction.ts +2 -1
- package/src/orchestrate/internal/selectFunction.ts +2 -1
- package/src/orchestrate/select.ts +10 -8
- package/src/prompts/AgenticaCancelPrompt.ts +2 -0
- package/src/prompts/AgenticaDescribePrompt.ts +2 -0
- package/src/prompts/AgenticaExecutePrompt.ts +2 -0
- package/src/prompts/AgenticaPrompt.ts +2 -0
- package/src/prompts/AgenticaSelectPrompt.ts +2 -0
- package/src/prompts/AgenticaTextPrompt.ts +1 -0
- package/src/structures/IAgenticaConfig.ts +1 -0
- package/src/structures/IAgenticaProps.ts +1 -0
- package/src/structures/IAgenticaSystemPrompt.ts +1 -0
- package/src/transformers/AgenticaEventTransformer.ts +4 -3
- package/src/transformers/AgenticaPromptTransformer.ts +5 -4
- package/src/utils/ChatGptCompletionMessageUtil.ts +2 -2
package/lib/index.mjs
CHANGED
|
@@ -1,1487 +1,1501 @@
|
|
|
1
|
-
import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard.js";
|
|
2
|
-
|
|
3
1
|
import "typia";
|
|
4
2
|
|
|
5
3
|
import { v4 } from "uuid";
|
|
6
4
|
|
|
7
|
-
import * as __typia_transform__validateReport from "typia/lib/internal/_validateReport.js";
|
|
8
|
-
|
|
9
5
|
import { HttpLlm, ChatGptTypeChecker, OpenApi } from "@samchon/openapi";
|
|
10
6
|
|
|
7
|
+
import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard.js";
|
|
8
|
+
|
|
9
|
+
import * as __typia_transform__validateReport from "typia/lib/internal/_validateReport.js";
|
|
10
|
+
|
|
11
11
|
import * as __typia_transform__accessExpressionAsString from "typia/lib/internal/_accessExpressionAsString.js";
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
class AgenticaTokenUsage {
|
|
14
|
+
constructor(props) {
|
|
15
|
+
if (props === undefined) {
|
|
16
|
+
const zero = AgenticaTokenUsage.zero();
|
|
17
|
+
this.aggregate = zero.aggregate;
|
|
18
|
+
this.initialize = zero.initialize;
|
|
19
|
+
this.select = zero.select;
|
|
20
|
+
this.cancel = zero.cancel;
|
|
21
|
+
this.call = zero.call;
|
|
22
|
+
this.describe = zero.describe;
|
|
23
|
+
} else {
|
|
24
|
+
this.aggregate = props.aggregate;
|
|
25
|
+
this.initialize = props.initialize;
|
|
26
|
+
this.select = props.select;
|
|
27
|
+
this.cancel = props.cancel;
|
|
28
|
+
this.call = props.call;
|
|
29
|
+
this.describe = props.describe;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
increment(y) {
|
|
33
|
+
const increment = (x, y) => {
|
|
34
|
+
x.total += y.total;
|
|
35
|
+
x.input.total += y.input.total;
|
|
36
|
+
x.input.cached += y.input.cached;
|
|
37
|
+
x.output.total += y.output.total;
|
|
38
|
+
x.output.reasoning += y.output.reasoning;
|
|
39
|
+
x.output.accepted_prediction += y.output.accepted_prediction;
|
|
40
|
+
x.output.rejected_prediction += y.output.rejected_prediction;
|
|
41
|
+
};
|
|
42
|
+
increment(this.aggregate, y.aggregate);
|
|
43
|
+
increment(this.initialize, y.initialize);
|
|
44
|
+
increment(this.select, y.select);
|
|
45
|
+
increment(this.cancel, y.cancel);
|
|
46
|
+
increment(this.call, y.call);
|
|
47
|
+
increment(this.describe, y.describe);
|
|
48
|
+
}
|
|
49
|
+
toJSON() {
|
|
50
|
+
return (() => {
|
|
51
|
+
const _co0 = input => ({
|
|
52
|
+
aggregate: _co1(input.aggregate),
|
|
53
|
+
initialize: _co1(input.initialize),
|
|
54
|
+
select: _co1(input.select),
|
|
55
|
+
cancel: _co1(input.cancel),
|
|
56
|
+
call: _co1(input.call),
|
|
57
|
+
describe: _co1(input.describe)
|
|
58
|
+
});
|
|
59
|
+
const _co1 = input => ({
|
|
60
|
+
total: input.total,
|
|
61
|
+
input: _co2(input.input),
|
|
62
|
+
output: _co3(input.output)
|
|
63
|
+
});
|
|
64
|
+
const _co2 = input => ({
|
|
65
|
+
total: input.total,
|
|
66
|
+
cached: input.cached
|
|
67
|
+
});
|
|
68
|
+
const _co3 = input => ({
|
|
69
|
+
total: input.total,
|
|
70
|
+
reasoning: input.reasoning,
|
|
71
|
+
accepted_prediction: input.accepted_prediction,
|
|
72
|
+
rejected_prediction: input.rejected_prediction
|
|
73
|
+
});
|
|
74
|
+
return input => _co0(input);
|
|
75
|
+
})()(this);
|
|
76
|
+
}
|
|
77
|
+
static zero() {
|
|
78
|
+
const component = () => ({
|
|
79
|
+
total: 0,
|
|
80
|
+
input: {
|
|
81
|
+
total: 0,
|
|
82
|
+
cached: 0
|
|
83
|
+
},
|
|
84
|
+
output: {
|
|
85
|
+
total: 0,
|
|
86
|
+
reasoning: 0,
|
|
87
|
+
accepted_prediction: 0,
|
|
88
|
+
rejected_prediction: 0
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return new AgenticaTokenUsage({
|
|
92
|
+
aggregate: component(),
|
|
93
|
+
initialize: component(),
|
|
94
|
+
select: component(),
|
|
95
|
+
cancel: component(),
|
|
96
|
+
call: component(),
|
|
97
|
+
describe: component()
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
static plus(x, y) {
|
|
101
|
+
const z = new AgenticaTokenUsage(x);
|
|
102
|
+
z.increment(y.toJSON());
|
|
103
|
+
return z;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
14
106
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
107
|
+
function __map_take(dict, key, generator) {
|
|
108
|
+
const oldbie = dict.get(key);
|
|
109
|
+
if (oldbie !== undefined) {
|
|
110
|
+
return oldbie;
|
|
18
111
|
}
|
|
19
|
-
|
|
20
|
-
|
|
112
|
+
const value = generator();
|
|
113
|
+
dict.set(key, value);
|
|
114
|
+
return value;
|
|
115
|
+
}
|
|
21
116
|
|
|
22
|
-
function
|
|
117
|
+
function compose(props) {
|
|
118
|
+
const unique = props.controllers.length === 1 || (() => {
|
|
119
|
+
const names = props.controllers.map((controller => controller.application.functions.map((func => func.name)))).flat();
|
|
120
|
+
return new Set(names).size === names.length;
|
|
121
|
+
})();
|
|
122
|
+
const naming = (func, ci) => unique ? func : `_${ci}_${func}`;
|
|
123
|
+
const array = props.controllers.map(((controller, ci) => controller.protocol === "http" ? controller.application.functions.map((func => ({
|
|
124
|
+
protocol: "http",
|
|
125
|
+
controller,
|
|
126
|
+
function: func,
|
|
127
|
+
name: naming(func.name, ci),
|
|
128
|
+
toJSON: () => ({
|
|
129
|
+
protocol: "http",
|
|
130
|
+
controller: controller.name,
|
|
131
|
+
function: func.name,
|
|
132
|
+
name: naming(func.name, ci)
|
|
133
|
+
})
|
|
134
|
+
}))) : controller.application.functions.map((func => ({
|
|
135
|
+
protocol: "class",
|
|
136
|
+
controller,
|
|
137
|
+
function: func,
|
|
138
|
+
name: naming(func.name, ci),
|
|
139
|
+
toJSON: () => ({
|
|
140
|
+
protocol: "class",
|
|
141
|
+
controller: controller.name,
|
|
142
|
+
function: func.name,
|
|
143
|
+
name: naming(func.name, ci)
|
|
144
|
+
})
|
|
145
|
+
}))))).flat();
|
|
146
|
+
const divided = props.config?.capacity !== undefined && array.length > props.config.capacity ? divide({
|
|
147
|
+
array,
|
|
148
|
+
capacity: props.config.capacity
|
|
149
|
+
}) : undefined;
|
|
150
|
+
const flat = new Map;
|
|
151
|
+
const group = new Map;
|
|
152
|
+
for (const item of array) {
|
|
153
|
+
flat.set(item.name, item);
|
|
154
|
+
__map_take(group, item.controller.name, (() => new Map)).set(item.name, item);
|
|
155
|
+
}
|
|
23
156
|
return {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
157
|
+
array,
|
|
158
|
+
divided,
|
|
159
|
+
flat,
|
|
160
|
+
group
|
|
27
161
|
};
|
|
28
162
|
}
|
|
29
163
|
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
164
|
+
function divide(props) {
|
|
165
|
+
const size = Math.ceil(props.array.length / props.capacity);
|
|
166
|
+
const capacity = Math.ceil(props.array.length / size);
|
|
167
|
+
const replica = props.array.slice();
|
|
168
|
+
return Array.from({
|
|
169
|
+
length: size
|
|
170
|
+
}, (() => replica.splice(0, capacity)));
|
|
35
171
|
}
|
|
36
172
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
173
|
+
const AgenticaOperationComposer = {
|
|
174
|
+
compose
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
function aggregate(props) {
|
|
178
|
+
const component = props.usage[props.kind];
|
|
179
|
+
component.total += props.completionUsage.total_tokens;
|
|
180
|
+
component.input.total += props.completionUsage.prompt_tokens;
|
|
181
|
+
component.input.total += props.completionUsage.prompt_tokens_details?.audio_tokens ?? 0;
|
|
182
|
+
component.input.cached += props.completionUsage.prompt_tokens_details?.cached_tokens ?? 0;
|
|
183
|
+
component.output.total += props.completionUsage.completion_tokens;
|
|
184
|
+
component.output.accepted_prediction += props.completionUsage.completion_tokens_details?.accepted_prediction_tokens ?? 0;
|
|
185
|
+
component.output.reasoning += props.completionUsage.completion_tokens_details?.reasoning_tokens ?? 0;
|
|
186
|
+
component.output.rejected_prediction += props.completionUsage.completion_tokens_details?.rejected_prediction_tokens ?? 0;
|
|
187
|
+
const sum = getter => Object.entries(props.usage).filter((([key]) => key !== "aggregate")).map((([, comp]) => getter(comp))).reduce(((a, b) => a + b), 0);
|
|
188
|
+
const aggregate = props.usage.aggregate;
|
|
189
|
+
aggregate.total = sum((comp => comp.total));
|
|
190
|
+
aggregate.input.total = sum((comp => comp.input.total));
|
|
191
|
+
aggregate.input.cached = sum((comp => comp.input.cached));
|
|
192
|
+
aggregate.output.total = sum((comp => comp.output.total));
|
|
193
|
+
aggregate.output.reasoning = sum((comp => comp.output.reasoning));
|
|
194
|
+
aggregate.output.accepted_prediction = sum((comp => comp.output.accepted_prediction));
|
|
195
|
+
aggregate.output.rejected_prediction = sum((comp => comp.output.rejected_prediction));
|
|
59
196
|
}
|
|
60
197
|
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
sumCompletionTokenDetail,
|
|
64
|
-
sumPromptTokenDetail
|
|
198
|
+
const AgenticaTokenUsageAggregator = {
|
|
199
|
+
aggregate
|
|
65
200
|
};
|
|
66
201
|
|
|
67
|
-
function
|
|
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
|
-
expected: "Array<ChatCompletionChunk.Choice>",
|
|
106
|
-
value: input.choices
|
|
107
|
-
}, _errorFactory)) && ("number" === typeof input.created || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
108
|
-
method: "json.assertParse",
|
|
109
|
-
path: _path + ".created",
|
|
110
|
-
expected: "number",
|
|
111
|
-
value: input.created
|
|
112
|
-
}, _errorFactory)) && ("string" === typeof input.model || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
113
|
-
method: "json.assertParse",
|
|
114
|
-
path: _path + ".model",
|
|
115
|
-
expected: "string",
|
|
116
|
-
value: input.model
|
|
117
|
-
}, _errorFactory)) && ("chat.completion.chunk" === input.object || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
118
|
-
method: "json.assertParse",
|
|
119
|
-
path: _path + ".object",
|
|
120
|
-
expected: '"chat.completion.chunk"',
|
|
121
|
-
value: input.object
|
|
122
|
-
}, _errorFactory)) && (null === input.service_tier || undefined === input.service_tier || "scale" === input.service_tier || "default" === input.service_tier || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
123
|
-
method: "json.assertParse",
|
|
124
|
-
path: _path + ".service_tier",
|
|
125
|
-
expected: '("default" | "scale" | null | undefined)',
|
|
126
|
-
value: input.service_tier
|
|
127
|
-
}, _errorFactory)) && (undefined === input.system_fingerprint || "string" === typeof input.system_fingerprint || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
128
|
-
method: "json.assertParse",
|
|
129
|
-
path: _path + ".system_fingerprint",
|
|
130
|
-
expected: "(string | undefined)",
|
|
131
|
-
value: input.system_fingerprint
|
|
132
|
-
}, _errorFactory)) && (null === input.usage || undefined === input.usage || ("object" === typeof input.usage && null !== input.usage || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
133
|
-
method: "json.assertParse",
|
|
134
|
-
path: _path + ".usage",
|
|
135
|
-
expected: "(CompletionUsage | null | undefined)",
|
|
136
|
-
value: input.usage
|
|
137
|
-
}, _errorFactory)) && _ao9(input.usage, _path + ".usage", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
138
|
-
method: "json.assertParse",
|
|
139
|
-
path: _path + ".usage",
|
|
140
|
-
expected: "(CompletionUsage | null | undefined)",
|
|
141
|
-
value: input.usage
|
|
142
|
-
}, _errorFactory));
|
|
143
|
-
const _ao1 = (input, _path, _exceptionable = true) => (("object" === typeof input.delta && null !== input.delta && false === Array.isArray(input.delta) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
144
|
-
method: "json.assertParse",
|
|
145
|
-
path: _path + ".delta",
|
|
146
|
-
expected: "ChatCompletionChunk.Choice.Delta",
|
|
147
|
-
value: input.delta
|
|
148
|
-
}, _errorFactory)) && _ao2(input.delta, _path + ".delta", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
149
|
-
method: "json.assertParse",
|
|
150
|
-
path: _path + ".delta",
|
|
151
|
-
expected: "ChatCompletionChunk.Choice.Delta",
|
|
152
|
-
value: input.delta
|
|
153
|
-
}, _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, {
|
|
154
|
-
method: "json.assertParse",
|
|
155
|
-
path: _path + ".finish_reason",
|
|
156
|
-
expected: '("content_filter" | "function_call" | "length" | "stop" | "tool_calls" | null)',
|
|
157
|
-
value: input.finish_reason
|
|
158
|
-
}, _errorFactory)) && ("number" === typeof input.index || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
159
|
-
method: "json.assertParse",
|
|
160
|
-
path: _path + ".index",
|
|
161
|
-
expected: "number",
|
|
162
|
-
value: input.index
|
|
163
|
-
}, _errorFactory)) && (null === input.logprobs || undefined === input.logprobs || ("object" === typeof input.logprobs && null !== input.logprobs || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
164
|
-
method: "json.assertParse",
|
|
165
|
-
path: _path + ".logprobs",
|
|
166
|
-
expected: "(ChatCompletionChunk.Choice.Logprobs | null | undefined)",
|
|
167
|
-
value: input.logprobs
|
|
168
|
-
}, _errorFactory)) && _ao6(input.logprobs, _path + ".logprobs", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
169
|
-
method: "json.assertParse",
|
|
170
|
-
path: _path + ".logprobs",
|
|
171
|
-
expected: "(ChatCompletionChunk.Choice.Logprobs | null | undefined)",
|
|
172
|
-
value: input.logprobs
|
|
173
|
-
}, _errorFactory));
|
|
174
|
-
const _ao2 = (input, _path, _exceptionable = true) => (null === input.content || undefined === input.content || "string" === typeof input.content || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
175
|
-
method: "json.assertParse",
|
|
176
|
-
path: _path + ".content",
|
|
177
|
-
expected: "(null | string | undefined)",
|
|
178
|
-
value: input.content
|
|
179
|
-
}, _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, {
|
|
180
|
-
method: "json.assertParse",
|
|
181
|
-
path: _path + ".function_call",
|
|
182
|
-
expected: "(ChatCompletionChunk.Choice.Delta.FunctionCall | undefined)",
|
|
183
|
-
value: input.function_call
|
|
184
|
-
}, _errorFactory)) && _ao3(input.function_call, _path + ".function_call", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
185
|
-
method: "json.assertParse",
|
|
186
|
-
path: _path + ".function_call",
|
|
187
|
-
expected: "(ChatCompletionChunk.Choice.Delta.FunctionCall | undefined)",
|
|
188
|
-
value: input.function_call
|
|
189
|
-
}, _errorFactory)) && (null === input.refusal || undefined === input.refusal || "string" === typeof input.refusal || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
190
|
-
method: "json.assertParse",
|
|
191
|
-
path: _path + ".refusal",
|
|
192
|
-
expected: "(null | string | undefined)",
|
|
193
|
-
value: input.refusal
|
|
194
|
-
}, _errorFactory)) && (undefined === input.role || "assistant" === input.role || "user" === input.role || "developer" === input.role || "system" === input.role || "tool" === input.role || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
195
|
-
method: "json.assertParse",
|
|
196
|
-
path: _path + ".role",
|
|
197
|
-
expected: '("assistant" | "developer" | "system" | "tool" | "user" | undefined)',
|
|
198
|
-
value: input.role
|
|
199
|
-
}, _errorFactory)) && (undefined === input.tool_calls || (Array.isArray(input.tool_calls) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
200
|
-
method: "json.assertParse",
|
|
201
|
-
path: _path + ".tool_calls",
|
|
202
|
-
expected: "(Array<ChatCompletionChunk.Choice.Delta.ToolCall> | undefined)",
|
|
203
|
-
value: input.tool_calls
|
|
204
|
-
}, _errorFactory)) && input.tool_calls.every(((elem, _index9) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
205
|
-
method: "json.assertParse",
|
|
206
|
-
path: _path + ".tool_calls[" + _index9 + "]",
|
|
207
|
-
expected: "ChatCompletionChunk.Choice.Delta.ToolCall",
|
|
208
|
-
value: elem
|
|
209
|
-
}, _errorFactory)) && _ao4(elem, _path + ".tool_calls[" + _index9 + "]", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
210
|
-
method: "json.assertParse",
|
|
211
|
-
path: _path + ".tool_calls[" + _index9 + "]",
|
|
212
|
-
expected: "ChatCompletionChunk.Choice.Delta.ToolCall",
|
|
213
|
-
value: elem
|
|
214
|
-
}, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
215
|
-
method: "json.assertParse",
|
|
216
|
-
path: _path + ".tool_calls",
|
|
217
|
-
expected: "(Array<ChatCompletionChunk.Choice.Delta.ToolCall> | undefined)",
|
|
218
|
-
value: input.tool_calls
|
|
219
|
-
}, _errorFactory));
|
|
220
|
-
const _ao3 = (input, _path, _exceptionable = true) => (undefined === input.arguments || "string" === typeof input.arguments || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
221
|
-
method: "json.assertParse",
|
|
222
|
-
path: _path + ".arguments",
|
|
223
|
-
expected: "(string | undefined)",
|
|
224
|
-
value: input.arguments
|
|
225
|
-
}, _errorFactory)) && (undefined === input.name || "string" === typeof input.name || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
226
|
-
method: "json.assertParse",
|
|
227
|
-
path: _path + ".name",
|
|
228
|
-
expected: "(string | undefined)",
|
|
229
|
-
value: input.name
|
|
230
|
-
}, _errorFactory));
|
|
231
|
-
const _ao4 = (input, _path, _exceptionable = true) => ("number" === typeof input.index || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
232
|
-
method: "json.assertParse",
|
|
233
|
-
path: _path + ".index",
|
|
234
|
-
expected: "number",
|
|
235
|
-
value: input.index
|
|
236
|
-
}, _errorFactory)) && (undefined === input.id || "string" === typeof input.id || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
237
|
-
method: "json.assertParse",
|
|
238
|
-
path: _path + ".id",
|
|
239
|
-
expected: "(string | undefined)",
|
|
240
|
-
value: input.id
|
|
241
|
-
}, _errorFactory)) && (undefined === input["function"] || ("object" === typeof input["function"] && null !== input["function"] && false === Array.isArray(input["function"]) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
242
|
-
method: "json.assertParse",
|
|
243
|
-
path: _path + '["function"]',
|
|
244
|
-
expected: "(ChatCompletionChunk.Choice.Delta.ToolCall.Function | undefined)",
|
|
245
|
-
value: input["function"]
|
|
246
|
-
}, _errorFactory)) && _ao5(input["function"], _path + '["function"]', _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
247
|
-
method: "json.assertParse",
|
|
248
|
-
path: _path + '["function"]',
|
|
249
|
-
expected: "(ChatCompletionChunk.Choice.Delta.ToolCall.Function | undefined)",
|
|
250
|
-
value: input["function"]
|
|
251
|
-
}, _errorFactory)) && (undefined === input.type || "function" === input.type || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
252
|
-
method: "json.assertParse",
|
|
253
|
-
path: _path + ".type",
|
|
254
|
-
expected: '("function" | undefined)',
|
|
255
|
-
value: input.type
|
|
256
|
-
}, _errorFactory));
|
|
257
|
-
const _ao5 = (input, _path, _exceptionable = true) => (undefined === input.arguments || "string" === typeof input.arguments || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
258
|
-
method: "json.assertParse",
|
|
259
|
-
path: _path + ".arguments",
|
|
260
|
-
expected: "(string | undefined)",
|
|
261
|
-
value: input.arguments
|
|
262
|
-
}, _errorFactory)) && (undefined === input.name || "string" === typeof input.name || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
263
|
-
method: "json.assertParse",
|
|
264
|
-
path: _path + ".name",
|
|
265
|
-
expected: "(string | undefined)",
|
|
266
|
-
value: input.name
|
|
267
|
-
}, _errorFactory));
|
|
268
|
-
const _ao6 = (input, _path, _exceptionable = true) => (null === input.content || (Array.isArray(input.content) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
269
|
-
method: "json.assertParse",
|
|
270
|
-
path: _path + ".content",
|
|
271
|
-
expected: "(Array<ChatCompletionTokenLogprob> | null)",
|
|
272
|
-
value: input.content
|
|
273
|
-
}, _errorFactory)) && input.content.every(((elem, _index10) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
274
|
-
method: "json.assertParse",
|
|
275
|
-
path: _path + ".content[" + _index10 + "]",
|
|
276
|
-
expected: "ChatCompletionTokenLogprob",
|
|
277
|
-
value: elem
|
|
278
|
-
}, _errorFactory)) && _ao7(elem, _path + ".content[" + _index10 + "]", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
279
|
-
method: "json.assertParse",
|
|
280
|
-
path: _path + ".content[" + _index10 + "]",
|
|
281
|
-
expected: "ChatCompletionTokenLogprob",
|
|
282
|
-
value: elem
|
|
283
|
-
}, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
284
|
-
method: "json.assertParse",
|
|
285
|
-
path: _path + ".content",
|
|
286
|
-
expected: "(Array<ChatCompletionTokenLogprob> | null)",
|
|
287
|
-
value: input.content
|
|
288
|
-
}, _errorFactory)) && (null === input.refusal || (Array.isArray(input.refusal) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
289
|
-
method: "json.assertParse",
|
|
290
|
-
path: _path + ".refusal",
|
|
291
|
-
expected: "(Array<ChatCompletionTokenLogprob> | null)",
|
|
292
|
-
value: input.refusal
|
|
293
|
-
}, _errorFactory)) && input.refusal.every(((elem, _index11) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
294
|
-
method: "json.assertParse",
|
|
295
|
-
path: _path + ".refusal[" + _index11 + "]",
|
|
296
|
-
expected: "ChatCompletionTokenLogprob",
|
|
297
|
-
value: elem
|
|
298
|
-
}, _errorFactory)) && _ao7(elem, _path + ".refusal[" + _index11 + "]", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
299
|
-
method: "json.assertParse",
|
|
300
|
-
path: _path + ".refusal[" + _index11 + "]",
|
|
301
|
-
expected: "ChatCompletionTokenLogprob",
|
|
302
|
-
value: elem
|
|
303
|
-
}, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
304
|
-
method: "json.assertParse",
|
|
305
|
-
path: _path + ".refusal",
|
|
306
|
-
expected: "(Array<ChatCompletionTokenLogprob> | null)",
|
|
307
|
-
value: input.refusal
|
|
308
|
-
}, _errorFactory));
|
|
309
|
-
const _ao7 = (input, _path, _exceptionable = true) => ("string" === typeof input.token || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
310
|
-
method: "json.assertParse",
|
|
311
|
-
path: _path + ".token",
|
|
312
|
-
expected: "string",
|
|
313
|
-
value: input.token
|
|
314
|
-
}, _errorFactory)) && (null === input.bytes || (Array.isArray(input.bytes) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
315
|
-
method: "json.assertParse",
|
|
316
|
-
path: _path + ".bytes",
|
|
317
|
-
expected: "(Array<number> | null)",
|
|
318
|
-
value: input.bytes
|
|
319
|
-
}, _errorFactory)) && input.bytes.every(((elem, _index12) => "number" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
320
|
-
method: "json.assertParse",
|
|
321
|
-
path: _path + ".bytes[" + _index12 + "]",
|
|
322
|
-
expected: "number",
|
|
323
|
-
value: elem
|
|
324
|
-
}, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
325
|
-
method: "json.assertParse",
|
|
326
|
-
path: _path + ".bytes",
|
|
327
|
-
expected: "(Array<number> | null)",
|
|
328
|
-
value: input.bytes
|
|
329
|
-
}, _errorFactory)) && ("number" === typeof input.logprob || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
330
|
-
method: "json.assertParse",
|
|
331
|
-
path: _path + ".logprob",
|
|
332
|
-
expected: "number",
|
|
333
|
-
value: input.logprob
|
|
334
|
-
}, _errorFactory)) && ((Array.isArray(input.top_logprobs) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
335
|
-
method: "json.assertParse",
|
|
336
|
-
path: _path + ".top_logprobs",
|
|
337
|
-
expected: "Array<ChatCompletionTokenLogprob.TopLogprob>",
|
|
338
|
-
value: input.top_logprobs
|
|
339
|
-
}, _errorFactory)) && input.top_logprobs.every(((elem, _index13) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
340
|
-
method: "json.assertParse",
|
|
341
|
-
path: _path + ".top_logprobs[" + _index13 + "]",
|
|
342
|
-
expected: "ChatCompletionTokenLogprob.TopLogprob",
|
|
343
|
-
value: elem
|
|
344
|
-
}, _errorFactory)) && _ao8(elem, _path + ".top_logprobs[" + _index13 + "]", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
345
|
-
method: "json.assertParse",
|
|
346
|
-
path: _path + ".top_logprobs[" + _index13 + "]",
|
|
347
|
-
expected: "ChatCompletionTokenLogprob.TopLogprob",
|
|
348
|
-
value: elem
|
|
349
|
-
}, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
350
|
-
method: "json.assertParse",
|
|
351
|
-
path: _path + ".top_logprobs",
|
|
352
|
-
expected: "Array<ChatCompletionTokenLogprob.TopLogprob>",
|
|
353
|
-
value: input.top_logprobs
|
|
354
|
-
}, _errorFactory));
|
|
355
|
-
const _ao8 = (input, _path, _exceptionable = true) => ("string" === typeof input.token || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
356
|
-
method: "json.assertParse",
|
|
357
|
-
path: _path + ".token",
|
|
358
|
-
expected: "string",
|
|
359
|
-
value: input.token
|
|
360
|
-
}, _errorFactory)) && (null === input.bytes || (Array.isArray(input.bytes) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
361
|
-
method: "json.assertParse",
|
|
362
|
-
path: _path + ".bytes",
|
|
363
|
-
expected: "(Array<number> | null)",
|
|
364
|
-
value: input.bytes
|
|
365
|
-
}, _errorFactory)) && input.bytes.every(((elem, _index14) => "number" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
366
|
-
method: "json.assertParse",
|
|
367
|
-
path: _path + ".bytes[" + _index14 + "]",
|
|
368
|
-
expected: "number",
|
|
369
|
-
value: elem
|
|
370
|
-
}, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
371
|
-
method: "json.assertParse",
|
|
372
|
-
path: _path + ".bytes",
|
|
373
|
-
expected: "(Array<number> | null)",
|
|
374
|
-
value: input.bytes
|
|
375
|
-
}, _errorFactory)) && ("number" === typeof input.logprob || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
376
|
-
method: "json.assertParse",
|
|
377
|
-
path: _path + ".logprob",
|
|
378
|
-
expected: "number",
|
|
379
|
-
value: input.logprob
|
|
380
|
-
}, _errorFactory));
|
|
381
|
-
const _ao9 = (input, _path, _exceptionable = true) => ("number" === typeof input.completion_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
382
|
-
method: "json.assertParse",
|
|
383
|
-
path: _path + ".completion_tokens",
|
|
384
|
-
expected: "number",
|
|
385
|
-
value: input.completion_tokens
|
|
386
|
-
}, _errorFactory)) && ("number" === typeof input.prompt_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
387
|
-
method: "json.assertParse",
|
|
388
|
-
path: _path + ".prompt_tokens",
|
|
389
|
-
expected: "number",
|
|
390
|
-
value: input.prompt_tokens
|
|
391
|
-
}, _errorFactory)) && ("number" === typeof input.total_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
392
|
-
method: "json.assertParse",
|
|
393
|
-
path: _path + ".total_tokens",
|
|
394
|
-
expected: "number",
|
|
395
|
-
value: input.total_tokens
|
|
396
|
-
}, _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, {
|
|
397
|
-
method: "json.assertParse",
|
|
398
|
-
path: _path + ".completion_tokens_details",
|
|
399
|
-
expected: "(CompletionUsage.CompletionTokensDetails | undefined)",
|
|
400
|
-
value: input.completion_tokens_details
|
|
401
|
-
}, _errorFactory)) && _ao10(input.completion_tokens_details, _path + ".completion_tokens_details", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
402
|
-
method: "json.assertParse",
|
|
403
|
-
path: _path + ".completion_tokens_details",
|
|
404
|
-
expected: "(CompletionUsage.CompletionTokensDetails | undefined)",
|
|
405
|
-
value: input.completion_tokens_details
|
|
406
|
-
}, _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, {
|
|
407
|
-
method: "json.assertParse",
|
|
408
|
-
path: _path + ".prompt_tokens_details",
|
|
409
|
-
expected: "(CompletionUsage.PromptTokensDetails | undefined)",
|
|
410
|
-
value: input.prompt_tokens_details
|
|
411
|
-
}, _errorFactory)) && _ao11(input.prompt_tokens_details, _path + ".prompt_tokens_details", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
412
|
-
method: "json.assertParse",
|
|
413
|
-
path: _path + ".prompt_tokens_details",
|
|
414
|
-
expected: "(CompletionUsage.PromptTokensDetails | undefined)",
|
|
415
|
-
value: input.prompt_tokens_details
|
|
416
|
-
}, _errorFactory));
|
|
417
|
-
const _ao10 = (input, _path, _exceptionable = true) => (undefined === input.accepted_prediction_tokens || "number" === typeof input.accepted_prediction_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
418
|
-
method: "json.assertParse",
|
|
419
|
-
path: _path + ".accepted_prediction_tokens",
|
|
420
|
-
expected: "(number | undefined)",
|
|
421
|
-
value: input.accepted_prediction_tokens
|
|
422
|
-
}, _errorFactory)) && (undefined === input.audio_tokens || "number" === typeof input.audio_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
423
|
-
method: "json.assertParse",
|
|
424
|
-
path: _path + ".audio_tokens",
|
|
425
|
-
expected: "(number | undefined)",
|
|
426
|
-
value: input.audio_tokens
|
|
427
|
-
}, _errorFactory)) && (undefined === input.reasoning_tokens || "number" === typeof input.reasoning_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
428
|
-
method: "json.assertParse",
|
|
429
|
-
path: _path + ".reasoning_tokens",
|
|
430
|
-
expected: "(number | undefined)",
|
|
431
|
-
value: input.reasoning_tokens
|
|
432
|
-
}, _errorFactory)) && (undefined === input.rejected_prediction_tokens || "number" === typeof input.rejected_prediction_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
433
|
-
method: "json.assertParse",
|
|
434
|
-
path: _path + ".rejected_prediction_tokens",
|
|
435
|
-
expected: "(number | undefined)",
|
|
436
|
-
value: input.rejected_prediction_tokens
|
|
437
|
-
}, _errorFactory));
|
|
438
|
-
const _ao11 = (input, _path, _exceptionable = true) => (undefined === input.audio_tokens || "number" === typeof input.audio_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
439
|
-
method: "json.assertParse",
|
|
440
|
-
path: _path + ".audio_tokens",
|
|
441
|
-
expected: "(number | undefined)",
|
|
442
|
-
value: input.audio_tokens
|
|
443
|
-
}, _errorFactory)) && (undefined === input.cached_tokens || "number" === typeof input.cached_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
444
|
-
method: "json.assertParse",
|
|
445
|
-
path: _path + ".cached_tokens",
|
|
446
|
-
expected: "(number | undefined)",
|
|
447
|
-
value: input.cached_tokens
|
|
448
|
-
}, _errorFactory));
|
|
449
|
-
const __is = input => "object" === typeof input && null !== input && _io0(input);
|
|
450
|
-
let _errorFactory;
|
|
451
|
-
const __assert = (input, errorFactory) => {
|
|
452
|
-
if (false === __is(input)) {
|
|
453
|
-
_errorFactory = errorFactory;
|
|
454
|
-
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || __typia_transform__assertGuard._assertGuard(true, {
|
|
455
|
-
method: "json.assertParse",
|
|
456
|
-
path: _path + "",
|
|
457
|
-
expected: "ChatCompletionChunk & { usage: CompletionUsage | null | undefined; }",
|
|
458
|
-
value: input
|
|
459
|
-
}, _errorFactory)) && _ao0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
|
|
460
|
-
method: "json.assertParse",
|
|
461
|
-
path: _path + "",
|
|
462
|
-
expected: "ChatCompletionChunk & { usage: CompletionUsage | null | undefined; }",
|
|
463
|
-
value: input
|
|
464
|
-
}, _errorFactory))(input, "$input", true);
|
|
202
|
+
function decodePrompt(history) {
|
|
203
|
+
if (history.type === "describe") {
|
|
204
|
+
return [];
|
|
205
|
+
} else if (history.type === "text") {
|
|
206
|
+
return [ {
|
|
207
|
+
role: history.role,
|
|
208
|
+
content: history.text
|
|
209
|
+
} ];
|
|
210
|
+
} else if (history.type === "select" || history.type === "cancel") {
|
|
211
|
+
return [ {
|
|
212
|
+
role: "assistant",
|
|
213
|
+
tool_calls: [ {
|
|
214
|
+
type: "function",
|
|
215
|
+
id: history.id,
|
|
216
|
+
function: {
|
|
217
|
+
name: `${history.type}Functions`,
|
|
218
|
+
arguments: JSON.stringify({
|
|
219
|
+
functions: history.selections.map((s => ({
|
|
220
|
+
name: s.operation.function.name,
|
|
221
|
+
reason: s.reason
|
|
222
|
+
})))
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
} ]
|
|
226
|
+
}, {
|
|
227
|
+
role: "tool",
|
|
228
|
+
tool_call_id: history.id,
|
|
229
|
+
content: ""
|
|
230
|
+
} ];
|
|
231
|
+
}
|
|
232
|
+
return [ {
|
|
233
|
+
role: "assistant",
|
|
234
|
+
tool_calls: [ {
|
|
235
|
+
type: "function",
|
|
236
|
+
id: history.id,
|
|
237
|
+
function: {
|
|
238
|
+
name: history.operation.name,
|
|
239
|
+
arguments: JSON.stringify(history.arguments)
|
|
465
240
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
241
|
+
} ]
|
|
242
|
+
}, {
|
|
243
|
+
role: "tool",
|
|
244
|
+
tool_call_id: history.id,
|
|
245
|
+
content: JSON.stringify({
|
|
246
|
+
function: {
|
|
247
|
+
protocol: history.operation.protocol,
|
|
248
|
+
description: history.operation.function.description,
|
|
249
|
+
parameters: history.operation.function.parameters,
|
|
250
|
+
output: history.operation.function.output,
|
|
251
|
+
...history.operation.protocol === "http" ? {
|
|
252
|
+
method: history.operation.function.method,
|
|
253
|
+
path: history.operation.function.path
|
|
254
|
+
} : {}
|
|
255
|
+
},
|
|
256
|
+
...history.operation.protocol === "http" ? {
|
|
257
|
+
status: history.value.status,
|
|
258
|
+
data: history.value.body
|
|
259
|
+
} : {
|
|
260
|
+
value: history.value
|
|
261
|
+
}
|
|
262
|
+
})
|
|
263
|
+
} ];
|
|
470
264
|
}
|
|
471
265
|
|
|
472
|
-
function
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
return;
|
|
479
|
-
}
|
|
480
|
-
choices[choice.index] = {
|
|
481
|
-
index: choice.index,
|
|
482
|
-
finish_reason: choice.finish_reason ?? null,
|
|
483
|
-
logprobs: choice.logprobs ?? null,
|
|
484
|
-
message: {
|
|
485
|
-
tool_calls: choice.delta.tool_calls !== undefined ? choice.delta.tool_calls.reduce(((acc, cur) => {
|
|
486
|
-
acc[cur.index] = {
|
|
487
|
-
id: cur.id ?? "",
|
|
488
|
-
type: "function",
|
|
489
|
-
function: {
|
|
490
|
-
name: cur.function?.name ?? "",
|
|
491
|
-
arguments: cur.function?.arguments ?? ""
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
return acc;
|
|
495
|
-
}), []) : undefined,
|
|
496
|
-
content: choice.delta.content ?? null,
|
|
497
|
-
refusal: choice.delta.refusal ?? null,
|
|
498
|
-
role: "assistant"
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
}));
|
|
502
|
-
const usage = (() => {
|
|
503
|
-
if (chunk.usage == null) {
|
|
504
|
-
return origin.usage;
|
|
505
|
-
}
|
|
506
|
-
if (origin.usage == null) {
|
|
507
|
-
return chunk.usage;
|
|
508
|
-
}
|
|
509
|
-
return ChatGptTokenUsageAggregator.sum(origin.usage, chunk.usage);
|
|
510
|
-
})();
|
|
266
|
+
function createTextPrompt(props) {
|
|
267
|
+
const prompt = {
|
|
268
|
+
type: "text",
|
|
269
|
+
role: props.role,
|
|
270
|
+
text: props.text
|
|
271
|
+
};
|
|
511
272
|
return {
|
|
512
|
-
...
|
|
513
|
-
|
|
514
|
-
usage
|
|
273
|
+
...prompt,
|
|
274
|
+
toJSON: () => prompt
|
|
515
275
|
};
|
|
516
276
|
}
|
|
517
277
|
|
|
518
|
-
function
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
usage: undefined,
|
|
530
|
-
service_tier: firstChunk.service_tier,
|
|
531
|
-
system_fingerprint: firstChunk.system_fingerprint
|
|
532
|
-
});
|
|
278
|
+
function createDescribePrompt(props) {
|
|
279
|
+
return {
|
|
280
|
+
type: "describe",
|
|
281
|
+
text: props.text,
|
|
282
|
+
executes: props.executes,
|
|
283
|
+
toJSON: () => ({
|
|
284
|
+
type: "describe",
|
|
285
|
+
text: props.text,
|
|
286
|
+
executes: props.executes.map((execute => execute.toJSON()))
|
|
287
|
+
})
|
|
288
|
+
};
|
|
533
289
|
}
|
|
534
290
|
|
|
535
|
-
function
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
291
|
+
function createSelectPrompt(props) {
|
|
292
|
+
return {
|
|
293
|
+
type: "select",
|
|
294
|
+
id: props.id,
|
|
295
|
+
selections: props.selections,
|
|
296
|
+
toJSON: () => ({
|
|
297
|
+
type: "select",
|
|
298
|
+
id: props.id,
|
|
299
|
+
selections: props.selections.map((selection => selection.toJSON()))
|
|
300
|
+
})
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function createCancelPrompt(props) {
|
|
305
|
+
return {
|
|
306
|
+
type: "cancel",
|
|
307
|
+
id: props.id,
|
|
308
|
+
selections: props.selections,
|
|
309
|
+
toJSON: () => ({
|
|
310
|
+
type: "cancel",
|
|
311
|
+
id: props.id,
|
|
312
|
+
selections: props.selections.map((selection => selection.toJSON()))
|
|
313
|
+
})
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function createExecutePrompt(props) {
|
|
318
|
+
return {
|
|
319
|
+
type: "execute",
|
|
320
|
+
protocol: props.operation.protocol,
|
|
321
|
+
id: props.id,
|
|
322
|
+
operation: props.operation,
|
|
323
|
+
arguments: props.arguments,
|
|
324
|
+
value: props.value,
|
|
325
|
+
toJSON: () => ({
|
|
326
|
+
type: "execute",
|
|
327
|
+
protocol: props.operation.protocol,
|
|
328
|
+
id: props.id,
|
|
329
|
+
operation: props.operation.toJSON(),
|
|
330
|
+
arguments: props.arguments,
|
|
331
|
+
value: props.value
|
|
332
|
+
})
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function createInitializeEvent() {
|
|
337
|
+
const event = {
|
|
338
|
+
type: "initialize"
|
|
339
|
+
};
|
|
340
|
+
return {
|
|
341
|
+
type: event.type,
|
|
342
|
+
toJSON: () => event
|
|
343
|
+
};
|
|
577
344
|
}
|
|
578
345
|
|
|
579
|
-
function
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
346
|
+
function createSelectEvent(props) {
|
|
347
|
+
return {
|
|
348
|
+
type: "select",
|
|
349
|
+
selection: props.selection,
|
|
350
|
+
toJSON: () => ({
|
|
351
|
+
type: "select",
|
|
352
|
+
selection: props.selection.toJSON()
|
|
353
|
+
}),
|
|
354
|
+
toPrompt: () => createSelectPrompt({
|
|
355
|
+
id: v4(),
|
|
356
|
+
selections: [ props.selection ]
|
|
357
|
+
})
|
|
358
|
+
};
|
|
586
359
|
}
|
|
587
360
|
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
constructor(props) {
|
|
598
|
-
if (props === undefined) {
|
|
599
|
-
const zero = AgenticaTokenUsage.zero();
|
|
600
|
-
this.aggregate = zero.aggregate;
|
|
601
|
-
this.initialize = zero.initialize;
|
|
602
|
-
this.select = zero.select;
|
|
603
|
-
this.cancel = zero.cancel;
|
|
604
|
-
this.call = zero.call;
|
|
605
|
-
this.describe = zero.describe;
|
|
606
|
-
} else {
|
|
607
|
-
this.aggregate = props.aggregate;
|
|
608
|
-
this.initialize = props.initialize;
|
|
609
|
-
this.select = props.select;
|
|
610
|
-
this.cancel = props.cancel;
|
|
611
|
-
this.call = props.call;
|
|
612
|
-
this.describe = props.describe;
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
increment(y) {
|
|
616
|
-
const increment = (x, y) => {
|
|
617
|
-
x.total += y.total;
|
|
618
|
-
x.input.total += y.input.total;
|
|
619
|
-
x.input.cached += y.input.cached;
|
|
620
|
-
x.output.total += y.output.total;
|
|
621
|
-
x.output.reasoning += y.output.reasoning;
|
|
622
|
-
x.output.accepted_prediction += y.output.accepted_prediction;
|
|
623
|
-
x.output.rejected_prediction += y.output.rejected_prediction;
|
|
624
|
-
};
|
|
625
|
-
increment(this.aggregate, y.aggregate);
|
|
626
|
-
increment(this.initialize, y.initialize);
|
|
627
|
-
increment(this.select, y.select);
|
|
628
|
-
increment(this.cancel, y.cancel);
|
|
629
|
-
increment(this.call, y.call);
|
|
630
|
-
increment(this.describe, y.describe);
|
|
631
|
-
}
|
|
632
|
-
toJSON() {
|
|
633
|
-
return (() => {
|
|
634
|
-
const _co0 = input => ({
|
|
635
|
-
aggregate: _co1(input.aggregate),
|
|
636
|
-
initialize: _co1(input.initialize),
|
|
637
|
-
select: _co1(input.select),
|
|
638
|
-
cancel: _co1(input.cancel),
|
|
639
|
-
call: _co1(input.call),
|
|
640
|
-
describe: _co1(input.describe)
|
|
641
|
-
});
|
|
642
|
-
const _co1 = input => ({
|
|
643
|
-
total: input.total,
|
|
644
|
-
input: _co2(input.input),
|
|
645
|
-
output: _co3(input.output)
|
|
646
|
-
});
|
|
647
|
-
const _co2 = input => ({
|
|
648
|
-
total: input.total,
|
|
649
|
-
cached: input.cached
|
|
650
|
-
});
|
|
651
|
-
const _co3 = input => ({
|
|
652
|
-
total: input.total,
|
|
653
|
-
reasoning: input.reasoning,
|
|
654
|
-
accepted_prediction: input.accepted_prediction,
|
|
655
|
-
rejected_prediction: input.rejected_prediction
|
|
656
|
-
});
|
|
657
|
-
return input => _co0(input);
|
|
658
|
-
})()(this);
|
|
659
|
-
}
|
|
660
|
-
static zero() {
|
|
661
|
-
const component = () => ({
|
|
662
|
-
total: 0,
|
|
663
|
-
input: {
|
|
664
|
-
total: 0,
|
|
665
|
-
cached: 0
|
|
666
|
-
},
|
|
667
|
-
output: {
|
|
668
|
-
total: 0,
|
|
669
|
-
reasoning: 0,
|
|
670
|
-
accepted_prediction: 0,
|
|
671
|
-
rejected_prediction: 0
|
|
672
|
-
}
|
|
673
|
-
});
|
|
674
|
-
return new AgenticaTokenUsage({
|
|
675
|
-
aggregate: component(),
|
|
676
|
-
initialize: component(),
|
|
677
|
-
select: component(),
|
|
678
|
-
cancel: component(),
|
|
679
|
-
call: component(),
|
|
680
|
-
describe: component()
|
|
681
|
-
});
|
|
682
|
-
}
|
|
683
|
-
static plus(x, y) {
|
|
684
|
-
const z = new AgenticaTokenUsage(x);
|
|
685
|
-
z.increment(y.toJSON());
|
|
686
|
-
return z;
|
|
687
|
-
}
|
|
361
|
+
function createCancelEvent(props) {
|
|
362
|
+
return {
|
|
363
|
+
type: "cancel",
|
|
364
|
+
selection: props.selection,
|
|
365
|
+
toJSON: () => ({
|
|
366
|
+
type: "cancel",
|
|
367
|
+
selection: props.selection.toJSON()
|
|
368
|
+
})
|
|
369
|
+
};
|
|
688
370
|
}
|
|
689
371
|
|
|
690
|
-
function
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
aggregate.input.total = sum((comp => comp.input.total));
|
|
704
|
-
aggregate.input.cached = sum((comp => comp.input.cached));
|
|
705
|
-
aggregate.output.total = sum((comp => comp.output.total));
|
|
706
|
-
aggregate.output.reasoning = sum((comp => comp.output.reasoning));
|
|
707
|
-
aggregate.output.accepted_prediction = sum((comp => comp.output.accepted_prediction));
|
|
708
|
-
aggregate.output.rejected_prediction = sum((comp => comp.output.rejected_prediction));
|
|
372
|
+
function createCallEvent(props) {
|
|
373
|
+
return {
|
|
374
|
+
type: "call",
|
|
375
|
+
id: props.id,
|
|
376
|
+
operation: props.operation,
|
|
377
|
+
arguments: props.arguments,
|
|
378
|
+
toJSON: () => ({
|
|
379
|
+
type: "call",
|
|
380
|
+
id: props.id,
|
|
381
|
+
operation: props.operation.toJSON(),
|
|
382
|
+
arguments: props.arguments
|
|
383
|
+
})
|
|
384
|
+
};
|
|
709
385
|
}
|
|
710
386
|
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
387
|
+
function createValidateEvent(props) {
|
|
388
|
+
return {
|
|
389
|
+
type: "validate",
|
|
390
|
+
id: props.id,
|
|
391
|
+
operation: props.operation,
|
|
392
|
+
result: props.result,
|
|
393
|
+
toJSON: () => ({
|
|
394
|
+
type: "validate",
|
|
395
|
+
id: props.id,
|
|
396
|
+
operation: props.operation.toJSON(),
|
|
397
|
+
result: props.result
|
|
398
|
+
})
|
|
399
|
+
};
|
|
400
|
+
}
|
|
714
401
|
|
|
715
|
-
function
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
402
|
+
function createExecuteEvent(props) {
|
|
403
|
+
return {
|
|
404
|
+
type: "execute",
|
|
405
|
+
protocol: props.operation.protocol,
|
|
406
|
+
id: props.id,
|
|
407
|
+
operation: props.operation,
|
|
408
|
+
arguments: props.arguments,
|
|
409
|
+
value: props.value,
|
|
410
|
+
toJSON: () => ({
|
|
411
|
+
type: "execute",
|
|
412
|
+
protocol: props.operation.protocol,
|
|
413
|
+
id: props.id,
|
|
414
|
+
operation: props.operation.toJSON(),
|
|
415
|
+
arguments: props.arguments,
|
|
416
|
+
value: props.value
|
|
417
|
+
}),
|
|
418
|
+
toPrompt: () => createExecutePrompt(props)
|
|
419
|
+
};
|
|
723
420
|
}
|
|
724
421
|
|
|
725
|
-
function
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
const array = props.controllers.map(((controller, ci) => controller.protocol === "http" ? controller.application.functions.map((func => ({
|
|
732
|
-
protocol: "http",
|
|
733
|
-
controller,
|
|
734
|
-
function: func,
|
|
735
|
-
name: naming(func.name, ci),
|
|
422
|
+
function createTextEvent(props) {
|
|
423
|
+
return {
|
|
424
|
+
type: "text",
|
|
425
|
+
role: props.role,
|
|
426
|
+
stream: props.stream,
|
|
427
|
+
join: props.join,
|
|
736
428
|
toJSON: () => ({
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
429
|
+
type: "text",
|
|
430
|
+
role: props.role,
|
|
431
|
+
done: props.done(),
|
|
432
|
+
text: props.get()
|
|
433
|
+
}),
|
|
434
|
+
toPrompt: () => ({
|
|
435
|
+
type: "text",
|
|
436
|
+
role: props.role,
|
|
437
|
+
text: props.get(),
|
|
438
|
+
toJSON: () => ({
|
|
439
|
+
type: "text",
|
|
440
|
+
role: props.role,
|
|
441
|
+
text: props.get()
|
|
442
|
+
})
|
|
741
443
|
})
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function createDescribeEvent(props) {
|
|
448
|
+
return {
|
|
449
|
+
type: "describe",
|
|
450
|
+
executes: props.executes,
|
|
451
|
+
stream: props.stream,
|
|
452
|
+
join: props.join,
|
|
747
453
|
toJSON: () => ({
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
454
|
+
type: "describe",
|
|
455
|
+
executes: props.executes.map((execute => execute.toJSON())),
|
|
456
|
+
done: props.done(),
|
|
457
|
+
text: props.get()
|
|
458
|
+
}),
|
|
459
|
+
toPrompt: () => ({
|
|
460
|
+
type: "describe",
|
|
461
|
+
executes: props.executes,
|
|
462
|
+
text: props.get(),
|
|
463
|
+
toJSON: () => ({
|
|
464
|
+
type: "describe",
|
|
465
|
+
executes: props.executes.map((execute => execute.toJSON())),
|
|
466
|
+
text: props.get()
|
|
467
|
+
})
|
|
752
468
|
})
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
}) : undefined;
|
|
758
|
-
const flat = new Map;
|
|
759
|
-
const group = new Map;
|
|
760
|
-
for (const item of array) {
|
|
761
|
-
flat.set(item.name, item);
|
|
762
|
-
__map_take(group, item.controller.name, (() => new Map)).set(item.name, item);
|
|
763
|
-
}
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function createRequestEvent(props) {
|
|
764
473
|
return {
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
474
|
+
type: "request",
|
|
475
|
+
source: props.source,
|
|
476
|
+
body: props.body,
|
|
477
|
+
options: props.options
|
|
769
478
|
};
|
|
770
479
|
}
|
|
771
480
|
|
|
772
|
-
function
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
481
|
+
function createResponseEvent(props) {
|
|
482
|
+
return {
|
|
483
|
+
type: "response",
|
|
484
|
+
source: props.source,
|
|
485
|
+
body: props.body,
|
|
486
|
+
options: props.options,
|
|
487
|
+
stream: props.stream,
|
|
488
|
+
join: props.join
|
|
489
|
+
};
|
|
779
490
|
}
|
|
780
491
|
|
|
781
|
-
|
|
782
|
-
compose
|
|
783
|
-
};
|
|
492
|
+
var AgenticaConstant;
|
|
784
493
|
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
494
|
+
(function(AgenticaConstant) {
|
|
495
|
+
AgenticaConstant.RETRY = 3;
|
|
496
|
+
AgenticaConstant.ELITICISM = true;
|
|
497
|
+
})(AgenticaConstant || (AgenticaConstant = {}));
|
|
498
|
+
|
|
499
|
+
const NOT_MOUNTED_YET = {};
|
|
500
|
+
|
|
501
|
+
class Singleton {
|
|
502
|
+
constructor(closure) {
|
|
503
|
+
this.closure_ = closure;
|
|
504
|
+
this.value_ = NOT_MOUNTED_YET;
|
|
505
|
+
}
|
|
506
|
+
get(...args) {
|
|
507
|
+
if (this.value_ === NOT_MOUNTED_YET) {
|
|
508
|
+
this.value_ = this.closure_(...args);
|
|
792
509
|
}
|
|
793
|
-
|
|
510
|
+
return this.value_;
|
|
794
511
|
}
|
|
795
|
-
return result;
|
|
796
512
|
}
|
|
797
513
|
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
514
|
+
const AgenticaSystemPrompt = {
|
|
515
|
+
CANCEL: "You are a helpful assistant for cancelling functions which are prepared to call.\n\nUse the supplied tools to select some functions to cancel of `getApiFunctions()` returned.\n\nIf you can't find any proper function to select, don't talk, don't do anything.",
|
|
516
|
+
COMMON: 'At first, the user\'s language locale code is "${locale}". When you are conversating with the user or describing the function calling result, consider it and always translate to the target locale language. Never conversate with different locale language text with the user.\n\nAt second, the user\'s timezone is "${timezone}", and ISO datetime is ${datetime}. When you are conversating with the user, consider current time and user belonged timezone.',
|
|
517
|
+
DESCRIBE: "You are a helpful assistant describing return values of function calls.\n\nAbove messages are the list of function call histories. When describing the return values, please do not too much shortly summarize them. Instead, provide detailed descriptions as much as.\n\nAlso, its content format must be markdown. If required, utilize the mermaid syntax for drawing some diagrams. When image contents are, just put them through the markdown image syntax.\n\nAt last, if user's language locale code is different with your description, please translate it to the user's language.",
|
|
518
|
+
EXECUTE: 'You are a helpful assistant for tool calling.\n\nUse the supplied tools to assist the user.\n\nIf previous messages are not enough to compose the arguments, you can ask the user to write more information. By the way, when asking the user to write more information, make the text concise and clear.\n\nFor reference, in the "tool" role message content, the `function` property means metadata of the API operation. In other words, it is the function schema describing its purpose, parameters and return value types. And then the `data` property is the return value from the target function calling.',
|
|
519
|
+
INITIALIZE: "You are a helpful assistant.\n\nUse the supplied tools to assist the user.",
|
|
520
|
+
SELECT: "You are a helpful assistant for selecting functions to call.\n\nUse the supplied tools to select some functions of `getApiFunctions()` returned.\n\nWhen selecting functions to call, pay attention to the relationship between functions. In particular, check the prerequisites between each function.\n\nIf you can't find any proper function to select, just type your own message. By the way, when typing your own message, please consider the user's language locale code. If your message is different with the user's language, please translate it to the user's."
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
const isNode = new Singleton((() => {
|
|
524
|
+
const isObject = obj => typeof obj === "object" && obj !== null;
|
|
525
|
+
return typeof global === "object" && isObject(global) && isObject(global.process) && isObject(global.process.versions) && typeof global.process.versions.node !== "undefined";
|
|
526
|
+
}));
|
|
527
|
+
|
|
528
|
+
const getLocale = new Singleton((() => isNode.get() ? process.env.LANG?.split(".")[0] ?? "en-US" : navigator.language));
|
|
529
|
+
|
|
530
|
+
const getTimezone = new Singleton((() => Intl.DateTimeFormat().resolvedOptions().timeZone));
|
|
531
|
+
|
|
532
|
+
function write(config) {
|
|
533
|
+
if (config?.systemPrompt?.common !== undefined) {
|
|
534
|
+
return config?.systemPrompt?.common(config);
|
|
811
535
|
}
|
|
812
|
-
|
|
536
|
+
const locale = config?.locale ?? getLocale.get();
|
|
537
|
+
const timezone = config?.timezone ?? getTimezone.get();
|
|
538
|
+
return AgenticaSystemPrompt.COMMON.replace("${locale}", locale).replace("${timezone}", timezone).replace("${datetime}", (new Date).toISOString());
|
|
813
539
|
}
|
|
814
540
|
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
controller.enqueue(value);
|
|
819
|
-
controller.close();
|
|
820
|
-
}
|
|
821
|
-
});
|
|
822
|
-
return stream;
|
|
823
|
-
}
|
|
541
|
+
const AgenticaDefaultPrompt = {
|
|
542
|
+
write
|
|
543
|
+
};
|
|
824
544
|
|
|
825
|
-
function
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
});
|
|
545
|
+
function createOperationSelection(props) {
|
|
546
|
+
return {
|
|
547
|
+
operation: props.operation,
|
|
548
|
+
reason: props.reason,
|
|
549
|
+
toJSON: () => ({
|
|
550
|
+
operation: props.operation.toJSON(),
|
|
551
|
+
reason: props.reason
|
|
552
|
+
})
|
|
553
|
+
};
|
|
837
554
|
}
|
|
838
555
|
|
|
839
|
-
|
|
840
|
-
readAll,
|
|
841
|
-
reduce,
|
|
842
|
-
to,
|
|
843
|
-
transform: transform$1
|
|
844
|
-
};
|
|
556
|
+
var ByteArrayUtil;
|
|
845
557
|
|
|
846
|
-
function
|
|
847
|
-
|
|
848
|
-
return
|
|
849
|
-
} else if (history.type === "text") {
|
|
850
|
-
return [ {
|
|
851
|
-
role: history.role,
|
|
852
|
-
content: history.text
|
|
853
|
-
} ];
|
|
854
|
-
} else if (history.type === "select" || history.type === "cancel") {
|
|
855
|
-
return [ {
|
|
856
|
-
role: "assistant",
|
|
857
|
-
tool_calls: [ {
|
|
858
|
-
type: "function",
|
|
859
|
-
id: history.id,
|
|
860
|
-
function: {
|
|
861
|
-
name: `${history.type}Functions`,
|
|
862
|
-
arguments: JSON.stringify({
|
|
863
|
-
functions: history.selections.map((s => ({
|
|
864
|
-
name: s.operation.function.name,
|
|
865
|
-
reason: s.reason
|
|
866
|
-
})))
|
|
867
|
-
})
|
|
868
|
-
}
|
|
869
|
-
} ]
|
|
870
|
-
}, {
|
|
871
|
-
role: "tool",
|
|
872
|
-
tool_call_id: history.id,
|
|
873
|
-
content: ""
|
|
874
|
-
} ];
|
|
558
|
+
(function(ByteArrayUtil) {
|
|
559
|
+
function toUtf8(byteArray) {
|
|
560
|
+
return (new TextDecoder).decode(byteArray);
|
|
875
561
|
}
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
562
|
+
ByteArrayUtil.toUtf8 = toUtf8;
|
|
563
|
+
})(ByteArrayUtil || (ByteArrayUtil = {}));
|
|
564
|
+
|
|
565
|
+
function sumCompletionTokenDetail(x, y) {
|
|
566
|
+
return {
|
|
567
|
+
accepted_prediction_tokens: (x.accepted_prediction_tokens ?? 0) + (y.accepted_prediction_tokens ?? 0),
|
|
568
|
+
reasoning_tokens: (x.reasoning_tokens ?? 0) + (y.reasoning_tokens ?? 0),
|
|
569
|
+
rejected_prediction_tokens: (x.rejected_prediction_tokens ?? 0) + (y.rejected_prediction_tokens ?? 0)
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function sumPromptTokenDetail(x, y) {
|
|
574
|
+
return {
|
|
575
|
+
audio_tokens: (x.audio_tokens ?? 0) + (y.audio_tokens ?? 0),
|
|
576
|
+
cached_tokens: (x.cached_tokens ?? 0) + (y.cached_tokens ?? 0)
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
function sum(x, y) {
|
|
581
|
+
return {
|
|
582
|
+
prompt_tokens: (x.prompt_tokens ?? 0) + (y.prompt_tokens ?? 0),
|
|
583
|
+
completion_tokens: (x.completion_tokens ?? 0) + (y.completion_tokens ?? 0),
|
|
584
|
+
total_tokens: (x.total_tokens ?? 0) + (y.total_tokens ?? 0),
|
|
585
|
+
completion_tokens_details: sumCompletionTokenDetail(x.completion_tokens_details ?? {
|
|
586
|
+
accepted_prediction_tokens: 0,
|
|
587
|
+
reasoning_tokens: 0,
|
|
588
|
+
rejected_prediction_tokens: 0
|
|
589
|
+
}, y.completion_tokens_details ?? {
|
|
590
|
+
accepted_prediction_tokens: 0,
|
|
591
|
+
reasoning_tokens: 0,
|
|
592
|
+
rejected_prediction_tokens: 0
|
|
593
|
+
}),
|
|
594
|
+
prompt_tokens_details: sumPromptTokenDetail(x.prompt_tokens_details ?? {
|
|
595
|
+
audio_tokens: 0,
|
|
596
|
+
cached_tokens: 0
|
|
597
|
+
}, y.prompt_tokens_details ?? {
|
|
598
|
+
audio_tokens: 0,
|
|
599
|
+
cached_tokens: 0
|
|
600
|
+
})
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
const ChatGptTokenUsageAggregator = {
|
|
605
|
+
sum,
|
|
606
|
+
sumCompletionTokenDetail,
|
|
607
|
+
sumPromptTokenDetail
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
function transformCompletionChunk(source) {
|
|
611
|
+
const str = source instanceof Uint8Array ? ByteArrayUtil.toUtf8(source) : source;
|
|
612
|
+
return (() => {
|
|
613
|
+
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));
|
|
614
|
+
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));
|
|
615
|
+
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))));
|
|
616
|
+
const _io3 = input => (undefined === input.arguments || "string" === typeof input.arguments) && (undefined === input.name || "string" === typeof input.name);
|
|
617
|
+
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);
|
|
618
|
+
const _io5 = input => (undefined === input.arguments || "string" === typeof input.arguments) && (undefined === input.name || "string" === typeof input.name);
|
|
619
|
+
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))));
|
|
620
|
+
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))));
|
|
621
|
+
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;
|
|
622
|
+
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));
|
|
623
|
+
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);
|
|
624
|
+
const _io11 = input => (undefined === input.audio_tokens || "number" === typeof input.audio_tokens) && (undefined === input.cached_tokens || "number" === typeof input.cached_tokens);
|
|
625
|
+
const _ao0 = (input, _path, _exceptionable = true) => ("string" === typeof input.id || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
626
|
+
method: "json.assertParse",
|
|
627
|
+
path: _path + ".id",
|
|
628
|
+
expected: "string",
|
|
629
|
+
value: input.id
|
|
630
|
+
}, _errorFactory)) && ((Array.isArray(input.choices) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
631
|
+
method: "json.assertParse",
|
|
632
|
+
path: _path + ".choices",
|
|
633
|
+
expected: "Array<ChatCompletionChunk.Choice>",
|
|
634
|
+
value: input.choices
|
|
635
|
+
}, _errorFactory)) && input.choices.every(((elem, _index8) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
636
|
+
method: "json.assertParse",
|
|
637
|
+
path: _path + ".choices[" + _index8 + "]",
|
|
638
|
+
expected: "ChatCompletionChunk.Choice",
|
|
639
|
+
value: elem
|
|
640
|
+
}, _errorFactory)) && _ao1(elem, _path + ".choices[" + _index8 + "]", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
641
|
+
method: "json.assertParse",
|
|
642
|
+
path: _path + ".choices[" + _index8 + "]",
|
|
643
|
+
expected: "ChatCompletionChunk.Choice",
|
|
644
|
+
value: elem
|
|
645
|
+
}, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
646
|
+
method: "json.assertParse",
|
|
647
|
+
path: _path + ".choices",
|
|
648
|
+
expected: "Array<ChatCompletionChunk.Choice>",
|
|
649
|
+
value: input.choices
|
|
650
|
+
}, _errorFactory)) && ("number" === typeof input.created || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
651
|
+
method: "json.assertParse",
|
|
652
|
+
path: _path + ".created",
|
|
653
|
+
expected: "number",
|
|
654
|
+
value: input.created
|
|
655
|
+
}, _errorFactory)) && ("string" === typeof input.model || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
656
|
+
method: "json.assertParse",
|
|
657
|
+
path: _path + ".model",
|
|
658
|
+
expected: "string",
|
|
659
|
+
value: input.model
|
|
660
|
+
}, _errorFactory)) && ("chat.completion.chunk" === input.object || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
661
|
+
method: "json.assertParse",
|
|
662
|
+
path: _path + ".object",
|
|
663
|
+
expected: '"chat.completion.chunk"',
|
|
664
|
+
value: input.object
|
|
665
|
+
}, _errorFactory)) && (null === input.service_tier || undefined === input.service_tier || "scale" === input.service_tier || "default" === input.service_tier || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
666
|
+
method: "json.assertParse",
|
|
667
|
+
path: _path + ".service_tier",
|
|
668
|
+
expected: '("default" | "scale" | null | undefined)',
|
|
669
|
+
value: input.service_tier
|
|
670
|
+
}, _errorFactory)) && (undefined === input.system_fingerprint || "string" === typeof input.system_fingerprint || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
671
|
+
method: "json.assertParse",
|
|
672
|
+
path: _path + ".system_fingerprint",
|
|
673
|
+
expected: "(string | undefined)",
|
|
674
|
+
value: input.system_fingerprint
|
|
675
|
+
}, _errorFactory)) && (null === input.usage || undefined === input.usage || ("object" === typeof input.usage && null !== input.usage || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
676
|
+
method: "json.assertParse",
|
|
677
|
+
path: _path + ".usage",
|
|
678
|
+
expected: "(CompletionUsage | null | undefined)",
|
|
679
|
+
value: input.usage
|
|
680
|
+
}, _errorFactory)) && _ao9(input.usage, _path + ".usage", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
681
|
+
method: "json.assertParse",
|
|
682
|
+
path: _path + ".usage",
|
|
683
|
+
expected: "(CompletionUsage | null | undefined)",
|
|
684
|
+
value: input.usage
|
|
685
|
+
}, _errorFactory));
|
|
686
|
+
const _ao1 = (input, _path, _exceptionable = true) => (("object" === typeof input.delta && null !== input.delta && false === Array.isArray(input.delta) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
687
|
+
method: "json.assertParse",
|
|
688
|
+
path: _path + ".delta",
|
|
689
|
+
expected: "ChatCompletionChunk.Choice.Delta",
|
|
690
|
+
value: input.delta
|
|
691
|
+
}, _errorFactory)) && _ao2(input.delta, _path + ".delta", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
692
|
+
method: "json.assertParse",
|
|
693
|
+
path: _path + ".delta",
|
|
694
|
+
expected: "ChatCompletionChunk.Choice.Delta",
|
|
695
|
+
value: input.delta
|
|
696
|
+
}, _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, {
|
|
697
|
+
method: "json.assertParse",
|
|
698
|
+
path: _path + ".finish_reason",
|
|
699
|
+
expected: '("content_filter" | "function_call" | "length" | "stop" | "tool_calls" | null)',
|
|
700
|
+
value: input.finish_reason
|
|
701
|
+
}, _errorFactory)) && ("number" === typeof input.index || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
702
|
+
method: "json.assertParse",
|
|
703
|
+
path: _path + ".index",
|
|
704
|
+
expected: "number",
|
|
705
|
+
value: input.index
|
|
706
|
+
}, _errorFactory)) && (null === input.logprobs || undefined === input.logprobs || ("object" === typeof input.logprobs && null !== input.logprobs || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
707
|
+
method: "json.assertParse",
|
|
708
|
+
path: _path + ".logprobs",
|
|
709
|
+
expected: "(ChatCompletionChunk.Choice.Logprobs | null | undefined)",
|
|
710
|
+
value: input.logprobs
|
|
711
|
+
}, _errorFactory)) && _ao6(input.logprobs, _path + ".logprobs", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
712
|
+
method: "json.assertParse",
|
|
713
|
+
path: _path + ".logprobs",
|
|
714
|
+
expected: "(ChatCompletionChunk.Choice.Logprobs | null | undefined)",
|
|
715
|
+
value: input.logprobs
|
|
716
|
+
}, _errorFactory));
|
|
717
|
+
const _ao2 = (input, _path, _exceptionable = true) => (null === input.content || undefined === input.content || "string" === typeof input.content || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
718
|
+
method: "json.assertParse",
|
|
719
|
+
path: _path + ".content",
|
|
720
|
+
expected: "(null | string | undefined)",
|
|
721
|
+
value: input.content
|
|
722
|
+
}, _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, {
|
|
723
|
+
method: "json.assertParse",
|
|
724
|
+
path: _path + ".function_call",
|
|
725
|
+
expected: "(ChatCompletionChunk.Choice.Delta.FunctionCall | undefined)",
|
|
726
|
+
value: input.function_call
|
|
727
|
+
}, _errorFactory)) && _ao3(input.function_call, _path + ".function_call", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
728
|
+
method: "json.assertParse",
|
|
729
|
+
path: _path + ".function_call",
|
|
730
|
+
expected: "(ChatCompletionChunk.Choice.Delta.FunctionCall | undefined)",
|
|
731
|
+
value: input.function_call
|
|
732
|
+
}, _errorFactory)) && (null === input.refusal || undefined === input.refusal || "string" === typeof input.refusal || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
733
|
+
method: "json.assertParse",
|
|
734
|
+
path: _path + ".refusal",
|
|
735
|
+
expected: "(null | string | undefined)",
|
|
736
|
+
value: input.refusal
|
|
737
|
+
}, _errorFactory)) && (undefined === input.role || "assistant" === input.role || "user" === input.role || "developer" === input.role || "system" === input.role || "tool" === input.role || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
738
|
+
method: "json.assertParse",
|
|
739
|
+
path: _path + ".role",
|
|
740
|
+
expected: '("assistant" | "developer" | "system" | "tool" | "user" | undefined)',
|
|
741
|
+
value: input.role
|
|
742
|
+
}, _errorFactory)) && (undefined === input.tool_calls || (Array.isArray(input.tool_calls) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
743
|
+
method: "json.assertParse",
|
|
744
|
+
path: _path + ".tool_calls",
|
|
745
|
+
expected: "(Array<ChatCompletionChunk.Choice.Delta.ToolCall> | undefined)",
|
|
746
|
+
value: input.tool_calls
|
|
747
|
+
}, _errorFactory)) && input.tool_calls.every(((elem, _index9) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
748
|
+
method: "json.assertParse",
|
|
749
|
+
path: _path + ".tool_calls[" + _index9 + "]",
|
|
750
|
+
expected: "ChatCompletionChunk.Choice.Delta.ToolCall",
|
|
751
|
+
value: elem
|
|
752
|
+
}, _errorFactory)) && _ao4(elem, _path + ".tool_calls[" + _index9 + "]", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
753
|
+
method: "json.assertParse",
|
|
754
|
+
path: _path + ".tool_calls[" + _index9 + "]",
|
|
755
|
+
expected: "ChatCompletionChunk.Choice.Delta.ToolCall",
|
|
756
|
+
value: elem
|
|
757
|
+
}, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
758
|
+
method: "json.assertParse",
|
|
759
|
+
path: _path + ".tool_calls",
|
|
760
|
+
expected: "(Array<ChatCompletionChunk.Choice.Delta.ToolCall> | undefined)",
|
|
761
|
+
value: input.tool_calls
|
|
762
|
+
}, _errorFactory));
|
|
763
|
+
const _ao3 = (input, _path, _exceptionable = true) => (undefined === input.arguments || "string" === typeof input.arguments || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
764
|
+
method: "json.assertParse",
|
|
765
|
+
path: _path + ".arguments",
|
|
766
|
+
expected: "(string | undefined)",
|
|
767
|
+
value: input.arguments
|
|
768
|
+
}, _errorFactory)) && (undefined === input.name || "string" === typeof input.name || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
769
|
+
method: "json.assertParse",
|
|
770
|
+
path: _path + ".name",
|
|
771
|
+
expected: "(string | undefined)",
|
|
772
|
+
value: input.name
|
|
773
|
+
}, _errorFactory));
|
|
774
|
+
const _ao4 = (input, _path, _exceptionable = true) => ("number" === typeof input.index || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
775
|
+
method: "json.assertParse",
|
|
776
|
+
path: _path + ".index",
|
|
777
|
+
expected: "number",
|
|
778
|
+
value: input.index
|
|
779
|
+
}, _errorFactory)) && (undefined === input.id || "string" === typeof input.id || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
780
|
+
method: "json.assertParse",
|
|
781
|
+
path: _path + ".id",
|
|
782
|
+
expected: "(string | undefined)",
|
|
783
|
+
value: input.id
|
|
784
|
+
}, _errorFactory)) && (undefined === input["function"] || ("object" === typeof input["function"] && null !== input["function"] && false === Array.isArray(input["function"]) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
785
|
+
method: "json.assertParse",
|
|
786
|
+
path: _path + '["function"]',
|
|
787
|
+
expected: "(ChatCompletionChunk.Choice.Delta.ToolCall.Function | undefined)",
|
|
788
|
+
value: input["function"]
|
|
789
|
+
}, _errorFactory)) && _ao5(input["function"], _path + '["function"]', _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
790
|
+
method: "json.assertParse",
|
|
791
|
+
path: _path + '["function"]',
|
|
792
|
+
expected: "(ChatCompletionChunk.Choice.Delta.ToolCall.Function | undefined)",
|
|
793
|
+
value: input["function"]
|
|
794
|
+
}, _errorFactory)) && (undefined === input.type || "function" === input.type || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
795
|
+
method: "json.assertParse",
|
|
796
|
+
path: _path + ".type",
|
|
797
|
+
expected: '("function" | undefined)',
|
|
798
|
+
value: input.type
|
|
799
|
+
}, _errorFactory));
|
|
800
|
+
const _ao5 = (input, _path, _exceptionable = true) => (undefined === input.arguments || "string" === typeof input.arguments || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
801
|
+
method: "json.assertParse",
|
|
802
|
+
path: _path + ".arguments",
|
|
803
|
+
expected: "(string | undefined)",
|
|
804
|
+
value: input.arguments
|
|
805
|
+
}, _errorFactory)) && (undefined === input.name || "string" === typeof input.name || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
806
|
+
method: "json.assertParse",
|
|
807
|
+
path: _path + ".name",
|
|
808
|
+
expected: "(string | undefined)",
|
|
809
|
+
value: input.name
|
|
810
|
+
}, _errorFactory));
|
|
811
|
+
const _ao6 = (input, _path, _exceptionable = true) => (null === input.content || (Array.isArray(input.content) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
812
|
+
method: "json.assertParse",
|
|
813
|
+
path: _path + ".content",
|
|
814
|
+
expected: "(Array<ChatCompletionTokenLogprob> | null)",
|
|
815
|
+
value: input.content
|
|
816
|
+
}, _errorFactory)) && input.content.every(((elem, _index10) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
817
|
+
method: "json.assertParse",
|
|
818
|
+
path: _path + ".content[" + _index10 + "]",
|
|
819
|
+
expected: "ChatCompletionTokenLogprob",
|
|
820
|
+
value: elem
|
|
821
|
+
}, _errorFactory)) && _ao7(elem, _path + ".content[" + _index10 + "]", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
822
|
+
method: "json.assertParse",
|
|
823
|
+
path: _path + ".content[" + _index10 + "]",
|
|
824
|
+
expected: "ChatCompletionTokenLogprob",
|
|
825
|
+
value: elem
|
|
826
|
+
}, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
827
|
+
method: "json.assertParse",
|
|
828
|
+
path: _path + ".content",
|
|
829
|
+
expected: "(Array<ChatCompletionTokenLogprob> | null)",
|
|
830
|
+
value: input.content
|
|
831
|
+
}, _errorFactory)) && (null === input.refusal || (Array.isArray(input.refusal) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
832
|
+
method: "json.assertParse",
|
|
833
|
+
path: _path + ".refusal",
|
|
834
|
+
expected: "(Array<ChatCompletionTokenLogprob> | null)",
|
|
835
|
+
value: input.refusal
|
|
836
|
+
}, _errorFactory)) && input.refusal.every(((elem, _index11) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
837
|
+
method: "json.assertParse",
|
|
838
|
+
path: _path + ".refusal[" + _index11 + "]",
|
|
839
|
+
expected: "ChatCompletionTokenLogprob",
|
|
840
|
+
value: elem
|
|
841
|
+
}, _errorFactory)) && _ao7(elem, _path + ".refusal[" + _index11 + "]", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
842
|
+
method: "json.assertParse",
|
|
843
|
+
path: _path + ".refusal[" + _index11 + "]",
|
|
844
|
+
expected: "ChatCompletionTokenLogprob",
|
|
845
|
+
value: elem
|
|
846
|
+
}, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
847
|
+
method: "json.assertParse",
|
|
848
|
+
path: _path + ".refusal",
|
|
849
|
+
expected: "(Array<ChatCompletionTokenLogprob> | null)",
|
|
850
|
+
value: input.refusal
|
|
851
|
+
}, _errorFactory));
|
|
852
|
+
const _ao7 = (input, _path, _exceptionable = true) => ("string" === typeof input.token || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
853
|
+
method: "json.assertParse",
|
|
854
|
+
path: _path + ".token",
|
|
855
|
+
expected: "string",
|
|
856
|
+
value: input.token
|
|
857
|
+
}, _errorFactory)) && (null === input.bytes || (Array.isArray(input.bytes) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
858
|
+
method: "json.assertParse",
|
|
859
|
+
path: _path + ".bytes",
|
|
860
|
+
expected: "(Array<number> | null)",
|
|
861
|
+
value: input.bytes
|
|
862
|
+
}, _errorFactory)) && input.bytes.every(((elem, _index12) => "number" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
863
|
+
method: "json.assertParse",
|
|
864
|
+
path: _path + ".bytes[" + _index12 + "]",
|
|
865
|
+
expected: "number",
|
|
866
|
+
value: elem
|
|
867
|
+
}, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
868
|
+
method: "json.assertParse",
|
|
869
|
+
path: _path + ".bytes",
|
|
870
|
+
expected: "(Array<number> | null)",
|
|
871
|
+
value: input.bytes
|
|
872
|
+
}, _errorFactory)) && ("number" === typeof input.logprob || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
873
|
+
method: "json.assertParse",
|
|
874
|
+
path: _path + ".logprob",
|
|
875
|
+
expected: "number",
|
|
876
|
+
value: input.logprob
|
|
877
|
+
}, _errorFactory)) && ((Array.isArray(input.top_logprobs) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
878
|
+
method: "json.assertParse",
|
|
879
|
+
path: _path + ".top_logprobs",
|
|
880
|
+
expected: "Array<ChatCompletionTokenLogprob.TopLogprob>",
|
|
881
|
+
value: input.top_logprobs
|
|
882
|
+
}, _errorFactory)) && input.top_logprobs.every(((elem, _index13) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
883
|
+
method: "json.assertParse",
|
|
884
|
+
path: _path + ".top_logprobs[" + _index13 + "]",
|
|
885
|
+
expected: "ChatCompletionTokenLogprob.TopLogprob",
|
|
886
|
+
value: elem
|
|
887
|
+
}, _errorFactory)) && _ao8(elem, _path + ".top_logprobs[" + _index13 + "]", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
888
|
+
method: "json.assertParse",
|
|
889
|
+
path: _path + ".top_logprobs[" + _index13 + "]",
|
|
890
|
+
expected: "ChatCompletionTokenLogprob.TopLogprob",
|
|
891
|
+
value: elem
|
|
892
|
+
}, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
893
|
+
method: "json.assertParse",
|
|
894
|
+
path: _path + ".top_logprobs",
|
|
895
|
+
expected: "Array<ChatCompletionTokenLogprob.TopLogprob>",
|
|
896
|
+
value: input.top_logprobs
|
|
897
|
+
}, _errorFactory));
|
|
898
|
+
const _ao8 = (input, _path, _exceptionable = true) => ("string" === typeof input.token || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
899
|
+
method: "json.assertParse",
|
|
900
|
+
path: _path + ".token",
|
|
901
|
+
expected: "string",
|
|
902
|
+
value: input.token
|
|
903
|
+
}, _errorFactory)) && (null === input.bytes || (Array.isArray(input.bytes) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
904
|
+
method: "json.assertParse",
|
|
905
|
+
path: _path + ".bytes",
|
|
906
|
+
expected: "(Array<number> | null)",
|
|
907
|
+
value: input.bytes
|
|
908
|
+
}, _errorFactory)) && input.bytes.every(((elem, _index14) => "number" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
909
|
+
method: "json.assertParse",
|
|
910
|
+
path: _path + ".bytes[" + _index14 + "]",
|
|
911
|
+
expected: "number",
|
|
912
|
+
value: elem
|
|
913
|
+
}, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
914
|
+
method: "json.assertParse",
|
|
915
|
+
path: _path + ".bytes",
|
|
916
|
+
expected: "(Array<number> | null)",
|
|
917
|
+
value: input.bytes
|
|
918
|
+
}, _errorFactory)) && ("number" === typeof input.logprob || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
919
|
+
method: "json.assertParse",
|
|
920
|
+
path: _path + ".logprob",
|
|
921
|
+
expected: "number",
|
|
922
|
+
value: input.logprob
|
|
923
|
+
}, _errorFactory));
|
|
924
|
+
const _ao9 = (input, _path, _exceptionable = true) => ("number" === typeof input.completion_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
925
|
+
method: "json.assertParse",
|
|
926
|
+
path: _path + ".completion_tokens",
|
|
927
|
+
expected: "number",
|
|
928
|
+
value: input.completion_tokens
|
|
929
|
+
}, _errorFactory)) && ("number" === typeof input.prompt_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
930
|
+
method: "json.assertParse",
|
|
931
|
+
path: _path + ".prompt_tokens",
|
|
932
|
+
expected: "number",
|
|
933
|
+
value: input.prompt_tokens
|
|
934
|
+
}, _errorFactory)) && ("number" === typeof input.total_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
935
|
+
method: "json.assertParse",
|
|
936
|
+
path: _path + ".total_tokens",
|
|
937
|
+
expected: "number",
|
|
938
|
+
value: input.total_tokens
|
|
939
|
+
}, _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, {
|
|
940
|
+
method: "json.assertParse",
|
|
941
|
+
path: _path + ".completion_tokens_details",
|
|
942
|
+
expected: "(CompletionUsage.CompletionTokensDetails | undefined)",
|
|
943
|
+
value: input.completion_tokens_details
|
|
944
|
+
}, _errorFactory)) && _ao10(input.completion_tokens_details, _path + ".completion_tokens_details", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
945
|
+
method: "json.assertParse",
|
|
946
|
+
path: _path + ".completion_tokens_details",
|
|
947
|
+
expected: "(CompletionUsage.CompletionTokensDetails | undefined)",
|
|
948
|
+
value: input.completion_tokens_details
|
|
949
|
+
}, _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, {
|
|
950
|
+
method: "json.assertParse",
|
|
951
|
+
path: _path + ".prompt_tokens_details",
|
|
952
|
+
expected: "(CompletionUsage.PromptTokensDetails | undefined)",
|
|
953
|
+
value: input.prompt_tokens_details
|
|
954
|
+
}, _errorFactory)) && _ao11(input.prompt_tokens_details, _path + ".prompt_tokens_details", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
955
|
+
method: "json.assertParse",
|
|
956
|
+
path: _path + ".prompt_tokens_details",
|
|
957
|
+
expected: "(CompletionUsage.PromptTokensDetails | undefined)",
|
|
958
|
+
value: input.prompt_tokens_details
|
|
959
|
+
}, _errorFactory));
|
|
960
|
+
const _ao10 = (input, _path, _exceptionable = true) => (undefined === input.accepted_prediction_tokens || "number" === typeof input.accepted_prediction_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
961
|
+
method: "json.assertParse",
|
|
962
|
+
path: _path + ".accepted_prediction_tokens",
|
|
963
|
+
expected: "(number | undefined)",
|
|
964
|
+
value: input.accepted_prediction_tokens
|
|
965
|
+
}, _errorFactory)) && (undefined === input.audio_tokens || "number" === typeof input.audio_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
966
|
+
method: "json.assertParse",
|
|
967
|
+
path: _path + ".audio_tokens",
|
|
968
|
+
expected: "(number | undefined)",
|
|
969
|
+
value: input.audio_tokens
|
|
970
|
+
}, _errorFactory)) && (undefined === input.reasoning_tokens || "number" === typeof input.reasoning_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
971
|
+
method: "json.assertParse",
|
|
972
|
+
path: _path + ".reasoning_tokens",
|
|
973
|
+
expected: "(number | undefined)",
|
|
974
|
+
value: input.reasoning_tokens
|
|
975
|
+
}, _errorFactory)) && (undefined === input.rejected_prediction_tokens || "number" === typeof input.rejected_prediction_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
976
|
+
method: "json.assertParse",
|
|
977
|
+
path: _path + ".rejected_prediction_tokens",
|
|
978
|
+
expected: "(number | undefined)",
|
|
979
|
+
value: input.rejected_prediction_tokens
|
|
980
|
+
}, _errorFactory));
|
|
981
|
+
const _ao11 = (input, _path, _exceptionable = true) => (undefined === input.audio_tokens || "number" === typeof input.audio_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
982
|
+
method: "json.assertParse",
|
|
983
|
+
path: _path + ".audio_tokens",
|
|
984
|
+
expected: "(number | undefined)",
|
|
985
|
+
value: input.audio_tokens
|
|
986
|
+
}, _errorFactory)) && (undefined === input.cached_tokens || "number" === typeof input.cached_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
987
|
+
method: "json.assertParse",
|
|
988
|
+
path: _path + ".cached_tokens",
|
|
989
|
+
expected: "(number | undefined)",
|
|
990
|
+
value: input.cached_tokens
|
|
991
|
+
}, _errorFactory));
|
|
992
|
+
const __is = input => "object" === typeof input && null !== input && _io0(input);
|
|
993
|
+
let _errorFactory;
|
|
994
|
+
const __assert = (input, errorFactory) => {
|
|
995
|
+
if (false === __is(input)) {
|
|
996
|
+
_errorFactory = errorFactory;
|
|
997
|
+
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || __typia_transform__assertGuard._assertGuard(true, {
|
|
998
|
+
method: "json.assertParse",
|
|
999
|
+
path: _path + "",
|
|
1000
|
+
expected: "ChatCompletionChunk & { usage: CompletionUsage | null | undefined; }",
|
|
1001
|
+
value: input
|
|
1002
|
+
}, _errorFactory)) && _ao0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
|
|
1003
|
+
method: "json.assertParse",
|
|
1004
|
+
path: _path + "",
|
|
1005
|
+
expected: "ChatCompletionChunk & { usage: CompletionUsage | null | undefined; }",
|
|
1006
|
+
value: input
|
|
1007
|
+
}, _errorFactory))(input, "$input", true);
|
|
905
1008
|
}
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
function createTextPrompt(props) {
|
|
911
|
-
const prompt = {
|
|
912
|
-
type: "text",
|
|
913
|
-
role: props.role,
|
|
914
|
-
text: props.text
|
|
915
|
-
};
|
|
916
|
-
return {
|
|
917
|
-
...prompt,
|
|
918
|
-
toJSON: () => prompt
|
|
919
|
-
};
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
function createDescribePrompt(props) {
|
|
923
|
-
return {
|
|
924
|
-
type: "describe",
|
|
925
|
-
text: props.text,
|
|
926
|
-
executes: props.executes,
|
|
927
|
-
toJSON: () => ({
|
|
928
|
-
type: "describe",
|
|
929
|
-
text: props.text,
|
|
930
|
-
executes: props.executes.map((execute => execute.toJSON()))
|
|
931
|
-
})
|
|
932
|
-
};
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
function createSelectPrompt(props) {
|
|
936
|
-
return {
|
|
937
|
-
type: "select",
|
|
938
|
-
id: props.id,
|
|
939
|
-
selections: props.selections,
|
|
940
|
-
toJSON: () => ({
|
|
941
|
-
type: "select",
|
|
942
|
-
id: props.id,
|
|
943
|
-
selections: props.selections.map((selection => selection.toJSON()))
|
|
944
|
-
})
|
|
945
|
-
};
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
function createCancelPrompt(props) {
|
|
949
|
-
return {
|
|
950
|
-
type: "cancel",
|
|
951
|
-
id: props.id,
|
|
952
|
-
selections: props.selections,
|
|
953
|
-
toJSON: () => ({
|
|
954
|
-
type: "cancel",
|
|
955
|
-
id: props.id,
|
|
956
|
-
selections: props.selections.map((selection => selection.toJSON()))
|
|
957
|
-
})
|
|
958
|
-
};
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
function createExecutePrompt(props) {
|
|
962
|
-
return {
|
|
963
|
-
type: "execute",
|
|
964
|
-
protocol: props.operation.protocol,
|
|
965
|
-
id: props.id,
|
|
966
|
-
operation: props.operation,
|
|
967
|
-
arguments: props.arguments,
|
|
968
|
-
value: props.value,
|
|
969
|
-
toJSON: () => ({
|
|
970
|
-
type: "execute",
|
|
971
|
-
protocol: props.operation.protocol,
|
|
972
|
-
id: props.id,
|
|
973
|
-
operation: props.operation.toJSON(),
|
|
974
|
-
arguments: props.arguments,
|
|
975
|
-
value: props.value
|
|
976
|
-
})
|
|
977
|
-
};
|
|
1009
|
+
return input;
|
|
1010
|
+
};
|
|
1011
|
+
return (input, errorFactory) => __assert(JSON.parse(input), errorFactory);
|
|
1012
|
+
})()(str);
|
|
978
1013
|
}
|
|
979
1014
|
|
|
980
|
-
function
|
|
1015
|
+
function accumulate(origin, chunk) {
|
|
1016
|
+
const choices = origin.choices;
|
|
1017
|
+
chunk.choices.forEach((choice => {
|
|
1018
|
+
const accChoice = choices[choice.index];
|
|
1019
|
+
if (accChoice != null) {
|
|
1020
|
+
choices[choice.index] = mergeChoice(accChoice, choice);
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
choices[choice.index] = {
|
|
1024
|
+
index: choice.index,
|
|
1025
|
+
finish_reason: choice.finish_reason ?? null,
|
|
1026
|
+
logprobs: choice.logprobs ?? null,
|
|
1027
|
+
message: {
|
|
1028
|
+
tool_calls: choice.delta.tool_calls !== undefined ? choice.delta.tool_calls.reduce(((acc, cur) => {
|
|
1029
|
+
acc[cur.index] = {
|
|
1030
|
+
id: cur.id ?? "",
|
|
1031
|
+
type: "function",
|
|
1032
|
+
function: {
|
|
1033
|
+
name: cur.function?.name ?? "",
|
|
1034
|
+
arguments: cur.function?.arguments ?? ""
|
|
1035
|
+
}
|
|
1036
|
+
};
|
|
1037
|
+
return acc;
|
|
1038
|
+
}), []) : undefined,
|
|
1039
|
+
content: choice.delta.content ?? null,
|
|
1040
|
+
refusal: choice.delta.refusal ?? null,
|
|
1041
|
+
role: "assistant"
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
}));
|
|
1045
|
+
const usage = (() => {
|
|
1046
|
+
if (chunk.usage == null) {
|
|
1047
|
+
return origin.usage;
|
|
1048
|
+
}
|
|
1049
|
+
if (origin.usage == null) {
|
|
1050
|
+
return chunk.usage;
|
|
1051
|
+
}
|
|
1052
|
+
return ChatGptTokenUsageAggregator.sum(origin.usage, chunk.usage);
|
|
1053
|
+
})();
|
|
981
1054
|
return {
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
operation: props.operation.toJSON(),
|
|
986
|
-
reason: props.reason
|
|
987
|
-
})
|
|
1055
|
+
...origin,
|
|
1056
|
+
choices,
|
|
1057
|
+
usage
|
|
988
1058
|
};
|
|
989
1059
|
}
|
|
990
1060
|
|
|
991
|
-
function
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
});
|
|
996
|
-
} else if (props.prompt.type === "select") {
|
|
997
|
-
return transformSelect({
|
|
998
|
-
operations: props.operations,
|
|
999
|
-
prompt: props.prompt
|
|
1000
|
-
});
|
|
1001
|
-
} else if (props.prompt.type === "cancel") {
|
|
1002
|
-
return transformCancel({
|
|
1003
|
-
operations: props.operations,
|
|
1004
|
-
prompt: props.prompt
|
|
1005
|
-
});
|
|
1006
|
-
} else if (props.prompt.type === "execute") {
|
|
1007
|
-
return transformExecute({
|
|
1008
|
-
operations: props.operations,
|
|
1009
|
-
prompt: props.prompt
|
|
1010
|
-
});
|
|
1011
|
-
} else if (props.prompt.type === "describe") {
|
|
1012
|
-
return transformDescribe({
|
|
1013
|
-
operations: props.operations,
|
|
1014
|
-
prompt: props.prompt
|
|
1015
|
-
});
|
|
1061
|
+
function merge(chunks) {
|
|
1062
|
+
const firstChunk = chunks[0];
|
|
1063
|
+
if (firstChunk === undefined) {
|
|
1064
|
+
throw new Error("No chunks received");
|
|
1016
1065
|
}
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
id: props.prompt.id,
|
|
1027
|
-
selections: props.prompt.selections.map((select => createOperationSelection({
|
|
1028
|
-
operation: findOperation({
|
|
1029
|
-
operations: props.operations,
|
|
1030
|
-
input: select.operation
|
|
1031
|
-
}),
|
|
1032
|
-
reason: select.reason
|
|
1033
|
-
})))
|
|
1034
|
-
});
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
function transformCancel(props) {
|
|
1038
|
-
return createCancelPrompt({
|
|
1039
|
-
id: props.prompt.id,
|
|
1040
|
-
selections: props.prompt.selections.map((select => createOperationSelection({
|
|
1041
|
-
operation: findOperation({
|
|
1042
|
-
operations: props.operations,
|
|
1043
|
-
input: select.operation
|
|
1044
|
-
}),
|
|
1045
|
-
reason: select.reason
|
|
1046
|
-
})))
|
|
1047
|
-
});
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
function transformExecute(props) {
|
|
1051
|
-
return createExecutePrompt({
|
|
1052
|
-
id: props.prompt.id,
|
|
1053
|
-
operation: findOperation({
|
|
1054
|
-
operations: props.operations,
|
|
1055
|
-
input: props.prompt.operation
|
|
1056
|
-
}),
|
|
1057
|
-
arguments: props.prompt.arguments,
|
|
1058
|
-
value: props.prompt.value
|
|
1059
|
-
});
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
function transformDescribe(props) {
|
|
1063
|
-
return createDescribePrompt({
|
|
1064
|
-
text: props.prompt.text,
|
|
1065
|
-
executes: props.prompt.executes.map((next => transformExecute({
|
|
1066
|
-
operations: props.operations,
|
|
1067
|
-
prompt: next
|
|
1068
|
-
})))
|
|
1066
|
+
return chunks.reduce(accumulate, {
|
|
1067
|
+
id: firstChunk.id,
|
|
1068
|
+
choices: [],
|
|
1069
|
+
created: firstChunk.created,
|
|
1070
|
+
model: firstChunk.model,
|
|
1071
|
+
object: "chat.completion",
|
|
1072
|
+
usage: undefined,
|
|
1073
|
+
service_tier: firstChunk.service_tier,
|
|
1074
|
+
system_fingerprint: firstChunk.system_fingerprint
|
|
1069
1075
|
});
|
|
1070
1076
|
}
|
|
1071
1077
|
|
|
1072
|
-
function
|
|
1073
|
-
|
|
1074
|
-
if (
|
|
1075
|
-
|
|
1078
|
+
function mergeChoice(acc, cur) {
|
|
1079
|
+
var _a;
|
|
1080
|
+
if (acc.finish_reason == null && cur.finish_reason != null) {
|
|
1081
|
+
acc.finish_reason = cur.finish_reason;
|
|
1076
1082
|
}
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
function createCancelEvent(props) {
|
|
1115
|
-
return {
|
|
1116
|
-
type: "cancel",
|
|
1117
|
-
selection: props.selection,
|
|
1118
|
-
toJSON: () => ({
|
|
1119
|
-
type: "cancel",
|
|
1120
|
-
selection: props.selection.toJSON()
|
|
1121
|
-
})
|
|
1122
|
-
};
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
|
-
function createCallEvent(props) {
|
|
1126
|
-
return {
|
|
1127
|
-
type: "call",
|
|
1128
|
-
id: props.id,
|
|
1129
|
-
operation: props.operation,
|
|
1130
|
-
arguments: props.arguments,
|
|
1131
|
-
toJSON: () => ({
|
|
1132
|
-
type: "call",
|
|
1133
|
-
id: props.id,
|
|
1134
|
-
operation: props.operation.toJSON(),
|
|
1135
|
-
arguments: props.arguments
|
|
1136
|
-
})
|
|
1137
|
-
};
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
function createValidateEvent(props) {
|
|
1141
|
-
return {
|
|
1142
|
-
type: "validate",
|
|
1143
|
-
id: props.id,
|
|
1144
|
-
operation: props.operation,
|
|
1145
|
-
result: props.result,
|
|
1146
|
-
toJSON: () => ({
|
|
1147
|
-
type: "validate",
|
|
1148
|
-
id: props.id,
|
|
1149
|
-
operation: props.operation.toJSON(),
|
|
1150
|
-
result: props.result
|
|
1151
|
-
})
|
|
1152
|
-
};
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
|
-
function createExecuteEvent(props) {
|
|
1156
|
-
return {
|
|
1157
|
-
type: "execute",
|
|
1158
|
-
protocol: props.operation.protocol,
|
|
1159
|
-
id: props.id,
|
|
1160
|
-
operation: props.operation,
|
|
1161
|
-
arguments: props.arguments,
|
|
1162
|
-
value: props.value,
|
|
1163
|
-
toJSON: () => ({
|
|
1164
|
-
type: "execute",
|
|
1165
|
-
protocol: props.operation.protocol,
|
|
1166
|
-
id: props.id,
|
|
1167
|
-
operation: props.operation.toJSON(),
|
|
1168
|
-
arguments: props.arguments,
|
|
1169
|
-
value: props.value
|
|
1170
|
-
}),
|
|
1171
|
-
toPrompt: () => createExecutePrompt(props)
|
|
1172
|
-
};
|
|
1083
|
+
if (acc.logprobs == null && cur.logprobs != null) {
|
|
1084
|
+
acc.logprobs = cur.logprobs;
|
|
1085
|
+
}
|
|
1086
|
+
if (cur.delta.content != null) {
|
|
1087
|
+
if (acc.message.content == null) {
|
|
1088
|
+
acc.message.content = cur.delta.content;
|
|
1089
|
+
} else {
|
|
1090
|
+
acc.message.content += cur.delta.content;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
if (cur.delta.refusal != null) {
|
|
1094
|
+
if (acc.message.refusal == null) {
|
|
1095
|
+
acc.message.refusal = cur.delta.refusal;
|
|
1096
|
+
} else {
|
|
1097
|
+
acc.message.refusal += cur.delta.refusal;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
if (cur.delta.tool_calls != null) {
|
|
1101
|
+
(_a = acc.message).tool_calls ?? (_a.tool_calls = []);
|
|
1102
|
+
const toolCalls = acc.message.tool_calls;
|
|
1103
|
+
cur.delta.tool_calls.forEach((toolCall => {
|
|
1104
|
+
const existingToolCall = toolCalls[toolCall.index];
|
|
1105
|
+
if (existingToolCall != null) {
|
|
1106
|
+
toolCalls[toolCall.index] = mergeToolCalls(existingToolCall, toolCall);
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1109
|
+
toolCalls[toolCall.index] = {
|
|
1110
|
+
id: toolCall.id ?? "",
|
|
1111
|
+
type: "function",
|
|
1112
|
+
function: {
|
|
1113
|
+
name: toolCall.function?.name ?? "",
|
|
1114
|
+
arguments: toolCall.function?.arguments ?? ""
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
}));
|
|
1118
|
+
}
|
|
1119
|
+
return acc;
|
|
1173
1120
|
}
|
|
1174
1121
|
|
|
1175
|
-
function
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
type: "text",
|
|
1183
|
-
role: props.role,
|
|
1184
|
-
done: props.done(),
|
|
1185
|
-
text: props.get()
|
|
1186
|
-
}),
|
|
1187
|
-
toPrompt: () => ({
|
|
1188
|
-
type: "text",
|
|
1189
|
-
role: props.role,
|
|
1190
|
-
text: props.get(),
|
|
1191
|
-
toJSON: () => ({
|
|
1192
|
-
type: "text",
|
|
1193
|
-
role: props.role,
|
|
1194
|
-
text: props.get()
|
|
1195
|
-
})
|
|
1196
|
-
})
|
|
1197
|
-
};
|
|
1122
|
+
function mergeToolCalls(acc, cur) {
|
|
1123
|
+
if (cur.function != null) {
|
|
1124
|
+
acc.function.arguments += cur.function.arguments ?? "";
|
|
1125
|
+
acc.function.name += cur.function.name ?? "";
|
|
1126
|
+
}
|
|
1127
|
+
acc.id += cur.id ?? "";
|
|
1128
|
+
return acc;
|
|
1198
1129
|
}
|
|
1199
1130
|
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
text: props.get()
|
|
1220
|
-
})
|
|
1221
|
-
})
|
|
1222
|
-
};
|
|
1131
|
+
const ChatGptCompletionMessageUtil = {
|
|
1132
|
+
transformCompletionChunk,
|
|
1133
|
+
accumulate,
|
|
1134
|
+
merge,
|
|
1135
|
+
mergeChoice,
|
|
1136
|
+
mergeToolCalls
|
|
1137
|
+
};
|
|
1138
|
+
|
|
1139
|
+
async function readAll(stream) {
|
|
1140
|
+
const reader = stream.getReader();
|
|
1141
|
+
const result = [];
|
|
1142
|
+
while (true) {
|
|
1143
|
+
const {done, value} = await reader.read();
|
|
1144
|
+
if (done) {
|
|
1145
|
+
break;
|
|
1146
|
+
}
|
|
1147
|
+
result.push(value);
|
|
1148
|
+
}
|
|
1149
|
+
return result;
|
|
1223
1150
|
}
|
|
1224
1151
|
|
|
1225
|
-
function
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1152
|
+
async function reduce(stream, reducer, initial) {
|
|
1153
|
+
const reader = stream.getReader();
|
|
1154
|
+
let acc = initial ?? null;
|
|
1155
|
+
while (true) {
|
|
1156
|
+
const {done, value} = await reader.read();
|
|
1157
|
+
if (done) {
|
|
1158
|
+
break;
|
|
1159
|
+
}
|
|
1160
|
+
if (acc === null) {
|
|
1161
|
+
acc = value;
|
|
1162
|
+
continue;
|
|
1163
|
+
}
|
|
1164
|
+
acc = reducer(acc, value);
|
|
1165
|
+
}
|
|
1166
|
+
return acc;
|
|
1232
1167
|
}
|
|
1233
1168
|
|
|
1234
|
-
function
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
};
|
|
1169
|
+
function to(value) {
|
|
1170
|
+
const stream = new ReadableStream({
|
|
1171
|
+
start: controller => {
|
|
1172
|
+
controller.enqueue(value);
|
|
1173
|
+
controller.close();
|
|
1174
|
+
}
|
|
1175
|
+
});
|
|
1176
|
+
return stream;
|
|
1243
1177
|
}
|
|
1244
1178
|
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
}
|
|
1179
|
+
function transform$1(stream, transformer) {
|
|
1180
|
+
const reader = stream.getReader();
|
|
1181
|
+
return new ReadableStream({
|
|
1182
|
+
pull: async controller => {
|
|
1183
|
+
const {done, value} = await reader.read();
|
|
1184
|
+
if (!done) {
|
|
1185
|
+
controller.enqueue(transformer(value));
|
|
1186
|
+
} else {
|
|
1187
|
+
controller.close();
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1253
1192
|
|
|
1254
|
-
const
|
|
1193
|
+
const StreamUtil = {
|
|
1194
|
+
readAll,
|
|
1195
|
+
reduce,
|
|
1196
|
+
to,
|
|
1197
|
+
transform: transform$1
|
|
1198
|
+
};
|
|
1255
1199
|
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1200
|
+
async function cancelFunction(ctx, reference) {
|
|
1201
|
+
const index = ctx.stack.findIndex((item => item.operation.name === reference.name));
|
|
1202
|
+
if (index === -1) {
|
|
1203
|
+
return null;
|
|
1260
1204
|
}
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1205
|
+
const item = ctx.stack[index];
|
|
1206
|
+
ctx.stack.splice(index, 1);
|
|
1207
|
+
await ctx.dispatch(createCancelEvent({
|
|
1208
|
+
selection: createOperationSelection({
|
|
1209
|
+
operation: item.operation,
|
|
1210
|
+
reason: reference.reason
|
|
1211
|
+
})
|
|
1212
|
+
}));
|
|
1213
|
+
return item;
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
async function call(ctx) {
|
|
1217
|
+
const completionStream = await ctx.request("call", {
|
|
1218
|
+
messages: [ {
|
|
1219
|
+
role: "system",
|
|
1220
|
+
content: AgenticaDefaultPrompt.write(ctx.config)
|
|
1221
|
+
}, ...ctx.histories.map(decodePrompt).flat(), {
|
|
1222
|
+
role: "user",
|
|
1223
|
+
content: ctx.prompt.text
|
|
1224
|
+
}, {
|
|
1225
|
+
role: "system",
|
|
1226
|
+
content: ctx.config?.systemPrompt?.execute?.(ctx.histories) ?? AgenticaSystemPrompt.EXECUTE
|
|
1227
|
+
} ],
|
|
1228
|
+
tools: ctx.stack.map((s => ({
|
|
1229
|
+
type: "function",
|
|
1230
|
+
function: {
|
|
1231
|
+
name: s.operation.name,
|
|
1232
|
+
description: s.operation.function.description,
|
|
1233
|
+
parameters: s.operation.function.separated !== undefined ? s.operation.function.separated.llm ?? {
|
|
1234
|
+
type: "object",
|
|
1235
|
+
properties: {},
|
|
1236
|
+
required: [],
|
|
1237
|
+
additionalProperties: false,
|
|
1238
|
+
$defs: {}
|
|
1239
|
+
} : s.operation.function.parameters
|
|
1240
|
+
}
|
|
1241
|
+
}))),
|
|
1242
|
+
tool_choice: "auto",
|
|
1243
|
+
parallel_tool_calls: false
|
|
1244
|
+
});
|
|
1245
|
+
const closures = [];
|
|
1246
|
+
const chunks = await StreamUtil.readAll(completionStream);
|
|
1247
|
+
const completion = ChatGptCompletionMessageUtil.merge(chunks);
|
|
1248
|
+
for (const choice of completion.choices) {
|
|
1249
|
+
for (const tc of choice.message.tool_calls ?? []) {
|
|
1250
|
+
if (tc.type === "function") {
|
|
1251
|
+
const operation = ctx.operations.flat.get(tc.function.name);
|
|
1252
|
+
if (operation === undefined) {
|
|
1253
|
+
continue;
|
|
1254
|
+
}
|
|
1255
|
+
closures.push((async () => {
|
|
1256
|
+
const call = createCallEvent({
|
|
1257
|
+
id: tc.id,
|
|
1258
|
+
operation,
|
|
1259
|
+
arguments: JSON.parse(tc.function.arguments)
|
|
1260
|
+
});
|
|
1261
|
+
if (call.operation.protocol === "http") {
|
|
1262
|
+
fillHttpArguments({
|
|
1263
|
+
operation: call.operation,
|
|
1264
|
+
arguments: call.arguments
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
await ctx.dispatch(call);
|
|
1268
|
+
const execute = await propagate(ctx, call, 0);
|
|
1269
|
+
void ctx.dispatch(createExecuteEvent({
|
|
1270
|
+
id: call.id,
|
|
1271
|
+
operation: call.operation,
|
|
1272
|
+
arguments: execute.arguments,
|
|
1273
|
+
value: execute.value
|
|
1274
|
+
}));
|
|
1275
|
+
await cancelFunction(ctx, {
|
|
1276
|
+
name: call.operation.name,
|
|
1277
|
+
reason: "completed"
|
|
1278
|
+
});
|
|
1279
|
+
void ctx.dispatch(createCancelEvent({
|
|
1280
|
+
selection: createOperationSelection({
|
|
1281
|
+
operation: call.operation,
|
|
1282
|
+
reason: "complete"
|
|
1283
|
+
})
|
|
1284
|
+
}));
|
|
1285
|
+
return [ execute, createCancelPrompt({
|
|
1286
|
+
id: call.id,
|
|
1287
|
+
selections: [ createOperationSelection({
|
|
1288
|
+
operation: call.operation,
|
|
1289
|
+
reason: "complete"
|
|
1290
|
+
}) ]
|
|
1291
|
+
}) ];
|
|
1292
|
+
}));
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
if (choice.message.role === "assistant" && choice.message.content !== null && choice.message.content.length > 0) {
|
|
1296
|
+
closures.push((async () => {
|
|
1297
|
+
const value = createTextPrompt({
|
|
1298
|
+
role: "assistant",
|
|
1299
|
+
text: choice.message.content
|
|
1300
|
+
});
|
|
1301
|
+
void ctx.dispatch(createTextEvent({
|
|
1302
|
+
role: "assistant",
|
|
1303
|
+
get: () => value.text,
|
|
1304
|
+
done: () => true,
|
|
1305
|
+
stream: StreamUtil.to(value.text),
|
|
1306
|
+
join: async () => Promise.resolve(value.text)
|
|
1307
|
+
}));
|
|
1308
|
+
return [ value ];
|
|
1309
|
+
}));
|
|
1264
1310
|
}
|
|
1265
|
-
return this.value_;
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
const isNode = new Singleton((() => {
|
|
1270
|
-
const isObject = obj => typeof obj === "object" && obj !== null;
|
|
1271
|
-
return typeof global === "object" && isObject(global) && isObject(global.process) && isObject(global.process.versions) && typeof global.process.versions.node !== "undefined";
|
|
1272
|
-
}));
|
|
1273
|
-
|
|
1274
|
-
const getLocale = new Singleton((() => isNode.get() ? process.env.LANG?.split(".")[0] ?? "en-US" : navigator.language));
|
|
1275
|
-
|
|
1276
|
-
const getTimezone = new Singleton((() => Intl.DateTimeFormat().resolvedOptions().timeZone));
|
|
1277
|
-
|
|
1278
|
-
function write(config) {
|
|
1279
|
-
if (config?.systemPrompt?.common !== undefined) {
|
|
1280
|
-
return config?.systemPrompt?.common(config);
|
|
1281
1311
|
}
|
|
1282
|
-
|
|
1283
|
-
const timezone = config?.timezone ?? getTimezone.get();
|
|
1284
|
-
return AgenticaSystemPrompt.COMMON.replace("${locale}", locale).replace("${timezone}", timezone);
|
|
1312
|
+
return (await Promise.all(closures.map((async fn => fn())))).flat();
|
|
1285
1313
|
}
|
|
1286
1314
|
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
if (this.resolvers.length > 0) {
|
|
1302
|
-
this.resolvers.shift()?.({
|
|
1303
|
-
value: this.queue.shift(),
|
|
1304
|
-
done: false
|
|
1305
|
-
});
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
async dequeue() {
|
|
1309
|
-
if (this.queue.length > 0) {
|
|
1310
|
-
return {
|
|
1311
|
-
value: this.queue.shift(),
|
|
1312
|
-
done: false
|
|
1313
|
-
};
|
|
1314
|
-
}
|
|
1315
|
-
if (this.closed) {
|
|
1316
|
-
if (this.emptyResolvers.length > 0) {
|
|
1317
|
-
this.emptyResolvers.forEach((resolve => resolve()));
|
|
1318
|
-
this.emptyResolvers = [];
|
|
1315
|
+
async function propagate(ctx, call, retry) {
|
|
1316
|
+
if (call.operation.protocol === "http") {
|
|
1317
|
+
const check = call.operation.function.validate(call.arguments);
|
|
1318
|
+
if (check.success === false) {
|
|
1319
|
+
void ctx.dispatch(createValidateEvent({
|
|
1320
|
+
id: call.id,
|
|
1321
|
+
operation: call.operation,
|
|
1322
|
+
result: check
|
|
1323
|
+
}));
|
|
1324
|
+
if (retry++ < (ctx.config?.retry ?? AgenticaConstant.RETRY)) {
|
|
1325
|
+
const trial = await correct(ctx, call, retry, check.errors);
|
|
1326
|
+
if (trial !== null) {
|
|
1327
|
+
return trial;
|
|
1328
|
+
}
|
|
1319
1329
|
}
|
|
1320
|
-
return {
|
|
1321
|
-
value: undefined,
|
|
1322
|
-
done: true
|
|
1323
|
-
};
|
|
1324
1330
|
}
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1331
|
+
try {
|
|
1332
|
+
const response = await executeHttpOperation(call.operation, call.arguments);
|
|
1333
|
+
const success = ((response.status === 400 || response.status === 404 || response.status === 422) && retry++ < (ctx.config?.retry ?? AgenticaConstant.RETRY) && typeof response.body) === false;
|
|
1334
|
+
return (success === false ? await correct(ctx, call, retry, response.body) : null) ?? createExecutePrompt({
|
|
1335
|
+
operation: call.operation,
|
|
1336
|
+
id: call.id,
|
|
1337
|
+
arguments: call.arguments,
|
|
1338
|
+
value: response
|
|
1339
|
+
});
|
|
1340
|
+
} catch (error) {
|
|
1341
|
+
return createExecutePrompt({
|
|
1342
|
+
operation: call.operation,
|
|
1343
|
+
id: call.id,
|
|
1344
|
+
arguments: call.arguments,
|
|
1345
|
+
value: {
|
|
1346
|
+
status: 500,
|
|
1347
|
+
headers: {},
|
|
1348
|
+
body: error instanceof Error ? {
|
|
1349
|
+
...error,
|
|
1350
|
+
name: error.name,
|
|
1351
|
+
message: error.message
|
|
1352
|
+
} : error
|
|
1353
|
+
}
|
|
1342
1354
|
});
|
|
1343
1355
|
}
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1356
|
+
} else {
|
|
1357
|
+
const check = call.operation.function.validate(call.arguments);
|
|
1358
|
+
if (check.success === false) {
|
|
1359
|
+
void ctx.dispatch(createValidateEvent({
|
|
1360
|
+
id: call.id,
|
|
1361
|
+
operation: call.operation,
|
|
1362
|
+
result: check
|
|
1363
|
+
}));
|
|
1364
|
+
return (retry++ < (ctx.config?.retry ?? AgenticaConstant.RETRY) ? await correct(ctx, call, retry, check.errors) : null) ?? createExecutePrompt({
|
|
1365
|
+
id: call.id,
|
|
1366
|
+
operation: call.operation,
|
|
1367
|
+
arguments: call.arguments,
|
|
1368
|
+
value: {
|
|
1369
|
+
name: "TypeGuardError",
|
|
1370
|
+
message: "Invalid arguments.",
|
|
1371
|
+
errors: check.errors
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1349
1374
|
}
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1375
|
+
try {
|
|
1376
|
+
const value = await executeClassOperation(call.operation, call.arguments);
|
|
1377
|
+
return createExecutePrompt({
|
|
1378
|
+
id: call.id,
|
|
1379
|
+
operation: call.operation,
|
|
1380
|
+
arguments: call.arguments,
|
|
1381
|
+
value
|
|
1382
|
+
});
|
|
1383
|
+
} catch (error) {
|
|
1384
|
+
return createExecutePrompt({
|
|
1385
|
+
id: call.id,
|
|
1386
|
+
operation: call.operation,
|
|
1387
|
+
arguments: call.arguments,
|
|
1388
|
+
value: error instanceof Error ? {
|
|
1389
|
+
...error,
|
|
1390
|
+
name: error.name,
|
|
1391
|
+
message: error.message
|
|
1392
|
+
} : error
|
|
1393
|
+
});
|
|
1357
1394
|
}
|
|
1358
|
-
return new Promise((resolve => {
|
|
1359
|
-
this.closeResolvers.push(resolve);
|
|
1360
|
-
}));
|
|
1361
1395
|
}
|
|
1362
1396
|
}
|
|
1363
1397
|
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1398
|
+
async function executeHttpOperation(operation, operationArguments) {
|
|
1399
|
+
const controllerBaseArguments = {
|
|
1400
|
+
connection: operation.controller.connection,
|
|
1401
|
+
application: operation.controller.application,
|
|
1402
|
+
function: operation.function
|
|
1403
|
+
};
|
|
1404
|
+
return operation.controller.execute !== undefined ? operation.controller.execute({
|
|
1405
|
+
...controllerBaseArguments,
|
|
1406
|
+
arguments: operationArguments
|
|
1407
|
+
}) : HttpLlm.propagate({
|
|
1408
|
+
...controllerBaseArguments,
|
|
1409
|
+
input: operationArguments
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
async function executeClassOperation(operation, operationArguments) {
|
|
1414
|
+
const execute = operation.controller.execute;
|
|
1415
|
+
if (typeof execute === "function") {
|
|
1416
|
+
return await execute({
|
|
1417
|
+
application: operation.controller.application,
|
|
1418
|
+
function: operation.function,
|
|
1419
|
+
arguments: operationArguments
|
|
1376
1420
|
});
|
|
1377
1421
|
}
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1422
|
+
return execute[operation.function.name](operationArguments);
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
async function correct(ctx, call, retry, error) {
|
|
1426
|
+
const completionStream = await ctx.request("call", {
|
|
1427
|
+
messages: [ {
|
|
1428
|
+
role: "system",
|
|
1429
|
+
content: AgenticaDefaultPrompt.write(ctx.config)
|
|
1430
|
+
}, ...ctx.histories.map(decodePrompt).flat(), {
|
|
1431
|
+
role: "user",
|
|
1432
|
+
content: ctx.prompt.text
|
|
1433
|
+
}, {
|
|
1434
|
+
role: "system",
|
|
1435
|
+
content: ctx.config?.systemPrompt?.execute?.(ctx.histories) ?? AgenticaSystemPrompt.EXECUTE
|
|
1436
|
+
}, {
|
|
1437
|
+
role: "assistant",
|
|
1438
|
+
tool_calls: [ {
|
|
1439
|
+
type: "function",
|
|
1440
|
+
id: call.id,
|
|
1441
|
+
function: {
|
|
1442
|
+
name: call.operation.name,
|
|
1443
|
+
arguments: JSON.stringify(call.arguments)
|
|
1444
|
+
}
|
|
1445
|
+
} ]
|
|
1446
|
+
}, {
|
|
1447
|
+
role: "tool",
|
|
1448
|
+
content: typeof error === "string" ? error : JSON.stringify(error),
|
|
1449
|
+
tool_call_id: call.id
|
|
1450
|
+
}, {
|
|
1451
|
+
role: "system",
|
|
1452
|
+
content: [ "You A.I. assistant has composed wrong arguments.", "", "Correct it at the next function calling." ].join("\n")
|
|
1453
|
+
} ],
|
|
1454
|
+
tools: [ {
|
|
1455
|
+
type: "function",
|
|
1456
|
+
function: {
|
|
1457
|
+
name: call.operation.name,
|
|
1458
|
+
description: call.operation.function.description,
|
|
1459
|
+
parameters: call.operation.function.separated !== undefined ? call.operation.function.separated?.llm ?? {
|
|
1460
|
+
$defs: {},
|
|
1461
|
+
type: "object",
|
|
1462
|
+
properties: {},
|
|
1463
|
+
additionalProperties: false,
|
|
1464
|
+
required: []
|
|
1465
|
+
} : call.operation.function.parameters
|
|
1466
|
+
}
|
|
1467
|
+
} ],
|
|
1468
|
+
tool_choice: "auto",
|
|
1469
|
+
parallel_tool_calls: false
|
|
1470
|
+
});
|
|
1471
|
+
const chunks = await StreamUtil.readAll(completionStream);
|
|
1472
|
+
const completion = ChatGptCompletionMessageUtil.merge(chunks);
|
|
1473
|
+
const toolCall = (completion.choices[0]?.message.tool_calls ?? []).find((tc => tc.type === "function" && tc.function.name === call.operation.name));
|
|
1474
|
+
if (toolCall === undefined) {
|
|
1475
|
+
return null;
|
|
1392
1476
|
}
|
|
1477
|
+
return propagate(ctx, createCallEvent({
|
|
1478
|
+
id: toolCall.id,
|
|
1479
|
+
operation: call.operation,
|
|
1480
|
+
arguments: JSON.parse(toolCall.function.arguments)
|
|
1481
|
+
}), retry);
|
|
1393
1482
|
}
|
|
1394
1483
|
|
|
1395
|
-
|
|
1396
|
-
if (
|
|
1397
|
-
return
|
|
1484
|
+
function fillHttpArguments(props) {
|
|
1485
|
+
if (props.operation.protocol !== "http") {
|
|
1486
|
+
return;
|
|
1398
1487
|
}
|
|
1399
|
-
const
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
content: ctx.config?.systemPrompt?.describe?.(histories) ?? AgenticaSystemPrompt.DESCRIBE
|
|
1406
|
-
} ]
|
|
1407
|
-
});
|
|
1408
|
-
const describeContext = [];
|
|
1409
|
-
const completion = await StreamUtil.reduce(completionStream, (async (accPromise, chunk) => {
|
|
1410
|
-
const acc = await accPromise;
|
|
1411
|
-
const registerContext = choices => {
|
|
1412
|
-
for (const choice of choices) {
|
|
1413
|
-
if (choice.finish_reason != null) {
|
|
1414
|
-
describeContext[choice.index].mpsc.close();
|
|
1415
|
-
continue;
|
|
1416
|
-
}
|
|
1417
|
-
if (choice.delta.content == null) {
|
|
1418
|
-
continue;
|
|
1419
|
-
}
|
|
1420
|
-
if (describeContext[choice.index] != null) {
|
|
1421
|
-
describeContext[choice.index].content += choice.delta.content;
|
|
1422
|
-
describeContext[choice.index].mpsc.produce(choice.delta.content);
|
|
1423
|
-
continue;
|
|
1424
|
-
}
|
|
1425
|
-
const mpsc = new MPSC;
|
|
1426
|
-
describeContext[choice.index] = {
|
|
1427
|
-
content: choice.delta.content,
|
|
1428
|
-
mpsc
|
|
1429
|
-
};
|
|
1430
|
-
mpsc.produce(choice.delta.content);
|
|
1431
|
-
void ctx.dispatch(createDescribeEvent({
|
|
1432
|
-
executes: histories,
|
|
1433
|
-
stream: mpsc.consumer,
|
|
1434
|
-
done: () => mpsc.done(),
|
|
1435
|
-
get: () => describeContext[choice.index]?.content ?? "",
|
|
1436
|
-
join: async () => {
|
|
1437
|
-
await mpsc.waitClosed();
|
|
1438
|
-
return describeContext[choice.index].content;
|
|
1439
|
-
}
|
|
1440
|
-
}));
|
|
1441
|
-
}
|
|
1442
|
-
};
|
|
1443
|
-
if (acc.object === "chat.completion.chunk") {
|
|
1444
|
-
registerContext([ acc, chunk ].flatMap((v => v.choices)));
|
|
1445
|
-
return ChatGptCompletionMessageUtil.merge([ acc, chunk ]);
|
|
1446
|
-
}
|
|
1447
|
-
registerContext(chunk.choices);
|
|
1448
|
-
return ChatGptCompletionMessageUtil.accumulate(acc, chunk);
|
|
1449
|
-
}));
|
|
1450
|
-
if (completion == null) {
|
|
1451
|
-
throw new Error("No completion received");
|
|
1488
|
+
const route = props.operation.function.route();
|
|
1489
|
+
if (route.body !== null && route.operation().requestBody?.required === true && "body" in props.arguments && isObject(props.operation.function.parameters.$defs, props.operation.function.parameters.properties.body)) {
|
|
1490
|
+
props.arguments.body = {};
|
|
1491
|
+
}
|
|
1492
|
+
if (route.query !== null && "query" in props.arguments && props.arguments.query === undefined) {
|
|
1493
|
+
props.arguments.query = {};
|
|
1452
1494
|
}
|
|
1453
|
-
const descriptions = completion.choices.map((choice => choice.message.role === "assistant" ? choice.message.content : null)).filter((str => str !== null)).map((content => createDescribePrompt({
|
|
1454
|
-
executes: histories,
|
|
1455
|
-
text: content
|
|
1456
|
-
})));
|
|
1457
|
-
return descriptions;
|
|
1458
1495
|
}
|
|
1459
1496
|
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
};
|
|
1463
|
-
|
|
1464
|
-
var AgenticaConstant;
|
|
1465
|
-
|
|
1466
|
-
(function(AgenticaConstant) {
|
|
1467
|
-
AgenticaConstant.RETRY = 3;
|
|
1468
|
-
AgenticaConstant.ELITICISM = true;
|
|
1469
|
-
})(AgenticaConstant || (AgenticaConstant = {}));
|
|
1470
|
-
|
|
1471
|
-
async function cancelFunction(ctx, reference) {
|
|
1472
|
-
const index = ctx.stack.findIndex((item => item.operation.name === reference.name));
|
|
1473
|
-
if (index === -1) {
|
|
1474
|
-
return null;
|
|
1475
|
-
}
|
|
1476
|
-
const item = ctx.stack[index];
|
|
1477
|
-
ctx.stack.splice(index, 1);
|
|
1478
|
-
await ctx.dispatch(createCancelEvent({
|
|
1479
|
-
selection: createOperationSelection({
|
|
1480
|
-
operation: item.operation,
|
|
1481
|
-
reason: reference.reason
|
|
1482
|
-
})
|
|
1483
|
-
}));
|
|
1484
|
-
return item;
|
|
1497
|
+
function isObject($defs, schema) {
|
|
1498
|
+
return ChatGptTypeChecker.isObject(schema) || ChatGptTypeChecker.isReference(schema) && isObject($defs, $defs[schema.$ref.split("/").at(-1)]) || ChatGptTypeChecker.isAnyOf(schema) && schema.anyOf.every((schema => isObject($defs, schema)));
|
|
1485
1499
|
}
|
|
1486
1500
|
|
|
1487
1501
|
const CONTAINER$1 = {
|
|
@@ -1774,325 +1788,213 @@ async function step$1(ctx, operations, retry, failures) {
|
|
|
1774
1788
|
});
|
|
1775
1789
|
for (const reference of input.functions) {
|
|
1776
1790
|
const operation = await cancelFunction(ctx, reference);
|
|
1777
|
-
if (operation !== null) {
|
|
1778
|
-
collection.selections.push(operation);
|
|
1779
|
-
}
|
|
1780
|
-
}
|
|
1781
|
-
if (collection.selections.length !== 0) {
|
|
1782
|
-
prompts.push(collection);
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1787
|
-
return prompts;
|
|
1788
|
-
}
|
|
1789
|
-
|
|
1790
|
-
function emendMessages$1(failures) {
|
|
1791
|
-
return failures.map((f => [ {
|
|
1792
|
-
role: "assistant",
|
|
1793
|
-
tool_calls: [ {
|
|
1794
|
-
type: "function",
|
|
1795
|
-
id: f.id,
|
|
1796
|
-
function: {
|
|
1797
|
-
name: f.name,
|
|
1798
|
-
arguments: JSON.stringify(f.validation.data)
|
|
1799
|
-
}
|
|
1800
|
-
} ]
|
|
1801
|
-
}, {
|
|
1802
|
-
role: "tool",
|
|
1803
|
-
content: JSON.stringify(f.validation.errors),
|
|
1804
|
-
tool_call_id: f.id
|
|
1805
|
-
}, {
|
|
1806
|
-
role: "system",
|
|
1807
|
-
content: [ "You A.I. assistant has composed wrong typed arguments.", "", "Correct it at the next function calling." ].join("\n")
|
|
1808
|
-
} ])).flat();
|
|
1809
|
-
}
|
|
1810
|
-
|
|
1811
|
-
async function call(ctx) {
|
|
1812
|
-
const completionStream = await ctx.request("call", {
|
|
1813
|
-
messages: [ {
|
|
1814
|
-
role: "system",
|
|
1815
|
-
content: AgenticaDefaultPrompt.write(ctx.config)
|
|
1816
|
-
}, ...ctx.histories.map(decodePrompt).flat(), {
|
|
1817
|
-
role: "user",
|
|
1818
|
-
content: ctx.prompt.text
|
|
1819
|
-
}, {
|
|
1820
|
-
role: "system",
|
|
1821
|
-
content: ctx.config?.systemPrompt?.execute?.(ctx.histories) ?? AgenticaSystemPrompt.EXECUTE
|
|
1822
|
-
} ],
|
|
1823
|
-
tools: ctx.stack.map((s => ({
|
|
1824
|
-
type: "function",
|
|
1825
|
-
function: {
|
|
1826
|
-
name: s.operation.name,
|
|
1827
|
-
description: s.operation.function.description,
|
|
1828
|
-
parameters: s.operation.function.separated !== undefined ? s.operation.function.separated.llm ?? {
|
|
1829
|
-
type: "object",
|
|
1830
|
-
properties: {},
|
|
1831
|
-
required: [],
|
|
1832
|
-
additionalProperties: false,
|
|
1833
|
-
$defs: {}
|
|
1834
|
-
} : s.operation.function.parameters
|
|
1835
|
-
}
|
|
1836
|
-
}))),
|
|
1837
|
-
tool_choice: "auto",
|
|
1838
|
-
parallel_tool_calls: false
|
|
1839
|
-
});
|
|
1840
|
-
const closures = [];
|
|
1841
|
-
const chunks = await StreamUtil.readAll(completionStream);
|
|
1842
|
-
const completion = ChatGptCompletionMessageUtil.merge(chunks);
|
|
1843
|
-
for (const choice of completion.choices) {
|
|
1844
|
-
for (const tc of choice.message.tool_calls ?? []) {
|
|
1845
|
-
if (tc.type === "function") {
|
|
1846
|
-
const operation = ctx.operations.flat.get(tc.function.name);
|
|
1847
|
-
if (operation === undefined) {
|
|
1848
|
-
continue;
|
|
1849
|
-
}
|
|
1850
|
-
closures.push((async () => {
|
|
1851
|
-
const call = createCallEvent({
|
|
1852
|
-
id: tc.id,
|
|
1853
|
-
operation,
|
|
1854
|
-
arguments: JSON.parse(tc.function.arguments)
|
|
1855
|
-
});
|
|
1856
|
-
if (call.operation.protocol === "http") {
|
|
1857
|
-
fillHttpArguments({
|
|
1858
|
-
operation: call.operation,
|
|
1859
|
-
arguments: call.arguments
|
|
1860
|
-
});
|
|
1861
|
-
}
|
|
1862
|
-
await ctx.dispatch(call);
|
|
1863
|
-
const execute = await propagate(ctx, call, 0);
|
|
1864
|
-
void ctx.dispatch(createExecuteEvent({
|
|
1865
|
-
id: call.id,
|
|
1866
|
-
operation: call.operation,
|
|
1867
|
-
arguments: execute.arguments,
|
|
1868
|
-
value: execute.value
|
|
1869
|
-
}));
|
|
1870
|
-
await cancelFunction(ctx, {
|
|
1871
|
-
name: call.operation.name,
|
|
1872
|
-
reason: "completed"
|
|
1873
|
-
});
|
|
1874
|
-
void ctx.dispatch(createCancelEvent({
|
|
1875
|
-
selection: createOperationSelection({
|
|
1876
|
-
operation: call.operation,
|
|
1877
|
-
reason: "complete"
|
|
1878
|
-
})
|
|
1879
|
-
}));
|
|
1880
|
-
return [ execute, createCancelPrompt({
|
|
1881
|
-
id: call.id,
|
|
1882
|
-
selections: [ createOperationSelection({
|
|
1883
|
-
operation: call.operation,
|
|
1884
|
-
reason: "complete"
|
|
1885
|
-
}) ]
|
|
1886
|
-
}) ];
|
|
1887
|
-
}));
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
if (choice.message.role === "assistant" && choice.message.content !== null && choice.message.content.length > 0) {
|
|
1891
|
-
closures.push((async () => {
|
|
1892
|
-
const value = createTextPrompt({
|
|
1893
|
-
role: "assistant",
|
|
1894
|
-
text: choice.message.content
|
|
1895
|
-
});
|
|
1896
|
-
void ctx.dispatch(createTextEvent({
|
|
1897
|
-
role: "assistant",
|
|
1898
|
-
get: () => value.text,
|
|
1899
|
-
done: () => true,
|
|
1900
|
-
stream: StreamUtil.to(value.text),
|
|
1901
|
-
join: async () => Promise.resolve(value.text)
|
|
1902
|
-
}));
|
|
1903
|
-
return [ value ];
|
|
1904
|
-
}));
|
|
1905
|
-
}
|
|
1906
|
-
}
|
|
1907
|
-
return (await Promise.all(closures.map((async fn => fn())))).flat();
|
|
1908
|
-
}
|
|
1909
|
-
|
|
1910
|
-
async function propagate(ctx, call, retry) {
|
|
1911
|
-
if (call.operation.protocol === "http") {
|
|
1912
|
-
const check = call.operation.function.validate(call.arguments);
|
|
1913
|
-
if (check.success === false) {
|
|
1914
|
-
void ctx.dispatch(createValidateEvent({
|
|
1915
|
-
id: call.id,
|
|
1916
|
-
operation: call.operation,
|
|
1917
|
-
result: check
|
|
1918
|
-
}));
|
|
1919
|
-
if (retry++ < (ctx.config?.retry ?? AgenticaConstant.RETRY)) {
|
|
1920
|
-
const trial = await correct(ctx, call, retry, check.errors);
|
|
1921
|
-
if (trial !== null) {
|
|
1922
|
-
return trial;
|
|
1791
|
+
if (operation !== null) {
|
|
1792
|
+
collection.selections.push(operation);
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
if (collection.selections.length !== 0) {
|
|
1796
|
+
prompts.push(collection);
|
|
1923
1797
|
}
|
|
1924
1798
|
}
|
|
1925
1799
|
}
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1800
|
+
}
|
|
1801
|
+
return prompts;
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
function emendMessages$1(failures) {
|
|
1805
|
+
return failures.map((f => [ {
|
|
1806
|
+
role: "assistant",
|
|
1807
|
+
tool_calls: [ {
|
|
1808
|
+
type: "function",
|
|
1809
|
+
id: f.id,
|
|
1810
|
+
function: {
|
|
1811
|
+
name: f.name,
|
|
1812
|
+
arguments: JSON.stringify(f.validation.data)
|
|
1813
|
+
}
|
|
1814
|
+
} ]
|
|
1815
|
+
}, {
|
|
1816
|
+
role: "tool",
|
|
1817
|
+
content: JSON.stringify(f.validation.errors),
|
|
1818
|
+
tool_call_id: f.id
|
|
1819
|
+
}, {
|
|
1820
|
+
role: "system",
|
|
1821
|
+
content: [ "You A.I. assistant has composed wrong typed arguments.", "", "Correct it at the next function calling." ].join("\n")
|
|
1822
|
+
} ])).flat();
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
class AsyncQueue {
|
|
1826
|
+
constructor() {
|
|
1827
|
+
this.queue = [];
|
|
1828
|
+
this.resolvers = [];
|
|
1829
|
+
this.closeResolvers = [];
|
|
1830
|
+
this.emptyResolvers = [];
|
|
1831
|
+
this.closed = false;
|
|
1832
|
+
}
|
|
1833
|
+
enqueue(item) {
|
|
1834
|
+
this.queue.push(item);
|
|
1835
|
+
if (this.resolvers.length > 0) {
|
|
1836
|
+
this.resolvers.shift()?.({
|
|
1837
|
+
value: this.queue.shift(),
|
|
1838
|
+
done: false
|
|
1949
1839
|
});
|
|
1950
1840
|
}
|
|
1951
|
-
}
|
|
1952
|
-
|
|
1953
|
-
if (
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
}));
|
|
1959
|
-
return (retry++ < (ctx.config?.retry ?? AgenticaConstant.RETRY) ? await correct(ctx, call, retry, check.errors) : null) ?? createExecutePrompt({
|
|
1960
|
-
id: call.id,
|
|
1961
|
-
operation: call.operation,
|
|
1962
|
-
arguments: call.arguments,
|
|
1963
|
-
value: {
|
|
1964
|
-
name: "TypeGuardError",
|
|
1965
|
-
message: "Invalid arguments.",
|
|
1966
|
-
errors: check.errors
|
|
1967
|
-
}
|
|
1968
|
-
});
|
|
1841
|
+
}
|
|
1842
|
+
async dequeue() {
|
|
1843
|
+
if (this.queue.length > 0) {
|
|
1844
|
+
return {
|
|
1845
|
+
value: this.queue.shift(),
|
|
1846
|
+
done: false
|
|
1847
|
+
};
|
|
1969
1848
|
}
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
value
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1849
|
+
if (this.closed) {
|
|
1850
|
+
if (this.emptyResolvers.length > 0) {
|
|
1851
|
+
this.emptyResolvers.forEach((resolve => resolve()));
|
|
1852
|
+
this.emptyResolvers = [];
|
|
1853
|
+
}
|
|
1854
|
+
return {
|
|
1855
|
+
value: undefined,
|
|
1856
|
+
done: true
|
|
1857
|
+
};
|
|
1858
|
+
}
|
|
1859
|
+
return new Promise((resolve => this.resolvers.push(resolve)));
|
|
1860
|
+
}
|
|
1861
|
+
isEmpty() {
|
|
1862
|
+
return this.queue.length === 0;
|
|
1863
|
+
}
|
|
1864
|
+
isClosed() {
|
|
1865
|
+
return this.closed;
|
|
1866
|
+
}
|
|
1867
|
+
done() {
|
|
1868
|
+
return this.isClosed() && this.isEmpty();
|
|
1869
|
+
}
|
|
1870
|
+
close() {
|
|
1871
|
+
this.closed = true;
|
|
1872
|
+
while (this.resolvers.length > 0) {
|
|
1873
|
+
this.resolvers.shift()?.({
|
|
1874
|
+
value: undefined,
|
|
1875
|
+
done: true
|
|
1988
1876
|
});
|
|
1989
1877
|
}
|
|
1878
|
+
this.closeResolvers.forEach((resolve => resolve()));
|
|
1990
1879
|
}
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
}
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
}
|
|
2007
|
-
|
|
2008
|
-
async function executeClassOperation(operation, operationArguments) {
|
|
2009
|
-
const execute = operation.controller.execute;
|
|
2010
|
-
if (typeof execute === "function") {
|
|
2011
|
-
return await execute({
|
|
2012
|
-
application: operation.controller.application,
|
|
2013
|
-
function: operation.function,
|
|
2014
|
-
arguments: operationArguments
|
|
2015
|
-
});
|
|
1880
|
+
async waitUntilEmpty() {
|
|
1881
|
+
if (this.isEmpty()) {
|
|
1882
|
+
return Promise.resolve();
|
|
1883
|
+
}
|
|
1884
|
+
return new Promise((resolve => {
|
|
1885
|
+
this.emptyResolvers.push(resolve);
|
|
1886
|
+
}));
|
|
1887
|
+
}
|
|
1888
|
+
async waitClosed() {
|
|
1889
|
+
if (this.isClosed()) {
|
|
1890
|
+
return Promise.resolve();
|
|
1891
|
+
}
|
|
1892
|
+
return new Promise((resolve => {
|
|
1893
|
+
this.closeResolvers.push(resolve);
|
|
1894
|
+
}));
|
|
2016
1895
|
}
|
|
2017
|
-
return execute[operation.function.name](operationArguments);
|
|
2018
1896
|
}
|
|
2019
1897
|
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
role: "system",
|
|
2030
|
-
content: ctx.config?.systemPrompt?.execute?.(ctx.histories) ?? AgenticaSystemPrompt.EXECUTE
|
|
2031
|
-
}, {
|
|
2032
|
-
role: "assistant",
|
|
2033
|
-
tool_calls: [ {
|
|
2034
|
-
type: "function",
|
|
2035
|
-
id: call.id,
|
|
2036
|
-
function: {
|
|
2037
|
-
name: call.operation.name,
|
|
2038
|
-
arguments: JSON.stringify(call.arguments)
|
|
1898
|
+
class MPSC {
|
|
1899
|
+
constructor() {
|
|
1900
|
+
this.queue = new AsyncQueue;
|
|
1901
|
+
this.consumer = new ReadableStream({
|
|
1902
|
+
pull: async controller => {
|
|
1903
|
+
const {value, done} = await this.queue.dequeue();
|
|
1904
|
+
if (done === true) {
|
|
1905
|
+
controller.close();
|
|
1906
|
+
return;
|
|
2039
1907
|
}
|
|
2040
|
-
|
|
2041
|
-
}, {
|
|
2042
|
-
role: "tool",
|
|
2043
|
-
content: typeof error === "string" ? error : JSON.stringify(error),
|
|
2044
|
-
tool_call_id: call.id
|
|
2045
|
-
}, {
|
|
2046
|
-
role: "system",
|
|
2047
|
-
content: [ "You A.I. assistant has composed wrong arguments.", "", "Correct it at the next function calling." ].join("\n")
|
|
2048
|
-
} ],
|
|
2049
|
-
tools: [ {
|
|
2050
|
-
type: "function",
|
|
2051
|
-
function: {
|
|
2052
|
-
name: call.operation.name,
|
|
2053
|
-
description: call.operation.function.description,
|
|
2054
|
-
parameters: call.operation.function.separated !== undefined ? call.operation.function.separated?.llm ?? {
|
|
2055
|
-
$defs: {},
|
|
2056
|
-
type: "object",
|
|
2057
|
-
properties: {},
|
|
2058
|
-
additionalProperties: false,
|
|
2059
|
-
required: []
|
|
2060
|
-
} : call.operation.function.parameters
|
|
1908
|
+
controller.enqueue(value);
|
|
2061
1909
|
}
|
|
2062
|
-
}
|
|
2063
|
-
tool_choice: "auto",
|
|
2064
|
-
parallel_tool_calls: false
|
|
2065
|
-
});
|
|
2066
|
-
const chunks = await StreamUtil.readAll(completionStream);
|
|
2067
|
-
const completion = ChatGptCompletionMessageUtil.merge(chunks);
|
|
2068
|
-
const toolCall = (completion.choices[0]?.message.tool_calls ?? []).find((tc => tc.type === "function" && tc.function.name === call.operation.name));
|
|
2069
|
-
if (toolCall === undefined) {
|
|
2070
|
-
return null;
|
|
1910
|
+
});
|
|
2071
1911
|
}
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
}
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
if (props.operation.protocol !== "http") {
|
|
2081
|
-
return;
|
|
1912
|
+
produce(chunk) {
|
|
1913
|
+
this.queue.enqueue(chunk);
|
|
1914
|
+
}
|
|
1915
|
+
close() {
|
|
1916
|
+
this.queue.close();
|
|
1917
|
+
}
|
|
1918
|
+
done() {
|
|
1919
|
+
return this.queue.done();
|
|
2082
1920
|
}
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
props.arguments.body = {};
|
|
1921
|
+
async waitClosed() {
|
|
1922
|
+
await this.queue.waitClosed();
|
|
2086
1923
|
}
|
|
2087
|
-
|
|
2088
|
-
|
|
1924
|
+
async waitUntilEmpty() {
|
|
1925
|
+
await this.queue.waitUntilEmpty();
|
|
2089
1926
|
}
|
|
2090
1927
|
}
|
|
2091
1928
|
|
|
2092
|
-
function
|
|
2093
|
-
|
|
1929
|
+
async function describe(ctx, histories) {
|
|
1930
|
+
if (histories.length === 0) {
|
|
1931
|
+
return [];
|
|
1932
|
+
}
|
|
1933
|
+
const completionStream = await ctx.request("describe", {
|
|
1934
|
+
messages: [ {
|
|
1935
|
+
role: "system",
|
|
1936
|
+
content: AgenticaDefaultPrompt.write(ctx.config)
|
|
1937
|
+
}, ...histories.map(decodePrompt).flat(), {
|
|
1938
|
+
role: "system",
|
|
1939
|
+
content: ctx.config?.systemPrompt?.describe?.(histories) ?? AgenticaSystemPrompt.DESCRIBE
|
|
1940
|
+
} ]
|
|
1941
|
+
});
|
|
1942
|
+
const describeContext = [];
|
|
1943
|
+
const completion = await StreamUtil.reduce(completionStream, (async (accPromise, chunk) => {
|
|
1944
|
+
const acc = await accPromise;
|
|
1945
|
+
const registerContext = choices => {
|
|
1946
|
+
for (const choice of choices) {
|
|
1947
|
+
if (choice.finish_reason != null) {
|
|
1948
|
+
describeContext[choice.index].mpsc.close();
|
|
1949
|
+
continue;
|
|
1950
|
+
}
|
|
1951
|
+
if (choice.delta.content == null) {
|
|
1952
|
+
continue;
|
|
1953
|
+
}
|
|
1954
|
+
if (describeContext[choice.index] != null) {
|
|
1955
|
+
describeContext[choice.index].content += choice.delta.content;
|
|
1956
|
+
describeContext[choice.index].mpsc.produce(choice.delta.content);
|
|
1957
|
+
continue;
|
|
1958
|
+
}
|
|
1959
|
+
const mpsc = new MPSC;
|
|
1960
|
+
describeContext[choice.index] = {
|
|
1961
|
+
content: choice.delta.content,
|
|
1962
|
+
mpsc
|
|
1963
|
+
};
|
|
1964
|
+
mpsc.produce(choice.delta.content);
|
|
1965
|
+
void ctx.dispatch(createDescribeEvent({
|
|
1966
|
+
executes: histories,
|
|
1967
|
+
stream: mpsc.consumer,
|
|
1968
|
+
done: () => mpsc.done(),
|
|
1969
|
+
get: () => describeContext[choice.index]?.content ?? "",
|
|
1970
|
+
join: async () => {
|
|
1971
|
+
await mpsc.waitClosed();
|
|
1972
|
+
return describeContext[choice.index].content;
|
|
1973
|
+
}
|
|
1974
|
+
}));
|
|
1975
|
+
}
|
|
1976
|
+
};
|
|
1977
|
+
if (acc.object === "chat.completion.chunk") {
|
|
1978
|
+
registerContext([ acc, chunk ].flatMap((v => v.choices)));
|
|
1979
|
+
return ChatGptCompletionMessageUtil.merge([ acc, chunk ]);
|
|
1980
|
+
}
|
|
1981
|
+
registerContext(chunk.choices);
|
|
1982
|
+
return ChatGptCompletionMessageUtil.accumulate(acc, chunk);
|
|
1983
|
+
}));
|
|
1984
|
+
if (completion == null) {
|
|
1985
|
+
throw new Error("No completion received");
|
|
1986
|
+
}
|
|
1987
|
+
const descriptions = completion.choices.map((choice => choice.message.role === "assistant" ? choice.message.content : null)).filter((str => str !== null)).map((content => createDescribePrompt({
|
|
1988
|
+
executes: histories,
|
|
1989
|
+
text: content
|
|
1990
|
+
})));
|
|
1991
|
+
return descriptions;
|
|
2094
1992
|
}
|
|
2095
1993
|
|
|
1994
|
+
const ChatGptDescribeFunctionAgent = {
|
|
1995
|
+
execute: describe
|
|
1996
|
+
};
|
|
1997
|
+
|
|
2096
1998
|
const FUNCTION = {
|
|
2097
1999
|
functions: [ {
|
|
2098
2000
|
name: "getApiFunctions",
|
|
@@ -3192,6 +3094,10 @@ const FUNCTION = {
|
|
|
3192
3094
|
type: "string",
|
|
3193
3095
|
enum: [ "object" ]
|
|
3194
3096
|
},
|
|
3097
|
+
properties: {
|
|
3098
|
+
title: "Properties of the object",
|
|
3099
|
+
$ref: "#/$defs/RecordstringIChatGptSchema"
|
|
3100
|
+
},
|
|
3195
3101
|
required: {
|
|
3196
3102
|
title: "List of key values of the required properties",
|
|
3197
3103
|
description: 'List of key values of the required properties.\n\nThe `required` means a list of the key values of the required\n{@link properties}. If some property key is not listed in the `required`\nlist, it means that property is optional. Otherwise some property key\nexists in the `required` list, it means that the property must be filled.\n\nBelow is an example of the {@link properties} and `required`.\n\n```typescript\ninterface SomeObject {\n id: string;\n email: string;\n name?: string;\n}\n```\n\nAs you can see, `id` and `email` {@link properties} are {@link required},\nso that they are listed in the `required` list.\n\n```json\n{\n "type": "object",\n "properties": {\n "id": { "type": "string" },\n "email": { "type": "string" },\n "name": { "type": "string" }\n },\n "required": ["id", "email"]\n}\n```',
|
|
@@ -3200,10 +3106,6 @@ const FUNCTION = {
|
|
|
3200
3106
|
type: "string"
|
|
3201
3107
|
}
|
|
3202
3108
|
},
|
|
3203
|
-
properties: {
|
|
3204
|
-
title: "Properties of the object",
|
|
3205
|
-
$ref: "#/$defs/RecordstringIChatGptSchema"
|
|
3206
|
-
},
|
|
3207
3109
|
title: {
|
|
3208
3110
|
title: "Title of the schema",
|
|
3209
3111
|
description: "Title of the schema.",
|
|
@@ -3231,7 +3133,7 @@ const FUNCTION = {
|
|
|
3231
3133
|
additionalProperties: {}
|
|
3232
3134
|
}
|
|
3233
3135
|
},
|
|
3234
|
-
required: [ "$defs", "additionalProperties", "type", "
|
|
3136
|
+
required: [ "$defs", "additionalProperties", "type", "properties", "required" ]
|
|
3235
3137
|
},
|
|
3236
3138
|
separated: {
|
|
3237
3139
|
description: "Collection of separated parameters.\n\nFilled only when {@link IHttpLlmApplication.IOptions.separate} is configured.\n\n------------------------------\n\nDescription of the current {@link IHttpLlmFunction.ISeparatedchatgpt} type:\n\n> Collection of separated parameters.",
|
|
@@ -3257,6 +3159,10 @@ const FUNCTION = {
|
|
|
3257
3159
|
type: "string",
|
|
3258
3160
|
enum: [ "object" ]
|
|
3259
3161
|
},
|
|
3162
|
+
properties: {
|
|
3163
|
+
title: "Properties of the object",
|
|
3164
|
+
$ref: "#/$defs/RecordstringIChatGptSchema"
|
|
3165
|
+
},
|
|
3260
3166
|
required: {
|
|
3261
3167
|
title: "List of key values of the required properties",
|
|
3262
3168
|
description: 'List of key values of the required properties.\n\nThe `required` means a list of the key values of the required\n{@link properties}. If some property key is not listed in the `required`\nlist, it means that property is optional. Otherwise some property key\nexists in the `required` list, it means that the property must be filled.\n\nBelow is an example of the {@link properties} and `required`.\n\n```typescript\ninterface SomeObject {\n id: string;\n email: string;\n name?: string;\n}\n```\n\nAs you can see, `id` and `email` {@link properties} are {@link required},\nso that they are listed in the `required` list.\n\n```json\n{\n "type": "object",\n "properties": {\n "id": { "type": "string" },\n "email": { "type": "string" },\n "name": { "type": "string" }\n },\n "required": ["id", "email"]\n}\n```',
|
|
@@ -3265,10 +3171,6 @@ const FUNCTION = {
|
|
|
3265
3171
|
type: "string"
|
|
3266
3172
|
}
|
|
3267
3173
|
},
|
|
3268
|
-
properties: {
|
|
3269
|
-
title: "Properties of the object",
|
|
3270
|
-
$ref: "#/$defs/RecordstringIChatGptSchema"
|
|
3271
|
-
},
|
|
3272
3174
|
title: {
|
|
3273
3175
|
title: "Title of the schema",
|
|
3274
3176
|
description: "Title of the schema.",
|
|
@@ -3296,7 +3198,7 @@ const FUNCTION = {
|
|
|
3296
3198
|
additionalProperties: {}
|
|
3297
3199
|
}
|
|
3298
3200
|
},
|
|
3299
|
-
required: [ "$defs", "additionalProperties", "type", "
|
|
3201
|
+
required: [ "$defs", "additionalProperties", "type", "properties", "required" ]
|
|
3300
3202
|
},
|
|
3301
3203
|
human: {
|
|
3302
3204
|
title: "Parameters that would be composed by the human",
|
|
@@ -3322,6 +3224,10 @@ const FUNCTION = {
|
|
|
3322
3224
|
type: "string",
|
|
3323
3225
|
enum: [ "object" ]
|
|
3324
3226
|
},
|
|
3227
|
+
properties: {
|
|
3228
|
+
title: "Properties of the object",
|
|
3229
|
+
$ref: "#/$defs/RecordstringIChatGptSchema"
|
|
3230
|
+
},
|
|
3325
3231
|
required: {
|
|
3326
3232
|
title: "List of key values of the required properties",
|
|
3327
3233
|
description: 'List of key values of the required properties.\n\nThe `required` means a list of the key values of the required\n{@link properties}. If some property key is not listed in the `required`\nlist, it means that property is optional. Otherwise some property key\nexists in the `required` list, it means that the property must be filled.\n\nBelow is an example of the {@link properties} and `required`.\n\n```typescript\ninterface SomeObject {\n id: string;\n email: string;\n name?: string;\n}\n```\n\nAs you can see, `id` and `email` {@link properties} are {@link required},\nso that they are listed in the `required` list.\n\n```json\n{\n "type": "object",\n "properties": {\n "id": { "type": "string" },\n "email": { "type": "string" },\n "name": { "type": "string" }\n },\n "required": ["id", "email"]\n}\n```',
|
|
@@ -3330,10 +3236,6 @@ const FUNCTION = {
|
|
|
3330
3236
|
type: "string"
|
|
3331
3237
|
}
|
|
3332
3238
|
},
|
|
3333
|
-
properties: {
|
|
3334
|
-
title: "Properties of the object",
|
|
3335
|
-
$ref: "#/$defs/RecordstringIChatGptSchema"
|
|
3336
|
-
},
|
|
3337
3239
|
title: {
|
|
3338
3240
|
title: "Title of the schema",
|
|
3339
3241
|
description: "Title of the schema.",
|
|
@@ -3361,7 +3263,7 @@ const FUNCTION = {
|
|
|
3361
3263
|
additionalProperties: {}
|
|
3362
3264
|
}
|
|
3363
3265
|
},
|
|
3364
|
-
required: [ "$defs", "additionalProperties", "type", "
|
|
3266
|
+
required: [ "$defs", "additionalProperties", "type", "properties", "required" ],
|
|
3365
3267
|
description: 'Description of the current {@link IChatGptSchema.IParameters} type:\n\n> Type of the function parameters.\n> \n> `IChatGptSchema.IParameters` is a type defining a function\'s parameters\n> as a keyworded object type.\n> \n> It also can be utilized for the structured output metadata.\n\n------------------------------\n\nDescription of the parent {@link IChatGptSchema} type:\n\n> Type schema info of the ChatGPT.\n> \n> `IChatGptSchema` is a type schema info of the ChatGPT function calling.\n> \n> `IChatGptSchema` basically follows the JSON schema definition of the OpenAPI v3.1\n> speciifcation; {@link OpenApiV3_1.IJsonSchema}.\n> \n> However, the `IChatGptSchema` does not follow the entire specification of\n> the OpenAPI v3.1. It has own specific restrictions and definitions. Here is the\n> list of how `IChatGptSchema` is different with the OpenAPI v3.1 JSON schema.\n> \n> - Decompose mixed type: {@link OpenApiV3_1.IJsonSchema.IMixed}\n> - Resolve nullable property: {@link OpenApiV3_1.IJsonSchema.__ISignificant.nullable}\n> - Tuple type is banned: {@link OpenApiV3_1.IJsonSchema.ITuple.prefixItems}\n> - Constant type is banned: {@link OpenApiV3_1.IJsonSchema.IConstant}\n> - Merge {@link OpenApiV3_1.IJsonSchema.IOneOf} to {@link IChatGptSchema.IAnOf}\n> - Merge {@link OpenApiV3_1.IJsonSchema.IAllOf} to {@link IChatGptSchema.IObject}\n> - Merge {@link OpenApiV3_1.IJsonSchema.IRecursiveReference} to {@link IChatGptSchema.IReference}\n> - When {@link IChatGptSchema.IConfig.strict} mode\n> - Every object properties must be required\n> - Do not allow {@link IChatGptSchema.IObject.additionalProperties}\n> \n> If compare with the {@link OpenApi.IJsonSchema}, the emended JSON schema specification,\n> \n> - {@link IChatGptSchema.IAnyOf} instead of the {@link OpenApi.IJsonSchema.IOneOf}\n> - {@link IChatGptSchema.IParameters.$defs} instead of the {@link OpenApi.IJsonSchema.IComponents.schemas}\n> - {@link IChatGptSchema.IString.enum} instead of the {@link OpenApi.IJsonSchema.IConstant}\n> - {@link IChatGptSchema.additionalProperties} is fixed to `false`\n> - No tuple type {@link OpenApi.IJsonSchema.ITuple} support\n> - When {@link IChatGptSchema.IConfig.strict} mode\n> - Every object properties must be required\n> - Do not allow {@link IChatGptSchema.IObject.additionalProperties}\n> \n> For reference, if you\'ve composed the `IChatGptSchema` type with the\n> {@link IChatGptSchema.IConfig.reference} `false` option (default is `false`),\n> only the recursived named types would be archived into the\n> {@link IChatGptSchema.IParameters.$defs}, and the others would be ecaped from the\n> {@link IChatGptSchema.IReference} type.\n> \n> Also, OpenAI has banned below constraint properties. Instead, `IChatGptSchema`\n> fills the {@link IChatGptSchema.__IAttribute.description} property with\n> the comment text like `"@format uuid"`.\n> \n> - {@link OpenApi.IJsonSchema.INumber.minimum}\n> - {@link OpenApi.IJsonSchema.INumber.maximum}\n> - {@link OpenApi.IJsonSchema.INumber.multipleOf}\n> - {@link OpenApi.IJsonSchema.IString.minLength}\n> - {@link OpenApi.IJsonSchema.IString.maxLength}\n> - {@link OpenApi.IJsonSchema.IString.format}\n> - {@link OpenApi.IJsonSchema.IString.pattern}\n> - {@link OpenApi.IJsonSchema.IString.contentMediaType}\n> - {@link OpenApi.IJsonSchema.IString.default}\n> - {@link OpenApi.IJsonSchema.IArray.minItems}\n> - {@link OpenApi.IJsonSchema.IArray.maxItems}\n> - {@link OpenApi.IJsonSchema.IArray.unique}\n> \n> Additionally, OpenAI cannot define the `description` property to the\n> {@link IChatGptSchema.IReference} type, and even does not understand\n> the capsulization to the {@link IChatGptSchema.IAnyOf} type.\n> Therefore, the `description` is written to the parent object type,\n> not the reference type.\n> \n> ```json\n> {\n> "type": "object",\n> "description": "### Description of {@link something} property.\\n\\n> Hello?",\n> "properties": {\n> "something": {\n> "$ref": "#/$defs/SomeObject"\n> }\n> }\n> }\n> ```\n\n### Description of {@link $defs} property:\n\n> Collection of the named types.\n\n### Description of {@link properties} property:\n\n> Properties of the object.\n> \n> The `properties` means a list of key-value pairs of the object\'s\n> regular properties. The key is the name of the regular property,\n> and the value is the type schema info.'
|
|
3366
3268
|
} ]
|
|
3367
3269
|
}
|
|
@@ -4211,6 +4113,104 @@ function execute(executor) {
|
|
|
4211
4113
|
};
|
|
4212
4114
|
}
|
|
4213
4115
|
|
|
4116
|
+
function transform(props) {
|
|
4117
|
+
if (props.prompt.type === "text") {
|
|
4118
|
+
return transformText({
|
|
4119
|
+
prompt: props.prompt
|
|
4120
|
+
});
|
|
4121
|
+
} else if (props.prompt.type === "select") {
|
|
4122
|
+
return transformSelect({
|
|
4123
|
+
operations: props.operations,
|
|
4124
|
+
prompt: props.prompt
|
|
4125
|
+
});
|
|
4126
|
+
} else if (props.prompt.type === "cancel") {
|
|
4127
|
+
return transformCancel({
|
|
4128
|
+
operations: props.operations,
|
|
4129
|
+
prompt: props.prompt
|
|
4130
|
+
});
|
|
4131
|
+
} else if (props.prompt.type === "execute") {
|
|
4132
|
+
return transformExecute({
|
|
4133
|
+
operations: props.operations,
|
|
4134
|
+
prompt: props.prompt
|
|
4135
|
+
});
|
|
4136
|
+
} else if (props.prompt.type === "describe") {
|
|
4137
|
+
return transformDescribe({
|
|
4138
|
+
operations: props.operations,
|
|
4139
|
+
prompt: props.prompt
|
|
4140
|
+
});
|
|
4141
|
+
}
|
|
4142
|
+
throw new Error("Invalid prompt type.");
|
|
4143
|
+
}
|
|
4144
|
+
|
|
4145
|
+
function transformText(props) {
|
|
4146
|
+
return createTextPrompt(props.prompt);
|
|
4147
|
+
}
|
|
4148
|
+
|
|
4149
|
+
function transformSelect(props) {
|
|
4150
|
+
return createSelectPrompt({
|
|
4151
|
+
id: props.prompt.id,
|
|
4152
|
+
selections: props.prompt.selections.map((select => createOperationSelection({
|
|
4153
|
+
operation: findOperation({
|
|
4154
|
+
operations: props.operations,
|
|
4155
|
+
input: select.operation
|
|
4156
|
+
}),
|
|
4157
|
+
reason: select.reason
|
|
4158
|
+
})))
|
|
4159
|
+
});
|
|
4160
|
+
}
|
|
4161
|
+
|
|
4162
|
+
function transformCancel(props) {
|
|
4163
|
+
return createCancelPrompt({
|
|
4164
|
+
id: props.prompt.id,
|
|
4165
|
+
selections: props.prompt.selections.map((select => createOperationSelection({
|
|
4166
|
+
operation: findOperation({
|
|
4167
|
+
operations: props.operations,
|
|
4168
|
+
input: select.operation
|
|
4169
|
+
}),
|
|
4170
|
+
reason: select.reason
|
|
4171
|
+
})))
|
|
4172
|
+
});
|
|
4173
|
+
}
|
|
4174
|
+
|
|
4175
|
+
function transformExecute(props) {
|
|
4176
|
+
return createExecutePrompt({
|
|
4177
|
+
id: props.prompt.id,
|
|
4178
|
+
operation: findOperation({
|
|
4179
|
+
operations: props.operations,
|
|
4180
|
+
input: props.prompt.operation
|
|
4181
|
+
}),
|
|
4182
|
+
arguments: props.prompt.arguments,
|
|
4183
|
+
value: props.prompt.value
|
|
4184
|
+
});
|
|
4185
|
+
}
|
|
4186
|
+
|
|
4187
|
+
function transformDescribe(props) {
|
|
4188
|
+
return createDescribePrompt({
|
|
4189
|
+
text: props.prompt.text,
|
|
4190
|
+
executes: props.prompt.executes.map((next => transformExecute({
|
|
4191
|
+
operations: props.operations,
|
|
4192
|
+
prompt: next
|
|
4193
|
+
})))
|
|
4194
|
+
});
|
|
4195
|
+
}
|
|
4196
|
+
|
|
4197
|
+
function findOperation(props) {
|
|
4198
|
+
const found = props.operations.get(props.input.controller)?.get(props.input.function);
|
|
4199
|
+
if (found === undefined) {
|
|
4200
|
+
throw new Error(`No operation found: (controller: ${props.input.controller}, function: ${props.input.function})`);
|
|
4201
|
+
}
|
|
4202
|
+
return found;
|
|
4203
|
+
}
|
|
4204
|
+
|
|
4205
|
+
const AgenticaPromptTransformer = {
|
|
4206
|
+
transform,
|
|
4207
|
+
transformText,
|
|
4208
|
+
transformSelect,
|
|
4209
|
+
transformCancel,
|
|
4210
|
+
transformExecute,
|
|
4211
|
+
transformDescribe
|
|
4212
|
+
};
|
|
4213
|
+
|
|
4214
4214
|
class Agentica {
|
|
4215
4215
|
constructor(props) {
|
|
4216
4216
|
this.props = props;
|
|
@@ -4595,7 +4595,7 @@ function assertHttpLlmApplication(props) {
|
|
|
4595
4595
|
if (undefined === value) return true;
|
|
4596
4596
|
return "object" === typeof value && null !== value && false === Array.isArray(value) && _iu5(value);
|
|
4597
4597
|
}));
|
|
4598
|
-
const _io114 = input => Array.isArray(input.type) && input.type.every((elem => "string" === elem || "number" === elem || "boolean" === elem || "object" === elem || "integer" === elem || "array" === elem || "null" === elem)) && (null === input["default"] || undefined === input["default"] || Array.isArray(input["default"])) && (undefined === input["enum"] || Array.isArray(input["enum"])) && ("string" === typeof input["const"] || "number" === typeof input["const"] || "boolean" === typeof input["const"]) && (undefined === input.nullable || "boolean" === typeof input.nullable) && (undefined === input.title || "string" === typeof input.title) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.deprecated || "boolean" === typeof input.deprecated) && true && (undefined === input.examples || "object" === typeof input.examples && null !== input.examples && false === Array.isArray(input.examples) && _io58(input.examples)) && (undefined === input.minimum || "number" === typeof input.minimum) && (undefined === input.maximum || "number" === typeof input.maximum) && (undefined === input.exclusiveMinimum || "number" === typeof input.exclusiveMinimum || "boolean" === typeof input.exclusiveMinimum) && (undefined === input.exclusiveMaximum || "number" === typeof input.exclusiveMaximum || "boolean" === typeof input.exclusiveMaximum) && (undefined === input.multipleOf || "number" === typeof input.multipleOf && 0 < input.multipleOf) && (undefined === input.maxLength || "number" === typeof input.maxLength && (Math.floor(input.maxLength) === input.maxLength && 0 <= input.maxLength && input.maxLength <= 0x10000000000000000)) && (undefined === input.format || "string" === typeof input.format) && (undefined === input.pattern || "string" === typeof input.pattern) && (undefined === input.contentMediaType || "string" === typeof input.contentMediaType) && (undefined === input.minLength || "number" === typeof input.minLength && (Math.floor(input.minLength) === input.minLength && 0 <= input.minLength && input.minLength <= 0x10000000000000000)) && (null !== input.items && (undefined === input.items || (Array.isArray(input.items) && input.items.every((elem => "object" === typeof elem && null !== elem && false === Array.isArray(elem) && _iu5(elem))) || "object" === typeof input.items && null !== input.items && false === Array.isArray(input.items) && _iu5(input.items)))) && (undefined === input.prefixItems || Array.isArray(input.prefixItems) && input.prefixItems.every((elem => "object" === typeof elem && null !== elem && false === Array.isArray(elem) && _iu5(elem)))) && (undefined === input.uniqueItems || "boolean" === typeof input.uniqueItems) && (null !== input.additionalItems && (undefined === input.additionalItems || "boolean" === typeof input.additionalItems || "object" === typeof input.additionalItems && null !== input.additionalItems && false === Array.isArray(input.additionalItems) && _iu5(input.additionalItems))) && (undefined === input.minItems || "number" === typeof input.minItems && (Math.floor(input.minItems) === input.minItems && 0 <= input.minItems && input.minItems <= 0x10000000000000000)) && (undefined === input.maxItems || "number" === typeof input.maxItems && (Math.floor(input.maxItems) === input.maxItems && 0 <= input.maxItems && input.maxItems <= 0x10000000000000000)) && (
|
|
4598
|
+
const _io114 = input => Array.isArray(input.type) && input.type.every((elem => "string" === elem || "number" === elem || "boolean" === elem || "object" === elem || "integer" === elem || "array" === elem || "null" === elem)) && (null === input["default"] || undefined === input["default"] || Array.isArray(input["default"])) && (undefined === input["enum"] || Array.isArray(input["enum"])) && ("string" === typeof input["const"] || "number" === typeof input["const"] || "boolean" === typeof input["const"]) && (undefined === input.nullable || "boolean" === typeof input.nullable) && (undefined === input.title || "string" === typeof input.title) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.deprecated || "boolean" === typeof input.deprecated) && true && (undefined === input.examples || "object" === typeof input.examples && null !== input.examples && false === Array.isArray(input.examples) && _io58(input.examples)) && (undefined === input.minimum || "number" === typeof input.minimum) && (undefined === input.maximum || "number" === typeof input.maximum) && (undefined === input.exclusiveMinimum || "number" === typeof input.exclusiveMinimum || "boolean" === typeof input.exclusiveMinimum) && (undefined === input.exclusiveMaximum || "number" === typeof input.exclusiveMaximum || "boolean" === typeof input.exclusiveMaximum) && (undefined === input.multipleOf || "number" === typeof input.multipleOf && 0 < input.multipleOf) && (undefined === input.maxLength || "number" === typeof input.maxLength && (Math.floor(input.maxLength) === input.maxLength && 0 <= input.maxLength && input.maxLength <= 0x10000000000000000)) && (undefined === input.format || "string" === typeof input.format) && (undefined === input.pattern || "string" === typeof input.pattern) && (undefined === input.contentMediaType || "string" === typeof input.contentMediaType) && (undefined === input.minLength || "number" === typeof input.minLength && (Math.floor(input.minLength) === input.minLength && 0 <= input.minLength && input.minLength <= 0x10000000000000000)) && (null !== input.items && (undefined === input.items || (Array.isArray(input.items) && input.items.every((elem => "object" === typeof elem && null !== elem && false === Array.isArray(elem) && _iu5(elem))) || "object" === typeof input.items && null !== input.items && false === Array.isArray(input.items) && _iu5(input.items)))) && (undefined === input.prefixItems || Array.isArray(input.prefixItems) && input.prefixItems.every((elem => "object" === typeof elem && null !== elem && false === Array.isArray(elem) && _iu5(elem)))) && (undefined === input.uniqueItems || "boolean" === typeof input.uniqueItems) && (null !== input.additionalItems && (undefined === input.additionalItems || "boolean" === typeof input.additionalItems || "object" === typeof input.additionalItems && null !== input.additionalItems && false === Array.isArray(input.additionalItems) && _iu5(input.additionalItems))) && (undefined === input.minItems || "number" === typeof input.minItems && (Math.floor(input.minItems) === input.minItems && 0 <= input.minItems && input.minItems <= 0x10000000000000000)) && (undefined === input.maxItems || "number" === typeof input.maxItems && (Math.floor(input.maxItems) === input.maxItems && 0 <= input.maxItems && input.maxItems <= 0x10000000000000000)) && (null !== input.additionalProperties && (undefined === input.additionalProperties || "boolean" === typeof input.additionalProperties || "object" === typeof input.additionalProperties && null !== input.additionalProperties && false === Array.isArray(input.additionalProperties) && _iu5(input.additionalProperties))) && (undefined === input.properties || "object" === typeof input.properties && null !== input.properties && false === Array.isArray(input.properties) && _io113(input.properties)) && (undefined === input.required || Array.isArray(input.required) && input.required.every((elem => "string" === typeof elem))) && (undefined === input.maxProperties || "number" === typeof input.maxProperties) && (undefined === input.minProperties || "number" === typeof input.minProperties) && (Array.isArray(input.oneOf) && input.oneOf.every((elem => "object" === typeof elem && null !== elem && false === Array.isArray(elem) && _iu5(elem)))) && (undefined === input.discriminator || "object" === typeof input.discriminator && null !== input.discriminator && _io127(input.discriminator)) && (Array.isArray(input.anyOf) && input.anyOf.every((elem => "object" === typeof elem && null !== elem && false === Array.isArray(elem) && _iu5(elem)))) && (Array.isArray(input.allOf) && input.allOf.every((elem => "object" === typeof elem && null !== elem && false === Array.isArray(elem) && _iu5(elem)))) && "string" === typeof input.$ref;
|
|
4599
4599
|
const _io115 = input => ("string" === typeof input["const"] || "number" === typeof input["const"] || "boolean" === typeof input["const"]) && (undefined === input.nullable || "boolean" === typeof input.nullable) && (undefined === input.title || "string" === typeof input.title) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.deprecated || "boolean" === typeof input.deprecated) && true && (undefined === input.examples || "object" === typeof input.examples && null !== input.examples && false === Array.isArray(input.examples) && _io58(input.examples));
|
|
4600
4600
|
const _io116 = input => (undefined === input.nullable || "boolean" === typeof input.nullable) && (null === input["default"] || undefined === input["default"] || "boolean" === typeof input["default"]) && (undefined === input["enum"] || Array.isArray(input["enum"]) && input["enum"].every((elem => null === elem || "boolean" === typeof elem))) && "boolean" === input.type && (undefined === input.title || "string" === typeof input.title) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.deprecated || "boolean" === typeof input.deprecated) && true && (undefined === input.examples || "object" === typeof input.examples && null !== input.examples && false === Array.isArray(input.examples) && _io58(input.examples));
|
|
4601
4601
|
const _io117 = input => (undefined === input.nullable || "boolean" === typeof input.nullable) && (null === input["default"] || undefined === input["default"] || "number" === typeof input["default"] && (Math.floor(input["default"]) === input["default"] && -0x8000000000000000 <= input["default"] && input["default"] <= 0x8000000000000000)) && (undefined === input["enum"] || Array.isArray(input["enum"]) && input["enum"].every((elem => null === elem || "number" === typeof elem))) && (undefined === input.minimum || "number" === typeof input.minimum && (Math.floor(input.minimum) === input.minimum && -0x8000000000000000 <= input.minimum && input.minimum <= 0x8000000000000000)) && (undefined === input.maximum || "number" === typeof input.maximum && (Math.floor(input.maximum) === input.maximum && -0x8000000000000000 <= input.maximum && input.maximum <= 0x8000000000000000)) && (undefined === input.exclusiveMinimum || "number" === typeof input.exclusiveMinimum && (Math.floor(input.exclusiveMinimum) === input.exclusiveMinimum && -0x8000000000000000 <= input.exclusiveMinimum && input.exclusiveMinimum <= 0x8000000000000000) || "boolean" === typeof input.exclusiveMinimum) && (undefined === input.exclusiveMaximum || "number" === typeof input.exclusiveMaximum && (Math.floor(input.exclusiveMaximum) === input.exclusiveMaximum && -0x8000000000000000 <= input.exclusiveMaximum && input.exclusiveMaximum <= 0x8000000000000000) || "boolean" === typeof input.exclusiveMaximum) && (undefined === input.multipleOf || "number" === typeof input.multipleOf && (Math.floor(input.multipleOf) === input.multipleOf && 0 <= input.multipleOf && input.multipleOf <= 0x10000000000000000 && 0 < input.multipleOf)) && "integer" === input.type && (undefined === input.title || "string" === typeof input.title) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.deprecated || "boolean" === typeof input.deprecated) && true && (undefined === input.examples || "object" === typeof input.examples && null !== input.examples && false === Array.isArray(input.examples) && _io58(input.examples));
|
|
@@ -9660,21 +9660,6 @@ function assertHttpLlmApplication(props) {
|
|
|
9660
9660
|
path: _path + ".maxItems",
|
|
9661
9661
|
expected: '((number & Type<"uint64">) | undefined)',
|
|
9662
9662
|
value: input.maxItems
|
|
9663
|
-
}, _errorFactory)) && (undefined === input.required || (Array.isArray(input.required) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
9664
|
-
method: "typia.assert",
|
|
9665
|
-
path: _path + ".required",
|
|
9666
|
-
expected: "(Array<string> | undefined)",
|
|
9667
|
-
value: input.required
|
|
9668
|
-
}, _errorFactory)) && input.required.every(((elem, _index131) => "string" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
9669
|
-
method: "typia.assert",
|
|
9670
|
-
path: _path + ".required[" + _index131 + "]",
|
|
9671
|
-
expected: "string",
|
|
9672
|
-
value: elem
|
|
9673
|
-
}, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
9674
|
-
method: "typia.assert",
|
|
9675
|
-
path: _path + ".required",
|
|
9676
|
-
expected: "(Array<string> | undefined)",
|
|
9677
|
-
value: input.required
|
|
9678
9663
|
}, _errorFactory)) && ((null !== input.additionalProperties || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
9679
9664
|
method: "typia.assert",
|
|
9680
9665
|
path: _path + ".additionalProperties",
|
|
@@ -9700,6 +9685,21 @@ function assertHttpLlmApplication(props) {
|
|
|
9700
9685
|
path: _path + ".properties",
|
|
9701
9686
|
expected: "(Record<string, OpenApiV3_1.IJsonSchema> | undefined)",
|
|
9702
9687
|
value: input.properties
|
|
9688
|
+
}, _errorFactory)) && (undefined === input.required || (Array.isArray(input.required) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
9689
|
+
method: "typia.assert",
|
|
9690
|
+
path: _path + ".required",
|
|
9691
|
+
expected: "(Array<string> | undefined)",
|
|
9692
|
+
value: input.required
|
|
9693
|
+
}, _errorFactory)) && input.required.every(((elem, _index131) => "string" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
9694
|
+
method: "typia.assert",
|
|
9695
|
+
path: _path + ".required[" + _index131 + "]",
|
|
9696
|
+
expected: "string",
|
|
9697
|
+
value: elem
|
|
9698
|
+
}, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
9699
|
+
method: "typia.assert",
|
|
9700
|
+
path: _path + ".required",
|
|
9701
|
+
expected: "(Array<string> | undefined)",
|
|
9702
|
+
value: input.required
|
|
9703
9703
|
}, _errorFactory)) && (undefined === input.maxProperties || "number" === typeof input.maxProperties || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
9704
9704
|
method: "typia.assert",
|
|
9705
9705
|
path: _path + ".maxProperties",
|
|
@@ -13766,7 +13766,7 @@ function validateHttpLlmApplication(props) {
|
|
|
13766
13766
|
if (undefined === value) return true;
|
|
13767
13767
|
return "object" === typeof value && null !== value && false === Array.isArray(value) && _iu5(value);
|
|
13768
13768
|
}));
|
|
13769
|
-
const _io114 = input => Array.isArray(input.type) && input.type.every((elem => "string" === elem || "number" === elem || "boolean" === elem || "object" === elem || "integer" === elem || "array" === elem || "null" === elem)) && (null === input["default"] || undefined === input["default"] || Array.isArray(input["default"])) && (undefined === input["enum"] || Array.isArray(input["enum"])) && ("string" === typeof input["const"] || "number" === typeof input["const"] || "boolean" === typeof input["const"]) && (undefined === input.nullable || "boolean" === typeof input.nullable) && (undefined === input.title || "string" === typeof input.title) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.deprecated || "boolean" === typeof input.deprecated) && true && (undefined === input.examples || "object" === typeof input.examples && null !== input.examples && false === Array.isArray(input.examples) && _io58(input.examples)) && (undefined === input.minimum || "number" === typeof input.minimum) && (undefined === input.maximum || "number" === typeof input.maximum) && (undefined === input.exclusiveMinimum || "number" === typeof input.exclusiveMinimum || "boolean" === typeof input.exclusiveMinimum) && (undefined === input.exclusiveMaximum || "number" === typeof input.exclusiveMaximum || "boolean" === typeof input.exclusiveMaximum) && (undefined === input.multipleOf || "number" === typeof input.multipleOf && 0 < input.multipleOf) && (undefined === input.maxLength || "number" === typeof input.maxLength && (Math.floor(input.maxLength) === input.maxLength && 0 <= input.maxLength && input.maxLength <= 0x10000000000000000)) && (undefined === input.format || "string" === typeof input.format) && (undefined === input.pattern || "string" === typeof input.pattern) && (undefined === input.contentMediaType || "string" === typeof input.contentMediaType) && (undefined === input.minLength || "number" === typeof input.minLength && (Math.floor(input.minLength) === input.minLength && 0 <= input.minLength && input.minLength <= 0x10000000000000000)) && (null !== input.items && (undefined === input.items || (Array.isArray(input.items) && input.items.every((elem => "object" === typeof elem && null !== elem && false === Array.isArray(elem) && _iu5(elem))) || "object" === typeof input.items && null !== input.items && false === Array.isArray(input.items) && _iu5(input.items)))) && (undefined === input.prefixItems || Array.isArray(input.prefixItems) && input.prefixItems.every((elem => "object" === typeof elem && null !== elem && false === Array.isArray(elem) && _iu5(elem)))) && (undefined === input.uniqueItems || "boolean" === typeof input.uniqueItems) && (null !== input.additionalItems && (undefined === input.additionalItems || "boolean" === typeof input.additionalItems || "object" === typeof input.additionalItems && null !== input.additionalItems && false === Array.isArray(input.additionalItems) && _iu5(input.additionalItems))) && (undefined === input.minItems || "number" === typeof input.minItems && (Math.floor(input.minItems) === input.minItems && 0 <= input.minItems && input.minItems <= 0x10000000000000000)) && (undefined === input.maxItems || "number" === typeof input.maxItems && (Math.floor(input.maxItems) === input.maxItems && 0 <= input.maxItems && input.maxItems <= 0x10000000000000000)) && (
|
|
13769
|
+
const _io114 = input => Array.isArray(input.type) && input.type.every((elem => "string" === elem || "number" === elem || "boolean" === elem || "object" === elem || "integer" === elem || "array" === elem || "null" === elem)) && (null === input["default"] || undefined === input["default"] || Array.isArray(input["default"])) && (undefined === input["enum"] || Array.isArray(input["enum"])) && ("string" === typeof input["const"] || "number" === typeof input["const"] || "boolean" === typeof input["const"]) && (undefined === input.nullable || "boolean" === typeof input.nullable) && (undefined === input.title || "string" === typeof input.title) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.deprecated || "boolean" === typeof input.deprecated) && true && (undefined === input.examples || "object" === typeof input.examples && null !== input.examples && false === Array.isArray(input.examples) && _io58(input.examples)) && (undefined === input.minimum || "number" === typeof input.minimum) && (undefined === input.maximum || "number" === typeof input.maximum) && (undefined === input.exclusiveMinimum || "number" === typeof input.exclusiveMinimum || "boolean" === typeof input.exclusiveMinimum) && (undefined === input.exclusiveMaximum || "number" === typeof input.exclusiveMaximum || "boolean" === typeof input.exclusiveMaximum) && (undefined === input.multipleOf || "number" === typeof input.multipleOf && 0 < input.multipleOf) && (undefined === input.maxLength || "number" === typeof input.maxLength && (Math.floor(input.maxLength) === input.maxLength && 0 <= input.maxLength && input.maxLength <= 0x10000000000000000)) && (undefined === input.format || "string" === typeof input.format) && (undefined === input.pattern || "string" === typeof input.pattern) && (undefined === input.contentMediaType || "string" === typeof input.contentMediaType) && (undefined === input.minLength || "number" === typeof input.minLength && (Math.floor(input.minLength) === input.minLength && 0 <= input.minLength && input.minLength <= 0x10000000000000000)) && (null !== input.items && (undefined === input.items || (Array.isArray(input.items) && input.items.every((elem => "object" === typeof elem && null !== elem && false === Array.isArray(elem) && _iu5(elem))) || "object" === typeof input.items && null !== input.items && false === Array.isArray(input.items) && _iu5(input.items)))) && (undefined === input.prefixItems || Array.isArray(input.prefixItems) && input.prefixItems.every((elem => "object" === typeof elem && null !== elem && false === Array.isArray(elem) && _iu5(elem)))) && (undefined === input.uniqueItems || "boolean" === typeof input.uniqueItems) && (null !== input.additionalItems && (undefined === input.additionalItems || "boolean" === typeof input.additionalItems || "object" === typeof input.additionalItems && null !== input.additionalItems && false === Array.isArray(input.additionalItems) && _iu5(input.additionalItems))) && (undefined === input.minItems || "number" === typeof input.minItems && (Math.floor(input.minItems) === input.minItems && 0 <= input.minItems && input.minItems <= 0x10000000000000000)) && (undefined === input.maxItems || "number" === typeof input.maxItems && (Math.floor(input.maxItems) === input.maxItems && 0 <= input.maxItems && input.maxItems <= 0x10000000000000000)) && (null !== input.additionalProperties && (undefined === input.additionalProperties || "boolean" === typeof input.additionalProperties || "object" === typeof input.additionalProperties && null !== input.additionalProperties && false === Array.isArray(input.additionalProperties) && _iu5(input.additionalProperties))) && (undefined === input.properties || "object" === typeof input.properties && null !== input.properties && false === Array.isArray(input.properties) && _io113(input.properties)) && (undefined === input.required || Array.isArray(input.required) && input.required.every((elem => "string" === typeof elem))) && (undefined === input.maxProperties || "number" === typeof input.maxProperties) && (undefined === input.minProperties || "number" === typeof input.minProperties) && (Array.isArray(input.oneOf) && input.oneOf.every((elem => "object" === typeof elem && null !== elem && false === Array.isArray(elem) && _iu5(elem)))) && (undefined === input.discriminator || "object" === typeof input.discriminator && null !== input.discriminator && _io127(input.discriminator)) && (Array.isArray(input.anyOf) && input.anyOf.every((elem => "object" === typeof elem && null !== elem && false === Array.isArray(elem) && _iu5(elem)))) && (Array.isArray(input.allOf) && input.allOf.every((elem => "object" === typeof elem && null !== elem && false === Array.isArray(elem) && _iu5(elem)))) && "string" === typeof input.$ref;
|
|
13770
13770
|
const _io115 = input => ("string" === typeof input["const"] || "number" === typeof input["const"] || "boolean" === typeof input["const"]) && (undefined === input.nullable || "boolean" === typeof input.nullable) && (undefined === input.title || "string" === typeof input.title) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.deprecated || "boolean" === typeof input.deprecated) && true && (undefined === input.examples || "object" === typeof input.examples && null !== input.examples && false === Array.isArray(input.examples) && _io58(input.examples));
|
|
13771
13771
|
const _io116 = input => (undefined === input.nullable || "boolean" === typeof input.nullable) && (null === input["default"] || undefined === input["default"] || "boolean" === typeof input["default"]) && (undefined === input["enum"] || Array.isArray(input["enum"]) && input["enum"].every((elem => null === elem || "boolean" === typeof elem))) && "boolean" === input.type && (undefined === input.title || "string" === typeof input.title) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.deprecated || "boolean" === typeof input.deprecated) && true && (undefined === input.examples || "object" === typeof input.examples && null !== input.examples && false === Array.isArray(input.examples) && _io58(input.examples));
|
|
13772
13772
|
const _io117 = input => (undefined === input.nullable || "boolean" === typeof input.nullable) && (null === input["default"] || undefined === input["default"] || "number" === typeof input["default"] && (Math.floor(input["default"]) === input["default"] && -0x8000000000000000 <= input["default"] && input["default"] <= 0x8000000000000000)) && (undefined === input["enum"] || Array.isArray(input["enum"]) && input["enum"].every((elem => null === elem || "number" === typeof elem))) && (undefined === input.minimum || "number" === typeof input.minimum && (Math.floor(input.minimum) === input.minimum && -0x8000000000000000 <= input.minimum && input.minimum <= 0x8000000000000000)) && (undefined === input.maximum || "number" === typeof input.maximum && (Math.floor(input.maximum) === input.maximum && -0x8000000000000000 <= input.maximum && input.maximum <= 0x8000000000000000)) && (undefined === input.exclusiveMinimum || "number" === typeof input.exclusiveMinimum && (Math.floor(input.exclusiveMinimum) === input.exclusiveMinimum && -0x8000000000000000 <= input.exclusiveMinimum && input.exclusiveMinimum <= 0x8000000000000000) || "boolean" === typeof input.exclusiveMinimum) && (undefined === input.exclusiveMaximum || "number" === typeof input.exclusiveMaximum && (Math.floor(input.exclusiveMaximum) === input.exclusiveMaximum && -0x8000000000000000 <= input.exclusiveMaximum && input.exclusiveMaximum <= 0x8000000000000000) || "boolean" === typeof input.exclusiveMaximum) && (undefined === input.multipleOf || "number" === typeof input.multipleOf && (Math.floor(input.multipleOf) === input.multipleOf && 0 <= input.multipleOf && input.multipleOf <= 0x10000000000000000 && 0 < input.multipleOf)) && "integer" === input.type && (undefined === input.title || "string" === typeof input.title) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.deprecated || "boolean" === typeof input.deprecated) && true && (undefined === input.examples || "object" === typeof input.examples && null !== input.examples && false === Array.isArray(input.examples) && _io58(input.examples));
|
|
@@ -17913,18 +17913,6 @@ function validateHttpLlmApplication(props) {
|
|
|
17913
17913
|
path: _path + ".maxItems",
|
|
17914
17914
|
expected: '((number & Type<"uint64">) | undefined)',
|
|
17915
17915
|
value: input.maxItems
|
|
17916
|
-
}), undefined === input.required || (Array.isArray(input.required) || _report(_exceptionable, {
|
|
17917
|
-
path: _path + ".required",
|
|
17918
|
-
expected: "(Array<string> | undefined)",
|
|
17919
|
-
value: input.required
|
|
17920
|
-
})) && input.required.map(((elem, _index131) => "string" === typeof elem || _report(_exceptionable, {
|
|
17921
|
-
path: _path + ".required[" + _index131 + "]",
|
|
17922
|
-
expected: "string",
|
|
17923
|
-
value: elem
|
|
17924
|
-
}))).every((flag => flag)) || _report(_exceptionable, {
|
|
17925
|
-
path: _path + ".required",
|
|
17926
|
-
expected: "(Array<string> | undefined)",
|
|
17927
|
-
value: input.required
|
|
17928
17916
|
}), (null !== input.additionalProperties || _report(_exceptionable, {
|
|
17929
17917
|
path: _path + ".additionalProperties",
|
|
17930
17918
|
expected: "(OpenApiV3_1.IJsonSchema.IAllOf | OpenApiV3_1.IJsonSchema.IAnyOf | OpenApiV3_1.IJsonSchema.IArray | OpenApiV3_1.IJsonSchema.IBoolean | OpenApiV3_1.IJsonSchema.IConstant | OpenApiV3_1.IJsonSchema.IInteger | OpenApiV3_1.IJsonSchema.IMixed | OpenApiV3_1.IJsonSchema.INull | OpenApiV3_1.IJsonSchema.INumber | OpenApiV3_1.IJsonSchema.IObject | OpenApiV3_1.IJsonSchema.IOneOf | OpenApiV3_1.IJsonSchema.IRecursiveReference | OpenApiV3_1.IJsonSchema.IReference<string> | OpenApiV3_1.IJsonSchema.IString | OpenApiV3_1.IJsonSchema.IUnknown | boolean | undefined)",
|
|
@@ -17945,6 +17933,18 @@ function validateHttpLlmApplication(props) {
|
|
|
17945
17933
|
path: _path + ".properties",
|
|
17946
17934
|
expected: "(Record<string, OpenApiV3_1.IJsonSchema> | undefined)",
|
|
17947
17935
|
value: input.properties
|
|
17936
|
+
}), undefined === input.required || (Array.isArray(input.required) || _report(_exceptionable, {
|
|
17937
|
+
path: _path + ".required",
|
|
17938
|
+
expected: "(Array<string> | undefined)",
|
|
17939
|
+
value: input.required
|
|
17940
|
+
})) && input.required.map(((elem, _index131) => "string" === typeof elem || _report(_exceptionable, {
|
|
17941
|
+
path: _path + ".required[" + _index131 + "]",
|
|
17942
|
+
expected: "string",
|
|
17943
|
+
value: elem
|
|
17944
|
+
}))).every((flag => flag)) || _report(_exceptionable, {
|
|
17945
|
+
path: _path + ".required",
|
|
17946
|
+
expected: "(Array<string> | undefined)",
|
|
17947
|
+
value: input.required
|
|
17948
17948
|
}), undefined === input.maxProperties || "number" === typeof input.maxProperties || _report(_exceptionable, {
|
|
17949
17949
|
path: _path + ".maxProperties",
|
|
17950
17950
|
expected: "(number | undefined)",
|