llm-exe 0.0.7 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/executor/_base.d.ts +8 -5
- package/dist/executor/_base.js +21 -7
- package/dist/executor/_base.js.map +1 -1
- package/dist/executor/_functions.js.map +1 -1
- package/dist/executor/index.d.ts +1 -0
- package/dist/executor/index.js +3 -1
- package/dist/executor/index.js.map +1 -1
- package/dist/executor/llm-openai-function.d.ts +16 -0
- package/dist/executor/llm-openai-function.js +28 -0
- package/dist/executor/llm-openai-function.js.map +1 -0
- package/dist/executor/llm.d.ts +5 -2
- package/dist/executor/llm.js +11 -2
- package/dist/executor/llm.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/chat.d.ts +52 -5
- package/dist/interfaces/functions.d.ts +5 -0
- package/dist/interfaces/openai.d.ts +14 -1
- package/dist/interfaces/parser.d.ts +1 -2
- package/dist/interfaces/utils.d.ts +3 -0
- package/dist/llm/_base.d.ts +7 -3
- package/dist/llm/_base.js +20 -5
- package/dist/llm/_base.js.map +1 -1
- package/dist/llm/openai.d.ts +4 -3
- package/dist/llm/openai.js +15 -15
- package/dist/llm/openai.js.map +1 -1
- package/dist/llm/output/openai.d.ts +6 -2
- package/dist/llm/output/openai.js +8 -1
- package/dist/llm/output/openai.js.map +1 -1
- package/dist/parser/_base.d.ts +16 -7
- package/dist/parser/_base.js +32 -13
- package/dist/parser/_base.js.map +1 -1
- package/dist/parser/_functions.d.ts +46 -40
- package/dist/parser/_functions.js +3 -3
- package/dist/parser/_functions.js.map +1 -1
- package/dist/parser/index.d.ts +3 -2
- package/dist/parser/index.js +4 -1
- package/dist/parser/index.js.map +1 -1
- package/dist/parser/parsers/JsonParser.d.ts +5 -5
- package/dist/parser/parsers/JsonParser.js +4 -4
- package/dist/parser/parsers/JsonParser.js.map +1 -1
- package/dist/parser/parsers/ListToJsonParser.d.ts +5 -5
- package/dist/parser/parsers/ListToJsonParser.js +3 -3
- package/dist/parser/parsers/ListToJsonParser.js.map +1 -1
- package/dist/parser/parsers/OpenAiFunctionParser.d.ts +16 -0
- package/dist/parser/parsers/OpenAiFunctionParser.js +32 -0
- package/dist/parser/parsers/OpenAiFunctionParser.js.map +1 -0
- package/dist/plugins/callable/callable.d.ts +7 -6
- package/dist/plugins/callable/callable.js +7 -0
- package/dist/plugins/callable/callable.js.map +1 -1
- package/dist/plugins/callable/index.d.ts +7 -16
- package/dist/plugins/callable/index.js +7 -6
- package/dist/plugins/callable/index.js.map +1 -1
- package/dist/prompt/_base.js +2 -2
- package/dist/prompt/_base.js.map +1 -1
- package/dist/prompt/chat.d.ts +21 -1
- package/dist/prompt/chat.js +97 -12
- package/dist/prompt/chat.js.map +1 -1
- package/dist/state/dialogue.d.ts +9 -2
- package/dist/state/dialogue.js +31 -1
- package/dist/state/dialogue.js.map +1 -1
- package/dist/utils/const.d.ts +13 -0
- package/dist/utils/const.js +14 -1
- package/dist/utils/const.js.map +1 -1
- package/dist/utils/modules/index.d.ts +6 -0
- package/dist/utils/modules/index.js +4 -0
- package/dist/utils/modules/index.js.map +1 -1
- package/dist/utils/modules/json-schema-filter.js +1 -1
- package/dist/utils/modules/json-schema-filter.js.map +1 -1
- package/package.json +6 -4
package/dist/executor/_base.d.ts
CHANGED
|
@@ -23,37 +23,38 @@ export declare abstract class BaseExecutor<I extends PlainObject, O = any, H ext
|
|
|
23
23
|
*/
|
|
24
24
|
name: string;
|
|
25
25
|
/**
|
|
26
|
-
* @property executions -
|
|
26
|
+
* @property executions -
|
|
27
27
|
*/
|
|
28
28
|
executions: number;
|
|
29
|
+
traceId: string | null;
|
|
29
30
|
/**
|
|
30
31
|
* @property hooks - hooks to be ran during execution
|
|
31
32
|
*/
|
|
32
33
|
hooks: any;
|
|
33
34
|
readonly allowedHooks: any[];
|
|
34
35
|
constructor(name: string, type: string, options?: CoreExecutorExecuteOptions<H>);
|
|
35
|
-
abstract handler(input: I): Promise<any>;
|
|
36
|
+
abstract handler(input: I, _options?: any): Promise<any>;
|
|
36
37
|
/**
|
|
37
38
|
*
|
|
38
39
|
* Used to filter the input of the handler
|
|
39
40
|
* @param _input
|
|
40
41
|
* @returns original input formatted for handler
|
|
41
42
|
*/
|
|
42
|
-
getHandlerInput(_input: I, _metadata: ExecutorExecutionMetadata<I, any
|
|
43
|
+
getHandlerInput(_input: I, _metadata: ExecutorExecutionMetadata<I, any>, _options?: any): any;
|
|
43
44
|
/**
|
|
44
45
|
*
|
|
45
46
|
* Used to filter the output of the handler
|
|
46
47
|
* @param _input
|
|
47
48
|
* @returns output O
|
|
48
49
|
*/
|
|
49
|
-
getHandlerOutput(out: any, _metadata: ExecutorExecutionMetadata<any, O
|
|
50
|
+
getHandlerOutput(out: any, _metadata: ExecutorExecutionMetadata<any, O>, _options?: any): O;
|
|
50
51
|
/**
|
|
51
52
|
*
|
|
52
53
|
* execute - Runs the executor
|
|
53
54
|
* @param _input
|
|
54
55
|
* @returns handler output
|
|
55
56
|
*/
|
|
56
|
-
execute(_input: I): Promise<O>;
|
|
57
|
+
execute(_input: I, _options?: any): Promise<O>;
|
|
57
58
|
metadata(): Record<string, any>;
|
|
58
59
|
getMetadata(metadata?: Record<string, any>): ExecutorMetadata;
|
|
59
60
|
runHook(hook: keyof H, _metadata: ExecutorExecutionMetadata): void;
|
|
@@ -62,4 +63,6 @@ export declare abstract class BaseExecutor<I extends PlainObject, O = any, H ext
|
|
|
62
63
|
on(eventName: keyof H, fn: ListenerFunction): this;
|
|
63
64
|
off(eventName: keyof H, fn: ListenerFunction): this;
|
|
64
65
|
once(eventName: keyof H, fn: ListenerFunction): this;
|
|
66
|
+
withTraceId(traceId: string): this;
|
|
67
|
+
getTraceId(): string | null;
|
|
65
68
|
}
|
package/dist/executor/_base.js
CHANGED
|
@@ -49,7 +49,7 @@ class BaseExecutor {
|
|
|
49
49
|
value: void 0
|
|
50
50
|
});
|
|
51
51
|
/**
|
|
52
|
-
* @property executions -
|
|
52
|
+
* @property executions -
|
|
53
53
|
*/
|
|
54
54
|
Object.defineProperty(this, "executions", {
|
|
55
55
|
enumerable: true,
|
|
@@ -57,6 +57,12 @@ class BaseExecutor {
|
|
|
57
57
|
writable: true,
|
|
58
58
|
value: void 0
|
|
59
59
|
});
|
|
60
|
+
Object.defineProperty(this, "traceId", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
configurable: true,
|
|
63
|
+
writable: true,
|
|
64
|
+
value: null
|
|
65
|
+
});
|
|
60
66
|
/**
|
|
61
67
|
* @property hooks - hooks to be ran during execution
|
|
62
68
|
*/
|
|
@@ -92,7 +98,7 @@ class BaseExecutor {
|
|
|
92
98
|
* @param _input
|
|
93
99
|
* @returns original input formatted for handler
|
|
94
100
|
*/
|
|
95
|
-
getHandlerInput(_input, _metadata) {
|
|
101
|
+
getHandlerInput(_input, _metadata, _options) {
|
|
96
102
|
return (0, utils_1.ensureInputIsObject)(_input);
|
|
97
103
|
}
|
|
98
104
|
/**
|
|
@@ -101,7 +107,7 @@ class BaseExecutor {
|
|
|
101
107
|
* @param _input
|
|
102
108
|
* @returns output O
|
|
103
109
|
*/
|
|
104
|
-
getHandlerOutput(out, _metadata) {
|
|
110
|
+
getHandlerOutput(out, _metadata, _options) {
|
|
105
111
|
return out;
|
|
106
112
|
}
|
|
107
113
|
/**
|
|
@@ -110,18 +116,18 @@ class BaseExecutor {
|
|
|
110
116
|
* @param _input
|
|
111
117
|
* @returns handler output
|
|
112
118
|
*/
|
|
113
|
-
async execute(_input) {
|
|
119
|
+
async execute(_input, _options) {
|
|
114
120
|
this.executions++;
|
|
115
121
|
const _metadata = (0, _metadata_1.createMetadataState)({
|
|
116
122
|
start: new Date().getTime(),
|
|
117
123
|
input: _input,
|
|
118
124
|
});
|
|
119
125
|
try {
|
|
120
|
-
const input = this.getHandlerInput(_input, _metadata.asPlainObject());
|
|
126
|
+
const input = this.getHandlerInput(_input, _metadata.asPlainObject(), _options);
|
|
121
127
|
_metadata.setItem({ handlerInput: input });
|
|
122
|
-
let result = await this.handler(input);
|
|
128
|
+
let result = await this.handler(input, _options);
|
|
123
129
|
_metadata.setItem({ handlerOutput: result });
|
|
124
|
-
const output = this.getHandlerOutput(result, _metadata.asPlainObject());
|
|
130
|
+
const output = this.getHandlerOutput(result, _metadata.asPlainObject(), _options);
|
|
125
131
|
_metadata.setItem({ output });
|
|
126
132
|
this.runHook("onSuccess", _metadata.asPlainObject());
|
|
127
133
|
return output;
|
|
@@ -141,6 +147,7 @@ class BaseExecutor {
|
|
|
141
147
|
}
|
|
142
148
|
getMetadata(metadata) {
|
|
143
149
|
return Object.assign({}, this.metadata(), {
|
|
150
|
+
traceId: this.getTraceId(),
|
|
144
151
|
id: this.id,
|
|
145
152
|
type: this.type,
|
|
146
153
|
name: this.name,
|
|
@@ -210,6 +217,13 @@ class BaseExecutor {
|
|
|
210
217
|
this.hooks[eventName].push(onceWrapper);
|
|
211
218
|
return this;
|
|
212
219
|
}
|
|
220
|
+
withTraceId(traceId) {
|
|
221
|
+
this.traceId = traceId;
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
224
|
+
getTraceId() {
|
|
225
|
+
return this.traceId;
|
|
226
|
+
}
|
|
213
227
|
}
|
|
214
228
|
exports.BaseExecutor = BaseExecutor;
|
|
215
229
|
//# sourceMappingURL=_base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_base.js","sourceRoot":"src/","sources":["executor/_base.ts"],"names":[],"mappings":";;;AAUA,mCAA0D;AAC1D,2CAAkD;AAClD,yCAA2E;AAE3E;;;;;GAKG;AACH,MAAsB,YAAY;
|
|
1
|
+
{"version":3,"file":"_base.js","sourceRoot":"src/","sources":["executor/_base.ts"],"names":[],"mappings":";;;AAUA,mCAA0D;AAC1D,2CAAkD;AAClD,yCAA2E;AAE3E;;;;;GAKG;AACH,MAAsB,YAAY;IAqChC,YACE,IAAY,EACZ,IAAY,EACZ,OAAuC;QAnCzC;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C,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QACnC,CAAC,CAAC;QACF,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,WAAW,CAAC,OAAgB;QAC1B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;CACF;AA5ND,oCA4NC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_functions.js","sourceRoot":"src/","sources":["executor/_functions.ts"],"names":[],"mappings":";;;AAUA,iCAAsC;AACtC,+BAAoC;
|
|
1
|
+
{"version":3,"file":"_functions.js","sourceRoot":"src/","sources":["executor/_functions.ts"],"names":[],"mappings":";;;AAUA,iCAAsC;AACtC,+BAAoC;AAGpC;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAChC,OAAqC,EACrC,OAAoC;IAEpC,OAAO,IAAI,mBAAY,CAAO,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;AACtD,CAAC;AALD,gDAKC;AAED;;;;;;;;GAQG;AACH,SAAgB,iBAAiB,CAM/B,gBAAoE,EACpE,OAAsD;IAEtD,OAAO,IAAI,iBAAW,CAA6B,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAChF,CAAC;AAVD,8CAUC"}
|
package/dist/executor/index.d.ts
CHANGED
package/dist/executor/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createLlmExecutor = exports.createCoreExecutor = exports.LlmExecutor = exports.CoreExecutor = exports.BaseExecutor = void 0;
|
|
3
|
+
exports.createLlmExecutor = exports.createCoreExecutor = exports.LlmExecutorOpenAiFunctions = exports.LlmExecutor = exports.CoreExecutor = exports.BaseExecutor = void 0;
|
|
4
4
|
var _base_1 = require("./_base");
|
|
5
5
|
Object.defineProperty(exports, "BaseExecutor", { enumerable: true, get: function () { return _base_1.BaseExecutor; } });
|
|
6
6
|
var core_1 = require("./core");
|
|
7
7
|
Object.defineProperty(exports, "CoreExecutor", { enumerable: true, get: function () { return core_1.CoreExecutor; } });
|
|
8
8
|
var llm_1 = require("./llm");
|
|
9
9
|
Object.defineProperty(exports, "LlmExecutor", { enumerable: true, get: function () { return llm_1.LlmExecutor; } });
|
|
10
|
+
var llm_openai_function_1 = require("./llm-openai-function");
|
|
11
|
+
Object.defineProperty(exports, "LlmExecutorOpenAiFunctions", { enumerable: true, get: function () { return llm_openai_function_1.LlmExecutorOpenAiFunctions; } });
|
|
10
12
|
var _functions_1 = require("./_functions");
|
|
11
13
|
Object.defineProperty(exports, "createCoreExecutor", { enumerable: true, get: function () { return _functions_1.createCoreExecutor; } });
|
|
12
14
|
Object.defineProperty(exports, "createLlmExecutor", { enumerable: true, get: function () { return _functions_1.createLlmExecutor; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["executor/index.ts"],"names":[],"mappings":";;;AAAA,iCAAuC;AAA9B,qGAAA,YAAY,OAAA;AACrB,+BAAsC;AAA7B,oGAAA,YAAY,OAAA;AACrB,6BAAoC;AAA3B,kGAAA,WAAW,OAAA;AACpB,2CAAqE;AAA5D,gHAAA,kBAAkB,OAAA;AAAE,+GAAA,iBAAiB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["executor/index.ts"],"names":[],"mappings":";;;AAAA,iCAAuC;AAA9B,qGAAA,YAAY,OAAA;AACrB,+BAAsC;AAA7B,oGAAA,YAAY,OAAA;AACrB,6BAAoC;AAA3B,kGAAA,WAAW,OAAA;AACpB,6DAAmE;AAA1D,iIAAA,0BAA0B,OAAA;AACnC,2CAAqE;AAA5D,gHAAA,kBAAkB,OAAA;AAAE,+GAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PromptInput, ParserOutput, CoreExecutorExecuteOptions, ExecutorWithLlmOptions, LlmExecutorHooks, OpenAiLlmExecutorOptions, OpenAiFunctionCall } from "../types";
|
|
2
|
+
import { OpenAI } from "../llm";
|
|
3
|
+
import { BasePrompt } from "../prompt";
|
|
4
|
+
import { BaseState } from "../state";
|
|
5
|
+
import { OpenAiFunctionParser } from "../parser/parsers/OpenAiFunctionParser";
|
|
6
|
+
import { BaseParser } from "../parser";
|
|
7
|
+
import { LlmExecutor } from "./llm";
|
|
8
|
+
/**
|
|
9
|
+
* Core Executor With LLM
|
|
10
|
+
*/
|
|
11
|
+
export declare class LlmExecutorOpenAiFunctions<Llm extends OpenAI, Prompt extends BasePrompt<Record<string, any>>, Parser extends BaseParser, State extends BaseState> extends LlmExecutor<Llm, Prompt, Parser, State> {
|
|
12
|
+
constructor(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<LlmExecutorHooks>);
|
|
13
|
+
execute<T extends Extract<OpenAiFunctionCall, "none">>(_input: PromptInput<Prompt>, _options: OpenAiLlmExecutorOptions<T>): Promise<ParserOutput<Parser>>;
|
|
14
|
+
execute<T extends Exclude<OpenAiFunctionCall, "none">>(_input: PromptInput<Prompt>, _options: OpenAiLlmExecutorOptions<T>): Promise<ParserOutput<OpenAiFunctionParser<Parser>>>;
|
|
15
|
+
execute<T extends OpenAiFunctionCall>(_input: PromptInput<Prompt>, _options: OpenAiLlmExecutorOptions<T>): Promise<ParserOutput<OpenAiFunctionParser<Parser>> | ParserOutput<Parser>>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LlmExecutorOpenAiFunctions = void 0;
|
|
4
|
+
const OpenAiFunctionParser_1 = require("../parser/parsers/OpenAiFunctionParser");
|
|
5
|
+
const parser_1 = require("../parser");
|
|
6
|
+
const llm_1 = require("./llm");
|
|
7
|
+
/**
|
|
8
|
+
* Core Executor With LLM
|
|
9
|
+
*/
|
|
10
|
+
class LlmExecutorOpenAiFunctions extends llm_1.LlmExecutor {
|
|
11
|
+
constructor(llmConfiguration, options) {
|
|
12
|
+
super(Object.assign({}, llmConfiguration, {
|
|
13
|
+
parser: new OpenAiFunctionParser_1.OpenAiFunctionParser({
|
|
14
|
+
parser: llmConfiguration.parser || new parser_1.StringParser(),
|
|
15
|
+
}),
|
|
16
|
+
}), options);
|
|
17
|
+
}
|
|
18
|
+
async execute(_input, _options) {
|
|
19
|
+
if (_options.function_call === "none") {
|
|
20
|
+
return super.execute(_input, _options);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return super.execute(_input, _options);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.LlmExecutorOpenAiFunctions = LlmExecutorOpenAiFunctions;
|
|
28
|
+
//# sourceMappingURL=llm-openai-function.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-openai-function.js","sourceRoot":"src/","sources":["executor/llm-openai-function.ts"],"names":[],"mappings":";;;AAYA,gFAA6E;AAC7E,qCAAoD;AACpD,+BAAoC;AAEpC;;GAEG;AACH,MAAa,0BAKX,SAAQ,iBAAuC;IAC/C,YACE,gBAAoE,EACpE,OAAsD;QAEtD,KAAK,CACH,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,gBAAgB,EAAE;YAClC,MAAM,EAAE,IAAI,2CAAoB,CAAC;gBAC/B,MAAM,EAAE,gBAAgB,CAAC,MAAM,IAAI,IAAI,qBAAY,EAAE;aACtD,CAAC;SACH,CAAC,EACF,OAAO,CACR,CAAC;IACJ,CAAC;IAiBD,KAAK,CAAC,OAAO,CACX,MAA2B,EAC3B,QAAqC;QAIrC,IAAI,QAAQ,CAAC,aAAa,KAAK,MAAM,EAAE;YACrC,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAyB,CAAC;SAChE;aAAM;YACL,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAEpC,CAAC;SACH;IACH,CAAC;CACF;AAjDD,gEAiDC"}
|
package/dist/executor/llm.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PromptInput, ParserOutput, CoreExecutorExecuteOptions, ExecutorWithLlmOptions, ExecutorExecutionMetadata, LlmExecutorHooks } from "../types";
|
|
1
|
+
import { PromptInput, ParserOutput, CoreExecutorExecuteOptions, ExecutorWithLlmOptions, ExecutorExecutionMetadata, LlmExecutorHooks, LlmExecutorExecuteOptions } from "../types";
|
|
2
2
|
import { BaseLlm } from "../llm";
|
|
3
3
|
import { BaseParser, StringParser } from "../parser";
|
|
4
4
|
import { BasePrompt } from "../prompt";
|
|
@@ -13,11 +13,13 @@ export declare class LlmExecutor<Llm extends BaseLlm<any>, Prompt extends BasePr
|
|
|
13
13
|
promptFn: any;
|
|
14
14
|
parser: StringParser | Parser;
|
|
15
15
|
constructor(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<LlmExecutorHooks>);
|
|
16
|
-
|
|
16
|
+
execute(_input: PromptInput<Prompt>, _options?: LlmExecutorExecuteOptions): Promise<ParserOutput<Parser>>;
|
|
17
|
+
handler(_input: PromptInput<Prompt>, ..._args: any[]): Promise<any>;
|
|
17
18
|
getHandlerInput(_input: PromptInput<Prompt>): any;
|
|
18
19
|
getHandlerOutput(out: any, _metadata: ExecutorExecutionMetadata<PromptInput<Prompt>, ParserOutput<Parser>>): ParserOutput<Parser>;
|
|
19
20
|
metadata(): {
|
|
20
21
|
llm: {
|
|
22
|
+
traceId: string | null;
|
|
21
23
|
promptType: import("../types").PromptType;
|
|
22
24
|
timeout: number;
|
|
23
25
|
jitter: "none" | "full";
|
|
@@ -26,4 +28,5 @@ export declare class LlmExecutor<Llm extends BaseLlm<any>, Prompt extends BasePr
|
|
|
26
28
|
metrics: any;
|
|
27
29
|
};
|
|
28
30
|
};
|
|
31
|
+
getTraceId(): string | null;
|
|
29
32
|
}
|
package/dist/executor/llm.js
CHANGED
|
@@ -44,8 +44,11 @@ class LlmExecutor extends _base_1.BaseExecutor {
|
|
|
44
44
|
this.promptFn = null;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
async
|
|
48
|
-
|
|
47
|
+
async execute(_input, _options) {
|
|
48
|
+
return super.execute(_input, _options);
|
|
49
|
+
}
|
|
50
|
+
async handler(_input, ..._args) {
|
|
51
|
+
const call = await this.llm.call(_input, ..._args);
|
|
49
52
|
const result = call.getResultContent();
|
|
50
53
|
return result;
|
|
51
54
|
}
|
|
@@ -68,6 +71,12 @@ class LlmExecutor extends _base_1.BaseExecutor {
|
|
|
68
71
|
llm: this.llm.getMetadata(),
|
|
69
72
|
};
|
|
70
73
|
}
|
|
74
|
+
getTraceId() {
|
|
75
|
+
if (this.traceId) {
|
|
76
|
+
return this.traceId;
|
|
77
|
+
}
|
|
78
|
+
return this.llm.getTraceId();
|
|
79
|
+
}
|
|
71
80
|
}
|
|
72
81
|
exports.LlmExecutor = LlmExecutor;
|
|
73
82
|
//# sourceMappingURL=llm.js.map
|
package/dist/executor/llm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm.js","sourceRoot":"src/","sources":["executor/llm.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"llm.js","sourceRoot":"src/","sources":["executor/llm.ts"],"names":[],"mappings":";;;AAUA,qCAAoD;AAGpD,mCAAuC;AAEvC;;GAEG;AACH,MAAa,WAKX,SAAQ,oBAIT;IAMC,YACE,gBAAoE,EACpE,OAAsD;QAEtD,KAAK,CACH,gBAAgB,CAAC,IAAI,IAAI,wBAAwB,EACjD,cAAc,EACd,OAAO,CACR,CAAC;QAbJ;;;;;WAAW;QACX;;;;;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AAC;IAED,gBAAgB,CACd,GAAQ,EACR,SAGC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAC3C,CAAC;IAED,QAAQ;QACN,OAAO;YACL,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE;SAC5B,CAAC;IACJ,CAAC;IACD,UAAU;QACR,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,OAAO,IAAI,CAAC,OAAO,CAAC;SACrB;QACD,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC;IAC/B,CAAC;CACF;AApFD,kCAoFC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { PineconeVectorStore } from "./vector";
|
|
|
8
8
|
import { BasePrompt, ChatPrompt, TextPrompt, createPrompt, createChatPrompt } from "./prompt";
|
|
9
9
|
import { BaseParser, CustomParser, createParser, createCustomParser } from "./parser";
|
|
10
10
|
import { DefaultState, BaseStateItem, DefaultStateItem, createState, createStateItem } from "./state";
|
|
11
|
+
import { LlmExecutorOpenAiFunctions } from "./executor/llm-openai-function";
|
|
11
12
|
export declare const llmExe: {
|
|
12
13
|
/**
|
|
13
14
|
* Utilities
|
|
@@ -40,6 +41,7 @@ export declare const llmExe: {
|
|
|
40
41
|
BaseExecutor: typeof BaseExecutor;
|
|
41
42
|
createCoreExecutor: typeof createCoreExecutor;
|
|
42
43
|
createLlmExecutor: typeof createLlmExecutor;
|
|
44
|
+
LlmExecutorOpenAiFunctions: typeof LlmExecutorOpenAiFunctions;
|
|
43
45
|
/**
|
|
44
46
|
* Callable
|
|
45
47
|
*/
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.llmExe = void 0;
|
|
27
|
+
// import { LlmExecutorExecuteOptions } from './interfaces/openai';
|
|
27
28
|
const callable_1 = require("./plugins/callable");
|
|
28
29
|
const _functions_1 = require("./executor/_functions");
|
|
29
30
|
const _base_1 = require("./executor/_base");
|
|
@@ -34,6 +35,7 @@ const vector_1 = require("./vector");
|
|
|
34
35
|
const prompt_1 = require("./prompt");
|
|
35
36
|
const parser_1 = require("./parser");
|
|
36
37
|
const state_1 = require("./state");
|
|
38
|
+
const llm_openai_function_1 = require("./executor/llm-openai-function");
|
|
37
39
|
exports.llmExe = {
|
|
38
40
|
/**
|
|
39
41
|
* Utilities
|
|
@@ -66,6 +68,7 @@ exports.llmExe = {
|
|
|
66
68
|
BaseExecutor: _base_1.BaseExecutor,
|
|
67
69
|
createCoreExecutor: _functions_1.createCoreExecutor,
|
|
68
70
|
createLlmExecutor: _functions_1.createLlmExecutor,
|
|
71
|
+
LlmExecutorOpenAiFunctions: llm_openai_function_1.LlmExecutorOpenAiFunctions,
|
|
69
72
|
/**
|
|
70
73
|
* Callable
|
|
71
74
|
*/
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0E;AAC1E,sDAA8E;AAC9E,4CAAgD;AAChD,+CAAiC;AACjC,+BAAyD;AACzD,+CAAqD;AACrD,qCAA+C;AAE/C,qCAMkB;AAElB,qCAKkB;AAElB,mCAMiB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mEAAmE;AACnE,iDAA0E;AAC1E,sDAA8E;AAC9E,4CAAgD;AAChD,+CAAiC;AACjC,+BAAyD;AACzD,+CAAqD;AACrD,qCAA+C;AAE/C,qCAMkB;AAElB,qCAKkB;AAElB,mCAMiB;AAEjB,wEAA4E;AAE/D,QAAA,MAAM,GAAG;IACpB;;OAEG;IACH,KAAK;IACL;;OAEG;IACH,OAAO,EAAP,aAAO;IACP,MAAM,EAAN,YAAM;IACN,eAAe,EAAf,qBAAe;IACf;;OAEG;IACH,UAAU,EAAV,mBAAU;IACV,UAAU,EAAV,mBAAU;IACV,UAAU,EAAV,mBAAU;IACV,YAAY,EAAZ,qBAAY;IACZ,gBAAgB,EAAhB,yBAAgB;IAChB;;OAEG;IACH,UAAU,EAAV,mBAAU;IACV,YAAY,EAAZ,qBAAY;IACZ,YAAY,EAAZ,qBAAY;IACZ,kBAAkB,EAAlB,2BAAkB;IAClB;;OAEG;IACH,YAAY,EAAZ,oBAAY;IACZ,kBAAkB,EAAlB,+BAAkB;IAClB,iBAAiB,EAAjB,8BAAiB;IACjB,0BAA0B,EAA1B,gDAA0B;IAC1B;;OAEG;IACH,YAAY,EAAZ,uBAAY;IACZ,sBAAsB,EAAtB,iCAAsB;IACtB;;OAEG;IACH,eAAe,EAAf,wBAAe;IACf,mBAAmB,EAAnB,4BAAmB;IACnB;;OAEG;IACH,YAAY,EAAZ,oBAAY;IACZ,aAAa,EAAb,qBAAa;IACb,gBAAgB,EAAhB,wBAAgB;IAChB,WAAW,EAAX,mBAAW;IACX,eAAe,EAAf,uBAAe;CAChB,CAAC"}
|
|
@@ -1,16 +1,31 @@
|
|
|
1
|
-
export type IChatMessageRole = "system" | "assistant" | "user";
|
|
1
|
+
export type IChatMessageRole = "system" | "assistant" | "user" | "function" | "function_call";
|
|
2
|
+
export type FinishReasons = "function_call" | "stop";
|
|
2
3
|
export interface IChatMessageBase {
|
|
3
4
|
role: IChatMessageRole;
|
|
4
|
-
content: string;
|
|
5
|
+
content: string | null;
|
|
5
6
|
}
|
|
6
7
|
export interface IChatUserMessage extends IChatMessageBase {
|
|
7
8
|
role: Extract<IChatMessageRole, "user">;
|
|
8
9
|
content: string;
|
|
9
10
|
name?: string;
|
|
10
11
|
}
|
|
12
|
+
export interface IChatFunctionMessage extends IChatMessageBase {
|
|
13
|
+
role: Extract<IChatMessageRole, "function">;
|
|
14
|
+
content: string;
|
|
15
|
+
name: string;
|
|
16
|
+
}
|
|
11
17
|
export interface IChatAssistantMessage extends IChatMessageBase {
|
|
12
18
|
role: Extract<IChatMessageRole, "assistant">;
|
|
13
19
|
content: string;
|
|
20
|
+
function_call?: undefined;
|
|
21
|
+
}
|
|
22
|
+
export interface IChatAssistantFunctionCallMessage extends IChatMessageBase {
|
|
23
|
+
role: Extract<IChatMessageRole, "assistant">;
|
|
24
|
+
content: null;
|
|
25
|
+
function_call?: {
|
|
26
|
+
name: string;
|
|
27
|
+
arguments: string;
|
|
28
|
+
};
|
|
14
29
|
}
|
|
15
30
|
export interface IChatSystemMessage extends IChatMessageBase {
|
|
16
31
|
role: Extract<IChatMessageRole, "system">;
|
|
@@ -21,7 +36,39 @@ export interface IChatMessagesPlaceholder {
|
|
|
21
36
|
content: string;
|
|
22
37
|
}
|
|
23
38
|
export type IPromptMessages = (IChatSystemMessage | IChatMessagesPlaceholder)[];
|
|
24
|
-
export type IPromptChatMessages = (IChatUserMessage | IChatAssistantMessage | IChatSystemMessage | IChatMessagesPlaceholder)[];
|
|
25
|
-
export type IChatMessage =
|
|
26
|
-
export type IChatMessages =
|
|
39
|
+
export type IPromptChatMessages = (IChatUserMessage | IChatAssistantMessage | IChatAssistantFunctionCallMessage | IChatSystemMessage | IChatMessagesPlaceholder | IChatFunctionMessage)[];
|
|
40
|
+
export type IChatMessage = IChatUserMessage | IChatAssistantMessage | IChatAssistantFunctionCallMessage | IChatSystemMessage | IChatFunctionMessage;
|
|
41
|
+
export type IChatMessages = IChatMessage[];
|
|
27
42
|
export type PromptTemplateHistoryToken = `{{>DialogueHistory key='${string}'}}`;
|
|
43
|
+
interface OutputOpenAIChatChoiceBase {
|
|
44
|
+
message: {
|
|
45
|
+
role: Extract<IChatMessageRole, "assistant">;
|
|
46
|
+
content: string | null;
|
|
47
|
+
function_call: null | {
|
|
48
|
+
name: string;
|
|
49
|
+
arguments: string;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
finish_reason: FinishReasons;
|
|
53
|
+
}
|
|
54
|
+
export interface OutputOpenAIChatChoiceFunction extends OutputOpenAIChatChoiceBase {
|
|
55
|
+
message: {
|
|
56
|
+
role: Extract<IChatMessageRole, "assistant">;
|
|
57
|
+
content: null;
|
|
58
|
+
function_call: {
|
|
59
|
+
name: string;
|
|
60
|
+
arguments: string;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
finish_reason: Extract<FinishReasons, "function_call">;
|
|
64
|
+
}
|
|
65
|
+
export interface OutputOpenAIChatChoiceMessage extends OutputOpenAIChatChoiceBase {
|
|
66
|
+
message: {
|
|
67
|
+
role: Extract<IChatMessageRole, "assistant">;
|
|
68
|
+
content: string;
|
|
69
|
+
function_call: null;
|
|
70
|
+
};
|
|
71
|
+
finish_reason: Exclude<FinishReasons, "function_call">;
|
|
72
|
+
}
|
|
73
|
+
export type OutputOpenAIChatChoice = OutputOpenAIChatChoiceFunction | OutputOpenAIChatChoiceMessage;
|
|
74
|
+
export {};
|
|
@@ -60,3 +60,8 @@ export type CoreExecutorHookInput<H = BaseExecutorHooks> = {
|
|
|
60
60
|
export interface CoreExecutorExecuteOptions<T = BaseExecutorHooks> {
|
|
61
61
|
hooks?: CoreExecutorHookInput<T>;
|
|
62
62
|
}
|
|
63
|
+
export interface CallableExecutorCore {
|
|
64
|
+
name: string;
|
|
65
|
+
description: string;
|
|
66
|
+
parameters?: Record<string, any>;
|
|
67
|
+
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { CallableExecutorCore } from "./index";
|
|
1
2
|
import { PromptType } from "./prompt";
|
|
2
3
|
export interface BaseLlmOptions {
|
|
4
|
+
traceId?: null | string;
|
|
3
5
|
timeout?: number;
|
|
4
6
|
maxDelay?: number;
|
|
5
7
|
numOfAttempts?: number;
|
|
6
8
|
jitter?: "none" | "full";
|
|
7
9
|
promptType?: PromptType;
|
|
8
10
|
}
|
|
9
|
-
export type OpenAIChatModelName = "gpt-3.5-turbo" | "gpt-4";
|
|
11
|
+
export type OpenAIChatModelName = "gpt-3.5-turbo" | "gpt-3.5-turbo-0613" | "gpt-3.5-turbo-16k" | "gpt-4-0613" | "gpt-4" | "gpt-4-0613" | "gpt-4-32k-0613";
|
|
10
12
|
export type OpenAIConversationModelName = "davinci" | "text-curie-001" | "text-babbage-001" | "text-ada-001";
|
|
11
13
|
export type OpenAIEmbeddingModelName = "text-embedding-ada-002";
|
|
12
14
|
export type OpenAIModelName = OpenAIChatModelName | OpenAIConversationModelName | OpenAIEmbeddingModelName;
|
|
@@ -24,6 +26,8 @@ export interface OpenAIOptions extends BaseLlmOptions {
|
|
|
24
26
|
frequencyPenalty?: number | null;
|
|
25
27
|
logitBias?: object | null;
|
|
26
28
|
user?: string;
|
|
29
|
+
function_call?: OpenAiFunctionCall;
|
|
30
|
+
functions?: CallableExecutorCore[];
|
|
27
31
|
}
|
|
28
32
|
export interface EmbedOpenAIOptions extends OpenAIOptions {
|
|
29
33
|
openAIApiKey: string;
|
|
@@ -31,3 +35,12 @@ export interface EmbedOpenAIOptions extends OpenAIOptions {
|
|
|
31
35
|
batchSize?: number;
|
|
32
36
|
stripNewLines?: boolean;
|
|
33
37
|
}
|
|
38
|
+
export type OpenAiFunctionCall = "auto" | "none" | {
|
|
39
|
+
name: string;
|
|
40
|
+
};
|
|
41
|
+
export interface LlmExecutorExecuteOptions {
|
|
42
|
+
}
|
|
43
|
+
export interface OpenAiLlmExecutorOptions<T extends OpenAiFunctionCall = OpenAiFunctionCall> extends LlmExecutorExecuteOptions {
|
|
44
|
+
functions: CallableExecutorCore[];
|
|
45
|
+
function_call: T;
|
|
46
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { JSONSchema7 } from "json-schema-to-ts";
|
|
2
2
|
export type CreateParserType = "json" | "string" | "boolean" | "number" | "stringExtract" | "listToArray" | "listToJson" | "listToKeyValue" | "replaceStringTemplate" | "markdownCodeBlocks" | "markdownCodeBlock";
|
|
3
3
|
export interface BaseParserOptions {
|
|
4
|
-
schema?: JSONSchema7;
|
|
5
|
-
validateSchema?: boolean;
|
|
6
4
|
}
|
|
7
5
|
export interface BaseParserOptionsWithSchema<S extends JSONSchema7 | undefined = undefined> extends BaseParserOptions {
|
|
8
6
|
schema?: S;
|
|
7
|
+
validateSchema?: boolean;
|
|
9
8
|
}
|
package/dist/llm/_base.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export declare abstract class BaseLlm<C = any> {
|
|
|
30
30
|
* The jitter strategy to use between retries. Options are "none" or "full".
|
|
31
31
|
*/
|
|
32
32
|
protected jitter: "none" | "full";
|
|
33
|
+
protected traceId: null | string;
|
|
33
34
|
/**
|
|
34
35
|
* An object to store metrics related to the LLM calls.
|
|
35
36
|
*/
|
|
@@ -48,6 +49,7 @@ export declare abstract class BaseLlm<C = any> {
|
|
|
48
49
|
* getMetadata - Used to return metrics and data about executions.
|
|
49
50
|
*/
|
|
50
51
|
getMetadata(): {
|
|
52
|
+
traceId: string | null;
|
|
51
53
|
promptType: PromptType;
|
|
52
54
|
timeout: number;
|
|
53
55
|
jitter: "none" | "full";
|
|
@@ -61,18 +63,20 @@ export declare abstract class BaseLlm<C = any> {
|
|
|
61
63
|
* @param _input - The input to the LLM.
|
|
62
64
|
* @return The output from the LLM.
|
|
63
65
|
*/
|
|
64
|
-
call(_input: any,
|
|
66
|
+
call(_input: any, ...args: any[]): Promise<BaseLlmOutput>;
|
|
65
67
|
/**
|
|
66
68
|
* _callWithRetry is a private method that handles retries and timeouts for the LLM call.
|
|
67
69
|
* @param _input - The input to the LLM.
|
|
68
70
|
* @return The result of the LLM call.
|
|
69
71
|
* @throws An error if the maximum number of retries is reached.
|
|
70
72
|
*/
|
|
71
|
-
_callWithRetry(_input: any,
|
|
73
|
+
_callWithRetry(_input: any, ...args: any[]): Promise<any>;
|
|
72
74
|
/**
|
|
73
75
|
* _call is an abstract method that must be implemented by subclasses to make the actual LLM call.
|
|
74
76
|
* @param {any} _input - The input to the LLM.
|
|
75
77
|
* @return The output from the LLM.
|
|
76
78
|
*/
|
|
77
|
-
_call(_input: any,
|
|
79
|
+
_call(_input: any, ..._args: any[]): Promise<BaseLlmOutput>;
|
|
80
|
+
withTraceId(traceId: string): this;
|
|
81
|
+
getTraceId(): string | null;
|
|
78
82
|
}
|
package/dist/llm/_base.js
CHANGED
|
@@ -69,6 +69,12 @@ class BaseLlm {
|
|
|
69
69
|
writable: true,
|
|
70
70
|
value: void 0
|
|
71
71
|
});
|
|
72
|
+
Object.defineProperty(this, "traceId", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: void 0
|
|
77
|
+
});
|
|
72
78
|
/**
|
|
73
79
|
* An object to store metrics related to the LLM calls.
|
|
74
80
|
*/
|
|
@@ -84,6 +90,7 @@ class BaseLlm {
|
|
|
84
90
|
history: [],
|
|
85
91
|
}
|
|
86
92
|
});
|
|
93
|
+
this.traceId = options?.traceId || null;
|
|
87
94
|
this.client = null;
|
|
88
95
|
this.promptType = options?.promptType || "text";
|
|
89
96
|
this.timeout = options.timeout || 30000;
|
|
@@ -105,6 +112,7 @@ class BaseLlm {
|
|
|
105
112
|
*/
|
|
106
113
|
getMetadata() {
|
|
107
114
|
return {
|
|
115
|
+
traceId: this.getTraceId(),
|
|
108
116
|
promptType: this.promptType,
|
|
109
117
|
timeout: this.timeout,
|
|
110
118
|
jitter: this.jitter,
|
|
@@ -119,8 +127,8 @@ class BaseLlm {
|
|
|
119
127
|
* @param _input - The input to the LLM.
|
|
120
128
|
* @return The output from the LLM.
|
|
121
129
|
*/
|
|
122
|
-
async call(_input,
|
|
123
|
-
const called = await this._callWithRetry(_input,
|
|
130
|
+
async call(_input, ...args) {
|
|
131
|
+
const called = await this._callWithRetry(_input, ...args);
|
|
124
132
|
return called;
|
|
125
133
|
}
|
|
126
134
|
/**
|
|
@@ -129,10 +137,10 @@ class BaseLlm {
|
|
|
129
137
|
* @return The result of the LLM call.
|
|
130
138
|
* @throws An error if the maximum number of retries is reached.
|
|
131
139
|
*/
|
|
132
|
-
async _callWithRetry(_input,
|
|
140
|
+
async _callWithRetry(_input, ...args) {
|
|
133
141
|
try {
|
|
134
142
|
this.metrics.total_calls++;
|
|
135
|
-
const result = await (0, exponential_backoff_1.backOff)(() => (0, utils_1.asyncCallWithTimeout)(this._call(_input,
|
|
143
|
+
const result = await (0, exponential_backoff_1.backOff)(() => (0, utils_1.asyncCallWithTimeout)(this._call(_input, ...args), this.timeout), {
|
|
136
144
|
startingDelay: 0,
|
|
137
145
|
maxDelay: this.maxDelay,
|
|
138
146
|
numOfAttempts: this.numOfAttempts,
|
|
@@ -156,9 +164,16 @@ class BaseLlm {
|
|
|
156
164
|
* @param {any} _input - The input to the LLM.
|
|
157
165
|
* @return The output from the LLM.
|
|
158
166
|
*/
|
|
159
|
-
async _call(_input,
|
|
167
|
+
async _call(_input, ..._args) {
|
|
160
168
|
return new output_1.OutputDefault(undefined);
|
|
161
169
|
}
|
|
170
|
+
withTraceId(traceId) {
|
|
171
|
+
this.traceId = traceId;
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
getTraceId() {
|
|
175
|
+
return this.traceId;
|
|
176
|
+
}
|
|
162
177
|
}
|
|
163
178
|
exports.BaseLlm = BaseLlm;
|
|
164
179
|
//# sourceMappingURL=_base.js.map
|
package/dist/llm/_base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_base.js","sourceRoot":"src/","sources":["llm/_base.ts"],"names":[],"mappings":";;;AAAA,6DAA8C;AAE9C,mCAA+C;AAC/C,yCAA4D;AAE5D;;;;GAIG;AACH,MAAsB,OAAO;
|
|
1
|
+
{"version":3,"file":"_base.js","sourceRoot":"src/","sources":["llm/_base.ts"],"names":[],"mappings":";;;AAAA,6DAA8C;AAE9C,mCAA+C;AAC/C,yCAA4D;AAE5D;;;;GAIG;AACH,MAAsB,OAAO;IA2C3B;;;OAGG;IACH,YAAY,OAAu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