@agentica/core 0.10.4 → 0.11.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/lib/Agentica.d.ts +14 -14
- package/lib/Agentica.js +54 -31
- package/lib/Agentica.js.map +1 -1
- package/lib/chatgpt/ChatGptAgent.d.ts +3 -3
- package/lib/chatgpt/ChatGptAgent.js +1 -1
- package/lib/chatgpt/ChatGptAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptCallFunctionAgent.d.ts +3 -3
- package/lib/chatgpt/ChatGptCallFunctionAgent.js +61 -63
- package/lib/chatgpt/ChatGptCallFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptCancelFunctionAgent.d.ts +6 -6
- package/lib/chatgpt/ChatGptCancelFunctionAgent.js +28 -30
- package/lib/chatgpt/ChatGptCancelFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptCompletionMessageUtil.d.ts +8 -0
- package/lib/chatgpt/ChatGptCompletionMessageUtil.js +536 -0
- package/lib/chatgpt/ChatGptCompletionMessageUtil.js.map +1 -0
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.d.ts +4 -3
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.js +56 -6
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptHistoryDecoder.d.ts +2 -2
- package/lib/chatgpt/ChatGptHistoryDecoder.js +8 -8
- package/lib/chatgpt/ChatGptHistoryDecoder.js.map +1 -1
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.d.ts +3 -3
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.js +11 -5
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptSelectFunctionAgent.d.ts +3 -3
- package/lib/chatgpt/ChatGptSelectFunctionAgent.js +39 -42
- package/lib/chatgpt/ChatGptSelectFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptUsageAggregator.d.ts +6 -0
- package/lib/chatgpt/ChatGptUsageAggregator.js +48 -0
- package/lib/chatgpt/ChatGptUsageAggregator.js.map +1 -0
- package/lib/context/AgenticaCancelPrompt.d.ts +16 -0
- package/lib/context/AgenticaCancelPrompt.js +20 -0
- package/lib/context/AgenticaCancelPrompt.js.map +1 -0
- package/lib/context/AgenticaClassOperation.d.ts +8 -0
- package/lib/context/AgenticaClassOperation.js +11 -0
- package/lib/context/AgenticaClassOperation.js.map +1 -0
- package/lib/{structures/IAgenticaContext.d.ts → context/AgenticaContext.d.ts} +15 -14
- package/lib/{structures/IAgenticaPrompt.js → context/AgenticaContext.js} +1 -1
- package/lib/context/AgenticaContext.js.map +1 -0
- package/lib/context/AgenticaHttpOperation.d.ts +8 -0
- package/lib/context/AgenticaHttpOperation.js +11 -0
- package/lib/context/AgenticaHttpOperation.js.map +1 -0
- package/lib/context/AgenticaOperation.d.ts +46 -0
- package/lib/{structures/IAgenticaContext.js → context/AgenticaOperation.js} +1 -1
- package/lib/context/AgenticaOperation.js.map +1 -0
- package/lib/context/AgenticaOperationBase.d.ts +29 -0
- package/lib/context/AgenticaOperationBase.js +21 -0
- package/lib/context/AgenticaOperationBase.js.map +1 -0
- package/lib/{structures/IAgenticaOperationCollection.d.ts → context/AgenticaOperationCollection.d.ts} +6 -6
- package/lib/{structures/IAgenticaOperationSelection.js → context/AgenticaOperationCollection.js} +1 -1
- package/lib/context/AgenticaOperationCollection.js.map +1 -0
- package/lib/context/AgenticaOperationSelection.d.ts +15 -0
- package/lib/context/AgenticaOperationSelection.js +17 -0
- package/lib/context/AgenticaOperationSelection.js.map +1 -0
- package/lib/context/AgenticaTokenUsage.d.ts +82 -0
- package/lib/context/AgenticaTokenUsage.js +97 -0
- package/lib/context/AgenticaTokenUsage.js.map +1 -0
- package/lib/context/internal/AgenticaTokenUsageAggregator.d.ts +10 -0
- package/lib/{internal → context/internal}/AgenticaTokenUsageAggregator.js +0 -46
- package/lib/context/internal/AgenticaTokenUsageAggregator.js.map +1 -0
- package/lib/context/internal/__IChatCancelFunctionsApplication.js.map +1 -0
- package/lib/context/internal/__IChatFunctionReference.js.map +1 -0
- package/lib/context/internal/__IChatInitialApplication.js.map +1 -0
- package/lib/context/internal/__IChatSelectFunctionsApplication.js.map +1 -0
- package/lib/events/AgenticaCallEvent.d.ts +18 -0
- package/lib/events/AgenticaCallEvent.js +22 -0
- package/lib/events/AgenticaCallEvent.js.map +1 -0
- package/lib/events/AgenticaCancelEvent.d.ts +14 -0
- package/lib/events/AgenticaCancelEvent.js +18 -0
- package/lib/events/AgenticaCancelEvent.js.map +1 -0
- package/lib/events/AgenticaDescribeEvent.d.ts +27 -0
- package/lib/events/AgenticaDescribeEvent.js +40 -0
- package/lib/events/AgenticaDescribeEvent.js.map +1 -0
- package/lib/events/AgenticaEvent.d.ts +25 -0
- package/lib/{structures/IAgenticaEvent.js → events/AgenticaEvent.js} +1 -1
- package/lib/events/AgenticaEvent.js.map +1 -0
- package/lib/events/AgenticaEventBase.d.ts +4 -0
- package/lib/events/AgenticaEventBase.js +10 -0
- package/lib/events/AgenticaEventBase.js.map +1 -0
- package/lib/events/AgenticaEventSource.d.ts +1 -0
- package/lib/events/AgenticaEventSource.js +3 -0
- package/lib/events/AgenticaEventSource.js.map +1 -0
- package/lib/events/AgenticaExecuteEvent.d.ts +22 -0
- package/lib/events/AgenticaExecuteEvent.js +33 -0
- package/lib/events/AgenticaExecuteEvent.js.map +1 -0
- package/lib/events/AgenticaInitializeEvent.d.ts +6 -0
- package/lib/events/AgenticaInitializeEvent.js +16 -0
- package/lib/events/AgenticaInitializeEvent.js.map +1 -0
- package/lib/events/AgenticaRequestEvent.d.ts +27 -0
- package/lib/events/AgenticaRequestEvent.js +22 -0
- package/lib/events/AgenticaRequestEvent.js.map +1 -0
- package/lib/events/AgenticaResponseEvent.d.ts +35 -0
- package/lib/events/AgenticaResponseEvent.js +16 -0
- package/lib/events/AgenticaResponseEvent.js.map +1 -0
- package/lib/events/AgenticaSelectEvent.d.ts +16 -0
- package/lib/events/AgenticaSelectEvent.js +26 -0
- package/lib/events/AgenticaSelectEvent.js.map +1 -0
- package/lib/events/AgenticaTextEvent.d.ts +25 -0
- package/lib/events/AgenticaTextEvent.js +40 -0
- package/lib/events/AgenticaTextEvent.js.map +1 -0
- package/lib/index.d.ts +26 -8
- package/lib/index.js +29 -9
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +1391 -306
- package/lib/index.mjs.map +1 -1
- package/lib/internal/AgenticaOperationComposer.d.ts +2 -2
- package/lib/internal/AgenticaOperationComposer.js +12 -0
- package/lib/internal/AgenticaOperationComposer.js.map +1 -1
- package/lib/internal/ByteArrayUtil.d.ts +3 -0
- package/lib/internal/ByteArrayUtil.js +10 -0
- package/lib/internal/ByteArrayUtil.js.map +1 -0
- package/lib/internal/MPSCUtil.d.ts +21 -0
- package/lib/internal/MPSCUtil.js +84 -0
- package/lib/internal/MPSCUtil.js.map +1 -0
- package/lib/internal/StreamUtil.d.ts +6 -0
- package/lib/internal/StreamUtil.js +65 -0
- package/lib/internal/StreamUtil.js.map +1 -0
- package/lib/json/IAgenticaEventJson.d.ts +149 -0
- package/lib/{structures/IAgenticaOperation.js → json/IAgenticaEventJson.js} +1 -1
- package/lib/json/IAgenticaEventJson.js.map +1 -0
- package/lib/json/IAgenticaOperationJson.d.ts +33 -0
- package/lib/json/IAgenticaOperationJson.js +3 -0
- package/lib/json/IAgenticaOperationJson.js.map +1 -0
- package/lib/json/IAgenticaOperationSelectionJson.d.ts +18 -0
- package/lib/{structures/IAgenticaOperationCollection.js → json/IAgenticaOperationSelectionJson.js} +1 -1
- package/lib/json/IAgenticaOperationSelectionJson.js.map +1 -0
- package/lib/json/IAgenticaPromptJson.d.ts +111 -0
- package/lib/json/IAgenticaPromptJson.js +3 -0
- package/lib/json/IAgenticaPromptJson.js.map +1 -0
- package/lib/{structures/IAgenticaTokenUsage.d.ts → json/IAgenticaTokenUsageJson.d.ts} +10 -10
- package/lib/json/IAgenticaTokenUsageJson.js +3 -0
- package/lib/json/IAgenticaTokenUsageJson.js.map +1 -0
- package/lib/prompts/AgenticaCancelPrompt.d.ts +16 -0
- package/lib/prompts/AgenticaCancelPrompt.js +20 -0
- package/lib/prompts/AgenticaCancelPrompt.js.map +1 -0
- package/lib/prompts/AgenticaDescribePrompt.d.ts +24 -0
- package/lib/prompts/AgenticaDescribePrompt.js +20 -0
- package/lib/prompts/AgenticaDescribePrompt.js.map +1 -0
- package/lib/prompts/AgenticaExecutePrompt.d.ts +20 -0
- package/lib/prompts/AgenticaExecutePrompt.js +24 -0
- package/lib/prompts/AgenticaExecutePrompt.js.map +1 -0
- package/lib/prompts/AgenticaPrompt.d.ts +7 -0
- package/lib/{typings/AgenticaSource.js → prompts/AgenticaPrompt.js} +1 -1
- package/lib/prompts/AgenticaPrompt.js.map +1 -0
- package/lib/prompts/AgenticaPromptBase.d.ts +22 -0
- package/lib/prompts/AgenticaPromptBase.js +22 -0
- package/lib/prompts/AgenticaPromptBase.js.map +1 -0
- package/lib/prompts/AgenticaSelectPrompt.d.ts +16 -0
- package/lib/prompts/AgenticaSelectPrompt.js +20 -0
- package/lib/prompts/AgenticaSelectPrompt.js.map +1 -0
- package/lib/prompts/AgenticaTextPrompt.d.ts +14 -0
- package/lib/prompts/AgenticaTextPrompt.js +20 -0
- package/lib/prompts/AgenticaTextPrompt.js.map +1 -0
- package/lib/structures/IAgenticaConfig.d.ts +3 -3
- package/lib/structures/IAgenticaExecutor.d.ts +12 -11
- package/lib/structures/IAgenticaProps.d.ts +2 -3
- package/lib/structures/IAgenticaSystemPrompt.d.ts +12 -11
- package/lib/transformers/AgenticaEventTransformer.d.ts +45 -0
- package/lib/transformers/AgenticaEventTransformer.js +127 -0
- package/lib/transformers/AgenticaEventTransformer.js.map +1 -0
- package/lib/transformers/AgenticaPromptTransformer.d.ts +34 -0
- package/lib/transformers/AgenticaPromptTransformer.js +90 -0
- package/lib/transformers/AgenticaPromptTransformer.js.map +1 -0
- package/package.json +1 -1
- package/src/Agentica.ts +93 -63
- package/src/chatgpt/ChatGptAgent.ts +8 -7
- package/src/chatgpt/ChatGptCallFunctionAgent.ts +90 -88
- package/src/chatgpt/ChatGptCancelFunctionAgent.ts +51 -58
- package/src/chatgpt/ChatGptCompletionMessageUtil.ts +166 -0
- package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +81 -12
- package/src/chatgpt/ChatGptHistoryDecoder.ts +14 -14
- package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +21 -13
- package/src/chatgpt/ChatGptSelectFunctionAgent.ts +66 -74
- package/src/chatgpt/ChatGptUsageAggregator.ts +62 -0
- package/src/context/AgenticaCancelPrompt.ts +32 -0
- package/src/context/AgenticaClassOperation.ts +23 -0
- package/src/{structures/IAgenticaContext.ts → context/AgenticaContext.ts} +17 -16
- package/src/context/AgenticaHttpOperation.ts +27 -0
- package/src/{structures/IAgenticaOperation.ts → context/AgenticaOperation.ts} +25 -22
- package/src/context/AgenticaOperationBase.ts +57 -0
- package/src/{structures/IAgenticaOperationCollection.ts → context/AgenticaOperationCollection.ts} +6 -6
- package/src/context/AgenticaOperationSelection.ts +27 -0
- package/src/context/AgenticaTokenUsage.ts +170 -0
- package/src/context/internal/AgenticaTokenUsageAggregator.ts +66 -0
- package/src/events/AgenticaCallEvent.ts +36 -0
- package/src/events/AgenticaCancelEvent.ts +28 -0
- package/src/events/AgenticaDescribeEvent.ts +61 -0
- package/src/events/AgenticaEvent.ts +36 -0
- package/src/events/AgenticaEventBase.ts +7 -0
- package/src/{typings/AgenticaSource.ts → events/AgenticaEventSource.ts} +1 -1
- package/src/events/AgenticaExecuteEvent.ts +50 -0
- package/src/events/AgenticaInitializeEvent.ts +14 -0
- package/src/events/AgenticaRequestEvent.ts +45 -0
- package/src/events/AgenticaResponseEvent.ts +48 -0
- package/src/events/AgenticaSelectEvent.ts +37 -0
- package/src/events/AgenticaTextEvent.ts +57 -0
- package/src/index.ts +33 -9
- package/src/internal/AgenticaOperationComposer.ts +24 -15
- package/src/internal/ByteArrayUtil.ts +5 -0
- package/src/internal/MPSCUtil.ts +75 -0
- package/src/internal/StreamUtil.ts +64 -0
- package/src/json/IAgenticaEventJson.ts +178 -0
- package/src/json/IAgenticaOperationJson.ts +36 -0
- package/src/json/IAgenticaOperationSelectionJson.ts +19 -0
- package/src/json/IAgenticaPromptJson.ts +130 -0
- package/src/{structures/IAgenticaTokenUsage.ts → json/IAgenticaTokenUsageJson.ts} +10 -10
- package/src/prompts/AgenticaCancelPrompt.ts +32 -0
- package/src/prompts/AgenticaDescribePrompt.ts +41 -0
- package/src/prompts/AgenticaExecutePrompt.ts +52 -0
- package/src/prompts/AgenticaPrompt.ts +14 -0
- package/src/prompts/AgenticaPromptBase.ts +27 -0
- package/src/prompts/AgenticaSelectPrompt.ts +32 -0
- package/src/prompts/AgenticaTextPrompt.ts +31 -0
- package/src/structures/IAgenticaConfig.ts +3 -3
- package/src/structures/IAgenticaExecutor.ts +14 -13
- package/src/structures/IAgenticaProps.ts +2 -3
- package/src/structures/IAgenticaSystemPrompt.ts +12 -11
- package/src/transformers/AgenticaEventTransformer.ts +165 -0
- package/src/transformers/AgenticaPromptTransformer.ts +134 -0
- package/lib/internal/AgenticaPromptFactory.d.ts +0 -7
- package/lib/internal/AgenticaPromptFactory.js +0 -9
- package/lib/internal/AgenticaPromptFactory.js.map +0 -1
- package/lib/internal/AgenticaPromptTransformer.d.ts +0 -10
- package/lib/internal/AgenticaPromptTransformer.js +0 -58
- package/lib/internal/AgenticaPromptTransformer.js.map +0 -1
- package/lib/internal/AgenticaTokenUsageAggregator.d.ts +0 -11
- package/lib/internal/AgenticaTokenUsageAggregator.js.map +0 -1
- package/lib/structures/IAgenticaContext.js.map +0 -1
- package/lib/structures/IAgenticaEvent.d.ts +0 -192
- package/lib/structures/IAgenticaEvent.js.map +0 -1
- package/lib/structures/IAgenticaOperation.d.ts +0 -47
- package/lib/structures/IAgenticaOperation.js.map +0 -1
- package/lib/structures/IAgenticaOperationCollection.js.map +0 -1
- package/lib/structures/IAgenticaOperationSelection.d.ts +0 -50
- package/lib/structures/IAgenticaOperationSelection.js.map +0 -1
- package/lib/structures/IAgenticaPrompt.d.ts +0 -138
- package/lib/structures/IAgenticaPrompt.js.map +0 -1
- package/lib/structures/IAgenticaTokenUsage.js +0 -3
- package/lib/structures/IAgenticaTokenUsage.js.map +0 -1
- package/lib/structures/internal/__IChatCancelFunctionsApplication.js.map +0 -1
- package/lib/structures/internal/__IChatFunctionReference.js.map +0 -1
- package/lib/structures/internal/__IChatInitialApplication.js.map +0 -1
- package/lib/structures/internal/__IChatSelectFunctionsApplication.js.map +0 -1
- package/lib/typings/AgenticaSource.d.ts +0 -1
- package/lib/typings/AgenticaSource.js.map +0 -1
- package/src/internal/AgenticaPromptFactory.ts +0 -32
- package/src/internal/AgenticaPromptTransformer.ts +0 -86
- package/src/internal/AgenticaTokenUsageAggregator.ts +0 -121
- package/src/structures/IAgenticaEvent.ts +0 -229
- package/src/structures/IAgenticaOperationSelection.ts +0 -68
- package/src/structures/IAgenticaPrompt.ts +0 -182
- /package/lib/{structures → context}/internal/__IChatCancelFunctionsApplication.d.ts +0 -0
- /package/lib/{structures → context}/internal/__IChatCancelFunctionsApplication.js +0 -0
- /package/lib/{structures → context}/internal/__IChatFunctionReference.d.ts +0 -0
- /package/lib/{structures → context}/internal/__IChatFunctionReference.js +0 -0
- /package/lib/{structures → context}/internal/__IChatInitialApplication.d.ts +0 -0
- /package/lib/{structures → context}/internal/__IChatInitialApplication.js +0 -0
- /package/lib/{structures → context}/internal/__IChatSelectFunctionsApplication.d.ts +0 -0
- /package/lib/{structures → context}/internal/__IChatSelectFunctionsApplication.js +0 -0
- /package/src/{structures → context}/internal/__IChatCancelFunctionsApplication.ts +0 -0
- /package/src/{structures → context}/internal/__IChatFunctionReference.ts +0 -0
- /package/src/{structures → context}/internal/__IChatInitialApplication.ts +0 -0
- /package/src/{structures → context}/internal/__IChatSelectFunctionsApplication.ts +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { IAgenticaOperationSelectionJson } from "../json/IAgenticaOperationSelectionJson";
|
|
4
|
+
import { AgenticaOperation } from "./AgenticaOperation";
|
|
5
|
+
|
|
6
|
+
export class AgenticaOperationSelection<Model extends ILlmSchema.Model> {
|
|
7
|
+
public readonly operation: AgenticaOperation<Model>;
|
|
8
|
+
public readonly reason: string;
|
|
9
|
+
|
|
10
|
+
public constructor(props: AgenticaOperationSelection.IProps<Model>) {
|
|
11
|
+
this.operation = props.operation;
|
|
12
|
+
this.reason = props.reason;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public toJSON(): IAgenticaOperationSelectionJson {
|
|
16
|
+
return {
|
|
17
|
+
operation: this.operation.toJSON(),
|
|
18
|
+
reason: this.reason,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export namespace AgenticaOperationSelection {
|
|
23
|
+
export interface IProps<Model extends ILlmSchema.Model> {
|
|
24
|
+
operation: AgenticaOperation<Model>;
|
|
25
|
+
reason: string;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import typia from "typia";
|
|
2
|
+
|
|
3
|
+
import { IAgenticaTokenUsageJson } from "../json/IAgenticaTokenUsageJson";
|
|
4
|
+
|
|
5
|
+
export class AgenticaTokenUsage implements IAgenticaTokenUsageJson {
|
|
6
|
+
/**
|
|
7
|
+
* Aggregated token usage.
|
|
8
|
+
*/
|
|
9
|
+
public readonly aggregate: IAgenticaTokenUsageJson.IComponent;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Token uasge of initializer agent.
|
|
13
|
+
*/
|
|
14
|
+
public readonly initialize: IAgenticaTokenUsageJson.IComponent;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Token usage of function selector agent.
|
|
18
|
+
*/
|
|
19
|
+
public readonly select: IAgenticaTokenUsageJson.IComponent;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Token usage of function canceler agent.
|
|
23
|
+
*/
|
|
24
|
+
public readonly cancel: IAgenticaTokenUsageJson.IComponent;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Token usage of function caller agent.
|
|
28
|
+
*/
|
|
29
|
+
public readonly call: IAgenticaTokenUsageJson.IComponent;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Token usage of function calling describer agent.
|
|
33
|
+
*/
|
|
34
|
+
public readonly describe: IAgenticaTokenUsageJson.IComponent;
|
|
35
|
+
|
|
36
|
+
public constructor(props?: IAgenticaTokenUsageJson) {
|
|
37
|
+
if (props === undefined) {
|
|
38
|
+
const zero = AgenticaTokenUsage.zero();
|
|
39
|
+
this.aggregate = zero.aggregate;
|
|
40
|
+
this.initialize = zero.initialize;
|
|
41
|
+
this.select = zero.select;
|
|
42
|
+
this.cancel = zero.cancel;
|
|
43
|
+
this.call = zero.call;
|
|
44
|
+
this.describe = zero.describe;
|
|
45
|
+
} else {
|
|
46
|
+
this.aggregate = props.aggregate;
|
|
47
|
+
this.initialize = props.initialize;
|
|
48
|
+
this.select = props.select;
|
|
49
|
+
this.cancel = props.cancel;
|
|
50
|
+
this.call = props.call;
|
|
51
|
+
this.describe = props.describe;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public increment(y: IAgenticaTokenUsageJson): void {
|
|
56
|
+
const increment = (
|
|
57
|
+
x: IAgenticaTokenUsageJson.IComponent,
|
|
58
|
+
y: IAgenticaTokenUsageJson.IComponent,
|
|
59
|
+
): void => {
|
|
60
|
+
x.total += y.total;
|
|
61
|
+
x.input.total += y.input.total;
|
|
62
|
+
x.input.cached += y.input.cached;
|
|
63
|
+
x.output.total += y.output.total;
|
|
64
|
+
x.output.reasoning += y.output.reasoning;
|
|
65
|
+
x.output.accepted_prediction += y.output.accepted_prediction;
|
|
66
|
+
x.output.rejected_prediction += y.output.rejected_prediction;
|
|
67
|
+
};
|
|
68
|
+
increment(this.aggregate, y.aggregate);
|
|
69
|
+
increment(this.initialize, y.initialize);
|
|
70
|
+
increment(this.select, y.select);
|
|
71
|
+
increment(this.cancel, y.cancel);
|
|
72
|
+
increment(this.call, y.call);
|
|
73
|
+
increment(this.describe, y.describe);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public toJSON(): IAgenticaTokenUsageJson {
|
|
77
|
+
return typia.misc.clone<IAgenticaTokenUsageJson>(this);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public static zero(): AgenticaTokenUsage {
|
|
81
|
+
const component = (): IAgenticaTokenUsageJson.IComponent => ({
|
|
82
|
+
total: 0,
|
|
83
|
+
input: {
|
|
84
|
+
total: 0,
|
|
85
|
+
cached: 0,
|
|
86
|
+
},
|
|
87
|
+
output: {
|
|
88
|
+
total: 0,
|
|
89
|
+
reasoning: 0,
|
|
90
|
+
accepted_prediction: 0,
|
|
91
|
+
rejected_prediction: 0,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
return new AgenticaTokenUsage({
|
|
95
|
+
aggregate: component(),
|
|
96
|
+
initialize: component(),
|
|
97
|
+
select: component(),
|
|
98
|
+
cancel: component(),
|
|
99
|
+
call: component(),
|
|
100
|
+
describe: component(),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public static plus(
|
|
105
|
+
x: AgenticaTokenUsage,
|
|
106
|
+
y: AgenticaTokenUsage,
|
|
107
|
+
): AgenticaTokenUsage {
|
|
108
|
+
const z: AgenticaTokenUsage = new AgenticaTokenUsage(x);
|
|
109
|
+
z.increment(y.toJSON());
|
|
110
|
+
return z;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export namespace AgenticaTokenUsage {
|
|
114
|
+
export interface IComponent {
|
|
115
|
+
/**
|
|
116
|
+
* Total token usage.
|
|
117
|
+
*/
|
|
118
|
+
total: number;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Input token usage of detailed.
|
|
122
|
+
*/
|
|
123
|
+
input: IInput;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Output token usage of detailed.
|
|
127
|
+
*/
|
|
128
|
+
output: IOutput;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Input token usage of detailed.
|
|
133
|
+
*/
|
|
134
|
+
export interface IInput {
|
|
135
|
+
/**
|
|
136
|
+
* Total amount of input token uasge.
|
|
137
|
+
*/
|
|
138
|
+
total: number;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Cached token usage.
|
|
142
|
+
*/
|
|
143
|
+
cached: number;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Output token usage of detailed.
|
|
148
|
+
*/
|
|
149
|
+
export interface IOutput {
|
|
150
|
+
/**
|
|
151
|
+
* Total amount of output token usage.
|
|
152
|
+
*/
|
|
153
|
+
total: number;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Reasoning token usage.
|
|
157
|
+
*/
|
|
158
|
+
reasoning: number;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Prediction token usage.
|
|
162
|
+
*/
|
|
163
|
+
accepted_prediction: number;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Rejected prediction token usage.
|
|
167
|
+
*/
|
|
168
|
+
rejected_prediction: number;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { CompletionUsage } from "openai/resources";
|
|
2
|
+
import { Primitive } from "typia";
|
|
3
|
+
|
|
4
|
+
import { AgenticaTokenUsage } from "../AgenticaTokenUsage";
|
|
5
|
+
|
|
6
|
+
export namespace AgenticaTokenUsageAggregator {
|
|
7
|
+
export const aggregate = (props: {
|
|
8
|
+
kind: Exclude<keyof Primitive<AgenticaTokenUsage>, "aggregate">;
|
|
9
|
+
completionUsage: CompletionUsage;
|
|
10
|
+
usage: AgenticaTokenUsage;
|
|
11
|
+
}): void => {
|
|
12
|
+
if (!props.completionUsage) return;
|
|
13
|
+
|
|
14
|
+
//----
|
|
15
|
+
// COMPONENT
|
|
16
|
+
//----
|
|
17
|
+
const component: AgenticaTokenUsage.IComponent = props.usage[props.kind];
|
|
18
|
+
|
|
19
|
+
// TOTAL
|
|
20
|
+
component.total += props.completionUsage.total_tokens;
|
|
21
|
+
|
|
22
|
+
// PROMPT
|
|
23
|
+
component.input.total += props.completionUsage.prompt_tokens;
|
|
24
|
+
component.input.total +=
|
|
25
|
+
props.completionUsage.prompt_tokens_details?.audio_tokens ?? 0;
|
|
26
|
+
component.input.cached +=
|
|
27
|
+
props.completionUsage.prompt_tokens_details?.cached_tokens ?? 0;
|
|
28
|
+
|
|
29
|
+
// COMPLETION
|
|
30
|
+
component.output.total += props.completionUsage.total_tokens;
|
|
31
|
+
component.output.accepted_prediction +=
|
|
32
|
+
props.completionUsage.completion_tokens_details
|
|
33
|
+
?.accepted_prediction_tokens ?? 0;
|
|
34
|
+
component.output.reasoning +=
|
|
35
|
+
props.completionUsage.completion_tokens_details?.reasoning_tokens ?? 0;
|
|
36
|
+
component.output.rejected_prediction +=
|
|
37
|
+
props.completionUsage.completion_tokens_details
|
|
38
|
+
?.rejected_prediction_tokens ?? 0;
|
|
39
|
+
|
|
40
|
+
//----
|
|
41
|
+
// RE-AGGREGATE
|
|
42
|
+
//----
|
|
43
|
+
const sum = (getter: (comp: AgenticaTokenUsage.IComponent) => number) =>
|
|
44
|
+
(
|
|
45
|
+
Object.entries(props.usage) as [
|
|
46
|
+
keyof AgenticaTokenUsage,
|
|
47
|
+
AgenticaTokenUsage.IComponent,
|
|
48
|
+
][]
|
|
49
|
+
)
|
|
50
|
+
.filter(([key]) => key !== "aggregate")
|
|
51
|
+
.map(([, comp]) => getter(comp))
|
|
52
|
+
.reduce((a, b) => a + b, 0);
|
|
53
|
+
const aggregate: AgenticaTokenUsage.IComponent = props.usage.aggregate;
|
|
54
|
+
aggregate.total = sum((comp) => comp.total);
|
|
55
|
+
aggregate.input.total = sum((comp) => comp.input.total);
|
|
56
|
+
aggregate.input.cached = sum((comp) => comp.input.cached);
|
|
57
|
+
aggregate.output.total = sum((comp) => comp.output.total);
|
|
58
|
+
aggregate.output.reasoning = sum((comp) => comp.output.reasoning);
|
|
59
|
+
aggregate.output.accepted_prediction = sum(
|
|
60
|
+
(comp) => comp.output.accepted_prediction,
|
|
61
|
+
);
|
|
62
|
+
aggregate.output.rejected_prediction = sum(
|
|
63
|
+
(comp) => comp.output.rejected_prediction,
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
|
+
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
5
|
+
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
6
|
+
|
|
7
|
+
export class AgenticaCallEvent<
|
|
8
|
+
Model extends ILlmSchema.Model,
|
|
9
|
+
> extends AgenticaEventBase<"call"> {
|
|
10
|
+
public readonly id: string;
|
|
11
|
+
public readonly operation: AgenticaOperation<Model>;
|
|
12
|
+
public arguments: Record<string, any>;
|
|
13
|
+
|
|
14
|
+
public constructor(props: AgenticaCallEvent.IProps<Model>) {
|
|
15
|
+
super("call");
|
|
16
|
+
this.id = props.id;
|
|
17
|
+
this.operation = props.operation;
|
|
18
|
+
this.arguments = props.arguments;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public toJSON(): IAgenticaEventJson.ICall {
|
|
22
|
+
return {
|
|
23
|
+
type: "call",
|
|
24
|
+
id: this.id,
|
|
25
|
+
operation: this.operation.toJSON(),
|
|
26
|
+
arguments: this.arguments,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export namespace AgenticaCallEvent {
|
|
31
|
+
export interface IProps<Model extends ILlmSchema.Model> {
|
|
32
|
+
id: string;
|
|
33
|
+
operation: AgenticaOperation<Model>;
|
|
34
|
+
arguments: Record<string, any>;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
4
|
+
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
5
|
+
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
6
|
+
|
|
7
|
+
export class AgenticaCancelEvent<
|
|
8
|
+
Model extends ILlmSchema.Model,
|
|
9
|
+
> extends AgenticaEventBase<"cancel"> {
|
|
10
|
+
public readonly selection: AgenticaOperationSelection<Model>;
|
|
11
|
+
|
|
12
|
+
public constructor(props: AgenticaCancelEvent.IProps<Model>) {
|
|
13
|
+
super("cancel");
|
|
14
|
+
this.selection = props.selection;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public toJSON(): IAgenticaEventJson.ICancel {
|
|
18
|
+
return {
|
|
19
|
+
type: "cancel",
|
|
20
|
+
selection: this.selection.toJSON(),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export namespace AgenticaCancelEvent {
|
|
25
|
+
export interface IProps<Model extends ILlmSchema.Model> {
|
|
26
|
+
selection: AgenticaOperationSelection<Model>;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
4
|
+
import { AgenticaDescribePrompt } from "../prompts/AgenticaDescribePrompt";
|
|
5
|
+
import { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
|
|
6
|
+
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
7
|
+
|
|
8
|
+
export class AgenticaDescribeEvent<
|
|
9
|
+
Model extends ILlmSchema.Model,
|
|
10
|
+
> extends AgenticaEventBase<"describe"> {
|
|
11
|
+
public readonly executes: AgenticaExecutePrompt<Model>[];
|
|
12
|
+
public readonly stream: ReadableStream<string>;
|
|
13
|
+
public get text(): string {
|
|
14
|
+
return this.get_();
|
|
15
|
+
}
|
|
16
|
+
public get done(): boolean {
|
|
17
|
+
return this.done_();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public constructor(props: AgenticaDescribeEvent.IProps<Model>) {
|
|
21
|
+
super("describe");
|
|
22
|
+
this.stream = props.stream;
|
|
23
|
+
this.executes = props.executes;
|
|
24
|
+
this.done_ = props.done;
|
|
25
|
+
this.get_ = props.get;
|
|
26
|
+
this.join_ = props.join;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public join(): Promise<string> {
|
|
30
|
+
return this.join_();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public toJSON(): IAgenticaEventJson.IDescribe {
|
|
34
|
+
return {
|
|
35
|
+
type: "describe",
|
|
36
|
+
executes: this.executes.map((e) => e.toJSON()),
|
|
37
|
+
text: this.text,
|
|
38
|
+
done: this.done,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public toPrompt(): AgenticaDescribePrompt<Model> {
|
|
43
|
+
return new AgenticaDescribePrompt({
|
|
44
|
+
executes: this.executes,
|
|
45
|
+
text: this.text,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private readonly done_: () => boolean;
|
|
50
|
+
private readonly get_: () => string;
|
|
51
|
+
private readonly join_: () => Promise<string>;
|
|
52
|
+
}
|
|
53
|
+
export namespace AgenticaDescribeEvent {
|
|
54
|
+
export interface IProps<Model extends ILlmSchema.Model> {
|
|
55
|
+
executes: AgenticaExecutePrompt<Model>[];
|
|
56
|
+
stream: ReadableStream<string>;
|
|
57
|
+
done: () => boolean;
|
|
58
|
+
get: () => string;
|
|
59
|
+
join: () => Promise<string>;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { AgenticaCallEvent } from "./AgenticaCallEvent";
|
|
4
|
+
import { AgenticaCancelEvent } from "./AgenticaCancelEvent";
|
|
5
|
+
import { AgenticaDescribeEvent } from "./AgenticaDescribeEvent";
|
|
6
|
+
import { AgenticaExecuteEvent } from "./AgenticaExecuteEvent";
|
|
7
|
+
import { AgenticaInitializeEvent } from "./AgenticaInitializeEvent";
|
|
8
|
+
import { AgenticaRequestEvent } from "./AgenticaRequestEvent";
|
|
9
|
+
import { AgenticaResponseEvent } from "./AgenticaResponseEvent";
|
|
10
|
+
import { AgenticaSelectEvent } from "./AgenticaSelectEvent";
|
|
11
|
+
import { AgenticaTextEvent } from "./AgenticaTextEvent";
|
|
12
|
+
|
|
13
|
+
export type AgenticaEvent<Model extends ILlmSchema.Model> =
|
|
14
|
+
| AgenticaCallEvent<Model>
|
|
15
|
+
| AgenticaCancelEvent<Model>
|
|
16
|
+
| AgenticaDescribeEvent<Model>
|
|
17
|
+
| AgenticaExecuteEvent<Model>
|
|
18
|
+
| AgenticaInitializeEvent
|
|
19
|
+
| AgenticaRequestEvent
|
|
20
|
+
| AgenticaResponseEvent
|
|
21
|
+
| AgenticaSelectEvent<Model>
|
|
22
|
+
| AgenticaTextEvent;
|
|
23
|
+
export namespace AgenticaEvent {
|
|
24
|
+
export type Type = AgenticaEvent<any>["type"];
|
|
25
|
+
export type Mapper<Model extends ILlmSchema.Model> = {
|
|
26
|
+
call: AgenticaCallEvent<Model>;
|
|
27
|
+
cancel: AgenticaCancelEvent<Model>;
|
|
28
|
+
describe: AgenticaDescribeEvent<Model>;
|
|
29
|
+
execute: AgenticaExecuteEvent<Model>;
|
|
30
|
+
initialize: AgenticaInitializeEvent;
|
|
31
|
+
request: AgenticaRequestEvent;
|
|
32
|
+
response: AgenticaResponseEvent;
|
|
33
|
+
select: AgenticaSelectEvent<Model>;
|
|
34
|
+
text: AgenticaTextEvent;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
|
+
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
5
|
+
import { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
|
|
6
|
+
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
7
|
+
|
|
8
|
+
export class AgenticaExecuteEvent<
|
|
9
|
+
Model extends ILlmSchema.Model,
|
|
10
|
+
> extends AgenticaEventBase<"execute"> {
|
|
11
|
+
public readonly id: string;
|
|
12
|
+
public readonly operation: AgenticaOperation<Model>;
|
|
13
|
+
public readonly arguments: Record<string, any>;
|
|
14
|
+
public readonly value: any;
|
|
15
|
+
|
|
16
|
+
public constructor(props: AgenticaExecuteEvent.IProps<Model>) {
|
|
17
|
+
super("execute");
|
|
18
|
+
this.id = props.id;
|
|
19
|
+
this.operation = props.operation;
|
|
20
|
+
this.arguments = props.arguments;
|
|
21
|
+
this.value = props.value;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public toJSON(): IAgenticaEventJson.IExecute {
|
|
25
|
+
return {
|
|
26
|
+
type: "execute",
|
|
27
|
+
id: this.id,
|
|
28
|
+
operation: this.operation.toJSON(),
|
|
29
|
+
arguments: this.arguments,
|
|
30
|
+
value: this.value,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public toPrompt(): AgenticaExecutePrompt<Model> {
|
|
35
|
+
return new AgenticaExecutePrompt({
|
|
36
|
+
id: this.id,
|
|
37
|
+
operation: this.operation,
|
|
38
|
+
arguments: this.arguments,
|
|
39
|
+
value: this.value,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export namespace AgenticaExecuteEvent {
|
|
44
|
+
export interface IProps<Model extends ILlmSchema.Model> {
|
|
45
|
+
id: string;
|
|
46
|
+
operation: AgenticaOperation<Model>;
|
|
47
|
+
arguments: Record<string, any>;
|
|
48
|
+
value: any;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
2
|
+
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
3
|
+
|
|
4
|
+
export class AgenticaInitializeEvent extends AgenticaEventBase<"initialize"> {
|
|
5
|
+
public constructor() {
|
|
6
|
+
super("initialize");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
public toJSON(): IAgenticaEventJson.IInitialize {
|
|
10
|
+
return {
|
|
11
|
+
type: "initialize",
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
|
|
3
|
+
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
4
|
+
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
5
|
+
import { AgenticaEventSource } from "./AgenticaEventSource";
|
|
6
|
+
|
|
7
|
+
export class AgenticaRequestEvent extends AgenticaEventBase<"request"> {
|
|
8
|
+
public readonly source: AgenticaEventSource;
|
|
9
|
+
public readonly body: OpenAI.ChatCompletionCreateParamsStreaming;
|
|
10
|
+
public readonly options?: OpenAI.RequestOptions | undefined;
|
|
11
|
+
|
|
12
|
+
public constructor(props: AgenticaRequestEvent.IProps) {
|
|
13
|
+
super("request");
|
|
14
|
+
this.source = props.source;
|
|
15
|
+
this.body = props.body;
|
|
16
|
+
this.options = props.options;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public toJSON(): IAgenticaEventJson.IRequest {
|
|
20
|
+
return {
|
|
21
|
+
type: "request",
|
|
22
|
+
source: this.source,
|
|
23
|
+
body: this.body,
|
|
24
|
+
options: this.options,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export namespace AgenticaRequestEvent {
|
|
29
|
+
export interface IProps {
|
|
30
|
+
/**
|
|
31
|
+
* The source agent of the request.
|
|
32
|
+
*/
|
|
33
|
+
source: AgenticaEventSource;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Request body.
|
|
37
|
+
*/
|
|
38
|
+
body: OpenAI.ChatCompletionCreateParamsStreaming;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Options for the request.
|
|
42
|
+
*/
|
|
43
|
+
options?: OpenAI.RequestOptions | undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
|
|
3
|
+
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
4
|
+
import { AgenticaEventSource } from "./AgenticaEventSource";
|
|
5
|
+
|
|
6
|
+
export class AgenticaResponseEvent extends AgenticaEventBase<"response"> {
|
|
7
|
+
public readonly source: AgenticaEventSource;
|
|
8
|
+
public readonly body: OpenAI.ChatCompletionCreateParamsStreaming;
|
|
9
|
+
public readonly stream: ReadableStream<OpenAI.ChatCompletionChunk>;
|
|
10
|
+
public readonly options?: OpenAI.RequestOptions | undefined;
|
|
11
|
+
public readonly join: () => Promise<OpenAI.ChatCompletion>;
|
|
12
|
+
|
|
13
|
+
public constructor(props: AgenticaResponseEvent.IProps) {
|
|
14
|
+
super("response");
|
|
15
|
+
this.source = props.source;
|
|
16
|
+
this.body = props.body;
|
|
17
|
+
this.stream = props.stream;
|
|
18
|
+
this.options = props.options;
|
|
19
|
+
this.join = props.join;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export namespace AgenticaResponseEvent {
|
|
23
|
+
export interface IProps {
|
|
24
|
+
/**
|
|
25
|
+
* The source agent of the response.
|
|
26
|
+
*/
|
|
27
|
+
source: AgenticaEventSource;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Request body.
|
|
31
|
+
*/
|
|
32
|
+
body: OpenAI.ChatCompletionCreateParamsStreaming;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Options for the request.
|
|
36
|
+
*/
|
|
37
|
+
options?: OpenAI.RequestOptions | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* The text content stream.
|
|
40
|
+
*/
|
|
41
|
+
stream: ReadableStream<OpenAI.ChatCompletionChunk>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get the description text.
|
|
45
|
+
*/
|
|
46
|
+
join: () => Promise<OpenAI.ChatCompletion>;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import { v4 } from "uuid";
|
|
3
|
+
|
|
4
|
+
import { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
5
|
+
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
6
|
+
import { AgenticaSelectPrompt } from "../prompts/AgenticaSelectPrompt";
|
|
7
|
+
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
8
|
+
|
|
9
|
+
export class AgenticaSelectEvent<
|
|
10
|
+
Model extends ILlmSchema.Model,
|
|
11
|
+
> extends AgenticaEventBase<"select"> {
|
|
12
|
+
public readonly selection: AgenticaOperationSelection<Model>;
|
|
13
|
+
|
|
14
|
+
public constructor(props: AgenticaSelectEvent.IProps<Model>) {
|
|
15
|
+
super("select");
|
|
16
|
+
this.selection = props.selection;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public toJSON(): IAgenticaEventJson.ISelect {
|
|
20
|
+
return {
|
|
21
|
+
type: "select",
|
|
22
|
+
selection: this.selection.toJSON(),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public toPrompt(): AgenticaSelectPrompt<Model> {
|
|
27
|
+
return new AgenticaSelectPrompt({
|
|
28
|
+
id: v4(),
|
|
29
|
+
selections: [this.selection],
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export namespace AgenticaSelectEvent {
|
|
34
|
+
export interface IProps<Model extends ILlmSchema.Model> {
|
|
35
|
+
selection: AgenticaOperationSelection<Model>;
|
|
36
|
+
}
|
|
37
|
+
}
|