@agentica/core 0.12.21 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -47
- package/lib/Agentica.d.ts +9 -9
- package/lib/Agentica.js +23 -16
- package/lib/Agentica.js.map +1 -1
- package/lib/chatgpt/ChatGptAgent.d.ts +7 -7
- package/lib/chatgpt/ChatGptAgent.js +17 -12
- package/lib/chatgpt/ChatGptAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptCallFunctionAgent.d.ts +7 -6
- package/lib/chatgpt/ChatGptCallFunctionAgent.js +121 -81
- package/lib/chatgpt/ChatGptCallFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptCancelFunctionAgent.d.ts +9 -7
- package/lib/chatgpt/ChatGptCancelFunctionAgent.js +177 -145
- package/lib/chatgpt/ChatGptCancelFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptCompletionMessageUtil.d.ts +13 -8
- package/lib/chatgpt/ChatGptCompletionMessageUtil.js +499 -489
- package/lib/chatgpt/ChatGptCompletionMessageUtil.js.map +1 -1
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.d.ts +7 -6
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.js +33 -32
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptHistoryDecoder.d.ts +7 -6
- package/lib/chatgpt/ChatGptHistoryDecoder.js +60 -56
- package/lib/chatgpt/ChatGptHistoryDecoder.js.map +1 -1
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.d.ts +7 -6
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.js +121 -116
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptSelectFunctionAgent.d.ts +20 -5
- package/lib/chatgpt/ChatGptSelectFunctionAgent.js +183 -150
- package/lib/chatgpt/ChatGptSelectFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptUsageAggregator.d.ts +9 -6
- package/lib/chatgpt/ChatGptUsageAggregator.js +46 -41
- package/lib/chatgpt/ChatGptUsageAggregator.js.map +1 -1
- package/lib/context/AgenticaCancelPrompt.d.ts +3 -3
- package/lib/context/AgenticaCancelPrompt.js +1 -1
- package/lib/context/AgenticaCancelPrompt.js.map +1 -1
- package/lib/context/AgenticaClassOperation.d.ts +1 -1
- package/lib/context/AgenticaClassOperation.js.map +1 -1
- package/lib/context/AgenticaContext.d.ts +9 -9
- package/lib/context/AgenticaHttpOperation.d.ts +1 -1
- package/lib/context/AgenticaHttpOperation.js.map +1 -1
- package/lib/context/AgenticaOperation.d.ts +4 -4
- package/lib/context/AgenticaOperationBase.d.ts +1 -1
- package/lib/context/AgenticaOperationCollection.d.ts +2 -2
- package/lib/context/AgenticaOperationSelection.d.ts +3 -3
- package/lib/context/AgenticaTokenUsage.d.ts +1 -1
- package/lib/context/AgenticaTokenUsage.js.map +1 -1
- package/lib/context/internal/AgenticaTokenUsageAggregator.d.ts +11 -10
- package/lib/context/internal/AgenticaTokenUsageAggregator.js +42 -43
- package/lib/context/internal/AgenticaTokenUsageAggregator.js.map +1 -1
- package/lib/context/internal/__IChatCancelFunctionsApplication.d.ts +2 -2
- package/lib/context/internal/__IChatInitialApplication.d.ts +2 -2
- package/lib/context/internal/__IChatSelectFunctionsApplication.d.ts +2 -2
- package/lib/events/AgenticaCallEvent.d.ts +3 -3
- package/lib/events/AgenticaCancelEvent.d.ts +3 -3
- package/lib/events/AgenticaDescribeEvent.d.ts +3 -3
- package/lib/events/AgenticaDescribeEvent.js +13 -2
- package/lib/events/AgenticaDescribeEvent.js.map +1 -1
- package/lib/events/AgenticaEvent.d.ts +12 -12
- package/lib/events/AgenticaExecuteEvent.d.ts +7 -7
- package/lib/events/AgenticaInitializeEvent.d.ts +1 -1
- package/lib/events/AgenticaRequestEvent.d.ts +3 -3
- package/lib/events/AgenticaRequestEvent.js.map +1 -1
- package/lib/events/AgenticaResponseEvent.d.ts +2 -2
- package/lib/events/AgenticaResponseEvent.js.map +1 -1
- package/lib/events/AgenticaSelectEvent.d.ts +3 -3
- package/lib/events/AgenticaSelectEvent.js.map +1 -1
- package/lib/events/AgenticaTextEvent.d.ts +1 -1
- package/lib/events/AgenticaTextEvent.js +12 -1
- package/lib/events/AgenticaTextEvent.js.map +1 -1
- package/lib/functional/assertHttpLlmApplication.d.ts +4 -3
- package/lib/functional/assertHttpLlmApplication.js +9339 -9338
- package/lib/functional/assertHttpLlmApplication.js.map +1 -1
- package/lib/functional/validateHttpLlmApplication.d.ts +5 -4
- package/lib/functional/validateHttpLlmApplication.js +19 -19
- package/lib/functional/validateHttpLlmApplication.js.map +1 -1
- package/lib/index.d.ts +19 -19
- package/lib/index.js +21 -21
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +19211 -18997
- package/lib/index.mjs.map +1 -1
- package/lib/internal/AgenticaDefaultPrompt.d.ts +6 -5
- package/lib/internal/AgenticaDefaultPrompt.js +39 -19
- package/lib/internal/AgenticaDefaultPrompt.js.map +1 -1
- package/lib/internal/AgenticaOperationComposer.d.ts +11 -10
- package/lib/internal/AgenticaOperationComposer.js +60 -59
- package/lib/internal/AgenticaOperationComposer.js.map +1 -1
- package/lib/internal/AgenticaSystemPrompt.d.ts +8 -8
- package/lib/internal/AgenticaSystemPrompt.js +9 -9
- package/lib/internal/AgenticaSystemPrompt.js.map +1 -1
- package/lib/internal/AsyncQueue.d.ts +15 -0
- package/lib/internal/AsyncQueue.js +82 -0
- package/lib/internal/AsyncQueue.js.map +1 -0
- package/lib/internal/ByteArrayUtil.d.ts +1 -1
- package/lib/internal/ByteArrayUtil.js +3 -2
- package/lib/internal/ByteArrayUtil.js.map +1 -1
- package/lib/internal/MPSC.d.ts +10 -0
- package/lib/internal/MPSC.js +49 -0
- package/lib/internal/MPSC.js.map +1 -0
- package/lib/internal/Singleton.js +6 -5
- package/lib/internal/Singleton.js.map +1 -1
- package/lib/internal/StreamUtil.d.ts +16 -6
- package/lib/internal/StreamUtil.js +43 -29
- package/lib/internal/StreamUtil.js.map +1 -1
- package/lib/internal/__map_take.js +5 -5
- package/lib/internal/__map_take.js.map +1 -1
- package/lib/json/IAgenticaEventJson.d.ts +7 -7
- package/lib/json/IAgenticaOperationSelectionJson.d.ts +1 -1
- package/lib/json/IAgenticaPromptJson.d.ts +2 -2
- package/lib/prompts/AgenticaCancelPrompt.d.ts +3 -3
- package/lib/prompts/AgenticaCancelPrompt.js +1 -1
- package/lib/prompts/AgenticaCancelPrompt.js.map +1 -1
- package/lib/prompts/AgenticaDescribePrompt.d.ts +3 -3
- package/lib/prompts/AgenticaDescribePrompt.js +1 -1
- package/lib/prompts/AgenticaDescribePrompt.js.map +1 -1
- package/lib/prompts/AgenticaExecutePrompt.d.ts +5 -5
- package/lib/prompts/AgenticaExecutePrompt.js.map +1 -1
- package/lib/prompts/AgenticaPrompt.d.ts +6 -6
- package/lib/prompts/AgenticaSelectPrompt.d.ts +3 -3
- package/lib/prompts/AgenticaSelectPrompt.js +1 -1
- package/lib/prompts/AgenticaSelectPrompt.js.map +1 -1
- package/lib/prompts/AgenticaTextPrompt.d.ts +1 -1
- package/lib/structures/IAgenticaConfig.d.ts +5 -5
- package/lib/structures/IAgenticaController.d.ts +1 -1
- package/lib/structures/IAgenticaExecutor.d.ts +4 -4
- package/lib/structures/IAgenticaProps.d.ts +5 -5
- package/lib/structures/IAgenticaSystemPrompt.d.ts +4 -4
- package/lib/structures/IAgenticaVendor.d.ts +1 -1
- package/lib/transformers/AgenticaEventTransformer.d.ts +55 -37
- package/lib/transformers/AgenticaEventTransformer.js +105 -58
- package/lib/transformers/AgenticaEventTransformer.js.map +1 -1
- package/lib/transformers/AgenticaPromptTransformer.d.ts +35 -29
- package/lib/transformers/AgenticaPromptTransformer.js +74 -45
- package/lib/transformers/AgenticaPromptTransformer.js.map +1 -1
- package/package.json +20 -23
- package/prompts/cancel.md +1 -1
- package/prompts/common.md +1 -1
- package/prompts/describe.md +1 -1
- package/prompts/execute.md +1 -1
- package/prompts/initialize.md +1 -1
- package/prompts/select.md +1 -1
- package/src/Agentica.ts +41 -31
- package/src/chatgpt/ChatGptAgent.ts +63 -57
- package/src/chatgpt/ChatGptCallFunctionAgent.ts +363 -337
- package/src/chatgpt/ChatGptCancelFunctionAgent.ts +188 -164
- package/src/chatgpt/ChatGptCompletionMessageUtil.ts +136 -137
- package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +105 -101
- package/src/chatgpt/ChatGptHistoryDecoder.ts +69 -65
- package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +128 -123
- package/src/chatgpt/ChatGptSelectFunctionAgent.ts +215 -189
- package/src/chatgpt/ChatGptUsageAggregator.ts +49 -54
- package/src/context/AgenticaCancelPrompt.ts +4 -4
- package/src/context/AgenticaClassOperation.ts +5 -5
- package/src/context/AgenticaContext.ts +15 -15
- package/src/context/AgenticaHttpOperation.ts +5 -5
- package/src/context/AgenticaOperation.ts +4 -4
- package/src/context/AgenticaOperationBase.ts +1 -1
- package/src/context/AgenticaOperationCollection.ts +2 -2
- package/src/context/AgenticaOperationSelection.ts +3 -3
- package/src/context/AgenticaTokenUsage.ts +4 -3
- package/src/context/internal/AgenticaTokenUsageAggregator.ts +59 -59
- package/src/context/internal/__IChatCancelFunctionsApplication.ts +2 -2
- package/src/context/internal/__IChatInitialApplication.ts +2 -2
- package/src/context/internal/__IChatSelectFunctionsApplication.ts +2 -2
- package/src/events/AgenticaCallEvent.ts +3 -3
- package/src/events/AgenticaCancelEvent.ts +3 -3
- package/src/events/AgenticaDescribeEvent.ts +5 -5
- package/src/events/AgenticaEvent.ts +12 -12
- package/src/events/AgenticaExecuteEvent.ts +7 -7
- package/src/events/AgenticaInitializeEvent.ts +1 -1
- package/src/events/AgenticaRequestEvent.ts +3 -3
- package/src/events/AgenticaResponseEvent.ts +2 -2
- package/src/events/AgenticaSelectEvent.ts +4 -4
- package/src/events/AgenticaTextEvent.ts +2 -2
- package/src/functional/assertHttpLlmApplication.ts +9 -6
- package/src/functional/validateHttpLlmApplication.ts +14 -8
- package/src/index.ts +24 -24
- package/src/internal/AgenticaDefaultPrompt.ts +42 -28
- package/src/internal/AgenticaOperationComposer.ts +63 -61
- package/src/internal/AgenticaSystemPrompt.ts +15 -14
- package/src/internal/AsyncQueue.ts +67 -0
- package/src/internal/ByteArrayUtil.ts +2 -2
- package/src/internal/MPSC.ts +40 -0
- package/src/internal/Singleton.ts +8 -6
- package/src/internal/StreamUtil.ts +62 -53
- package/src/internal/__map_take.ts +5 -7
- package/src/json/IAgenticaEventJson.ts +7 -8
- package/src/json/IAgenticaOperationSelectionJson.ts +1 -1
- package/src/json/IAgenticaPromptJson.ts +2 -2
- package/src/prompts/AgenticaCancelPrompt.ts +4 -4
- package/src/prompts/AgenticaDescribePrompt.ts +4 -4
- package/src/prompts/AgenticaExecutePrompt.ts +6 -5
- package/src/prompts/AgenticaPrompt.ts +6 -6
- package/src/prompts/AgenticaSelectPrompt.ts +4 -4
- package/src/prompts/AgenticaTextPrompt.ts +1 -1
- package/src/structures/IAgenticaConfig.ts +5 -5
- package/src/structures/IAgenticaController.ts +14 -14
- package/src/structures/IAgenticaExecutor.ts +4 -4
- package/src/structures/IAgenticaProps.ts +5 -5
- package/src/structures/IAgenticaSystemPrompt.ts +4 -4
- package/src/structures/IAgenticaVendor.ts +1 -1
- package/src/transformers/AgenticaEventTransformer.ts +169 -136
- package/src/transformers/AgenticaPromptTransformer.ts +125 -103
- package/lib/internal/MPSCUtil.d.ts +0 -35
- package/lib/internal/MPSCUtil.js +0 -105
- package/lib/internal/MPSCUtil.js.map +0 -1
- package/src/internal/MPSCUtil.ts +0 -111
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import OpenAI from "openai";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import type OpenAI from "openai";
|
|
3
3
|
|
|
4
|
-
import { AgenticaEvent } from "../events/AgenticaEvent";
|
|
5
|
-
import { AgenticaEventSource } from "../events/AgenticaEventSource";
|
|
6
|
-
import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
7
|
-
import { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
|
|
8
|
-
import { IAgenticaConfig } from "../structures/IAgenticaConfig";
|
|
9
|
-
import { AgenticaOperationCollection } from "./AgenticaOperationCollection";
|
|
10
|
-
import { AgenticaOperationSelection } from "./AgenticaOperationSelection";
|
|
4
|
+
import type { AgenticaEvent } from "../events/AgenticaEvent";
|
|
5
|
+
import type { AgenticaEventSource } from "../events/AgenticaEventSource";
|
|
6
|
+
import type { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
7
|
+
import type { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
|
|
8
|
+
import type { IAgenticaConfig } from "../structures/IAgenticaConfig";
|
|
9
|
+
import type { AgenticaOperationCollection } from "./AgenticaOperationCollection";
|
|
10
|
+
import type { AgenticaOperationSelection } from "./AgenticaOperationSelection";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Context of the Nestia A.I. agent.
|
|
@@ -41,9 +41,9 @@ import { AgenticaOperationSelection } from "./AgenticaOperationSelection";
|
|
|
41
41
|
* @author Samchon
|
|
42
42
|
*/
|
|
43
43
|
export interface AgenticaContext<Model extends ILlmSchema.Model> {
|
|
44
|
-
|
|
44
|
+
// ----
|
|
45
45
|
// APPLICATION
|
|
46
|
-
|
|
46
|
+
// ----
|
|
47
47
|
/**
|
|
48
48
|
* Collection of operations.
|
|
49
49
|
*
|
|
@@ -63,9 +63,9 @@ export interface AgenticaContext<Model extends ILlmSchema.Model> {
|
|
|
63
63
|
*/
|
|
64
64
|
config: IAgenticaConfig<Model> | undefined;
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
// ----
|
|
67
67
|
// STATES
|
|
68
|
-
|
|
68
|
+
// ----
|
|
69
69
|
/**
|
|
70
70
|
* Prompt histories.
|
|
71
71
|
*/
|
|
@@ -98,9 +98,9 @@ export interface AgenticaContext<Model extends ILlmSchema.Model> {
|
|
|
98
98
|
*/
|
|
99
99
|
ready: () => boolean;
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
// ----
|
|
102
102
|
// HANDLERS
|
|
103
|
-
|
|
103
|
+
// ----
|
|
104
104
|
/**
|
|
105
105
|
* Dispatch event.
|
|
106
106
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
IHttpLlmApplication,
|
|
3
3
|
IHttpLlmFunction,
|
|
4
4
|
ILlmSchema,
|
|
@@ -9,10 +9,10 @@ import { AgenticaOperationBase } from "./AgenticaOperationBase";
|
|
|
9
9
|
export class AgenticaHttpOperation<
|
|
10
10
|
Model extends ILlmSchema.Model,
|
|
11
11
|
> extends AgenticaOperationBase<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
> {
|
|
12
|
+
"http",
|
|
13
|
+
IHttpLlmApplication<Model>,
|
|
14
|
+
IHttpLlmFunction<Model>
|
|
15
|
+
> {
|
|
16
16
|
public constructor(props: AgenticaHttpOperation.IProps<Model>) {
|
|
17
17
|
super(props);
|
|
18
18
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IHttpLlmFunction, ILlmFunction, ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { IHttpLlmFunction, ILlmFunction, ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { IAgenticaOperationJson } from "../json/IAgenticaOperationJson";
|
|
4
|
-
import { IAgenticaController } from "../structures/IAgenticaController";
|
|
3
|
+
import type { IAgenticaOperationJson } from "../json/IAgenticaOperationJson";
|
|
4
|
+
import type { IAgenticaController } from "../structures/IAgenticaController";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Operation information in the Agentica Agent.
|
|
@@ -61,6 +61,6 @@ export namespace AgenticaOperation {
|
|
|
61
61
|
/**
|
|
62
62
|
* Convert to primitive JSON object.
|
|
63
63
|
*/
|
|
64
|
-
toJSON()
|
|
64
|
+
toJSON: () => IAgenticaOperationJson;
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { AgenticaOperation } from "./AgenticaOperation";
|
|
3
|
+
import type { AgenticaOperation } from "./AgenticaOperation";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Collection of operations used in the Nestia Agent.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { IAgenticaOperationSelectionJson } from "../json/IAgenticaOperationSelectionJson";
|
|
4
|
-
import { AgenticaOperation } from "./AgenticaOperation";
|
|
3
|
+
import type { IAgenticaOperationSelectionJson } from "../json/IAgenticaOperationSelectionJson";
|
|
4
|
+
import type { AgenticaOperation } from "./AgenticaOperation";
|
|
5
5
|
|
|
6
6
|
export class AgenticaOperationSelection<Model extends ILlmSchema.Model> {
|
|
7
7
|
public readonly operation: AgenticaOperation<Model>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { IAgenticaTokenUsageJson } from "../json/IAgenticaTokenUsageJson";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import typia from "typia";
|
|
4
4
|
|
|
5
5
|
export class AgenticaTokenUsage implements IAgenticaTokenUsageJson {
|
|
6
6
|
/**
|
|
@@ -42,7 +42,8 @@ export class AgenticaTokenUsage implements IAgenticaTokenUsageJson {
|
|
|
42
42
|
this.cancel = zero.cancel;
|
|
43
43
|
this.call = zero.call;
|
|
44
44
|
this.describe = zero.describe;
|
|
45
|
-
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
46
47
|
this.aggregate = props.aggregate;
|
|
47
48
|
this.initialize = props.initialize;
|
|
48
49
|
this.select = props.select;
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import { CompletionUsage } from "openai/resources";
|
|
1
|
+
import type { CompletionUsage } from "openai/resources";
|
|
2
2
|
|
|
3
|
-
import { IAgenticaTokenUsageJson } from "../../json/IAgenticaTokenUsageJson";
|
|
4
|
-
import { AgenticaTokenUsage } from "../AgenticaTokenUsage";
|
|
3
|
+
import type { IAgenticaTokenUsageJson } from "../../json/IAgenticaTokenUsageJson";
|
|
4
|
+
import type { AgenticaTokenUsage } from "../AgenticaTokenUsage";
|
|
5
5
|
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
export function aggregate(props: {
|
|
7
|
+
kind: Exclude<keyof IAgenticaTokenUsageJson, "aggregate">;
|
|
8
|
+
completionUsage: CompletionUsage;
|
|
9
|
+
usage: AgenticaTokenUsage;
|
|
10
|
+
}): void {
|
|
11
|
+
// ----
|
|
12
|
+
// COMPONENT
|
|
13
|
+
// ----
|
|
14
|
+
const component: AgenticaTokenUsage.IComponent = props.usage[props.kind];
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
//----
|
|
17
|
-
const component: AgenticaTokenUsage.IComponent = props.usage[props.kind];
|
|
16
|
+
// TOTAL
|
|
17
|
+
component.total += props.completionUsage.total_tokens;
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
// PROMPT
|
|
20
|
+
component.input.total += props.completionUsage.prompt_tokens;
|
|
21
|
+
component.input.total
|
|
22
|
+
+= props.completionUsage.prompt_tokens_details?.audio_tokens ?? 0;
|
|
23
|
+
component.input.cached
|
|
24
|
+
+= props.completionUsage.prompt_tokens_details?.cached_tokens ?? 0;
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
props.completionUsage.
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
// COMPLETION
|
|
27
|
+
component.output.total += props.completionUsage.completion_tokens;
|
|
28
|
+
component.output.accepted_prediction
|
|
29
|
+
+= props.completionUsage.completion_tokens_details
|
|
30
|
+
?.accepted_prediction_tokens ?? 0;
|
|
31
|
+
component.output.reasoning
|
|
32
|
+
+= props.completionUsage.completion_tokens_details?.reasoning_tokens ?? 0;
|
|
33
|
+
component.output.rejected_prediction
|
|
34
|
+
+= props.completionUsage.completion_tokens_details
|
|
35
|
+
?.rejected_prediction_tokens ?? 0;
|
|
28
36
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
};
|
|
37
|
+
// ----
|
|
38
|
+
// RE-AGGREGATE
|
|
39
|
+
// ----
|
|
40
|
+
const sum = (getter: (comp: AgenticaTokenUsage.IComponent) => number) =>
|
|
41
|
+
(
|
|
42
|
+
Object.entries(props.usage) as [
|
|
43
|
+
keyof AgenticaTokenUsage,
|
|
44
|
+
AgenticaTokenUsage.IComponent,
|
|
45
|
+
][]
|
|
46
|
+
)
|
|
47
|
+
.filter(([key]) => key !== "aggregate")
|
|
48
|
+
.map(([, comp]) => getter(comp))
|
|
49
|
+
.reduce((a, b) => a + b, 0);
|
|
50
|
+
const aggregate: AgenticaTokenUsage.IComponent = props.usage.aggregate;
|
|
51
|
+
aggregate.total = sum(comp => comp.total);
|
|
52
|
+
aggregate.input.total = sum(comp => comp.input.total);
|
|
53
|
+
aggregate.input.cached = sum(comp => comp.input.cached);
|
|
54
|
+
aggregate.output.total = sum(comp => comp.output.total);
|
|
55
|
+
aggregate.output.reasoning = sum(comp => comp.output.reasoning);
|
|
56
|
+
aggregate.output.accepted_prediction = sum(
|
|
57
|
+
comp => comp.output.accepted_prediction,
|
|
58
|
+
);
|
|
59
|
+
aggregate.output.rejected_prediction = sum(
|
|
60
|
+
comp => comp.output.rejected_prediction,
|
|
61
|
+
);
|
|
66
62
|
}
|
|
63
|
+
|
|
64
|
+
export const AgenticaTokenUsageAggregator = {
|
|
65
|
+
aggregate,
|
|
66
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __IChatFunctionReference } from "./__IChatFunctionReference";
|
|
1
|
+
import type { __IChatFunctionReference } from "./__IChatFunctionReference";
|
|
2
2
|
|
|
3
3
|
export interface __IChatCancelFunctionsApplication {
|
|
4
4
|
/**
|
|
@@ -19,5 +19,5 @@ export interface __IChatCancelFunctionsApplication {
|
|
|
19
19
|
*
|
|
20
20
|
* @param props Properties of the function
|
|
21
21
|
*/
|
|
22
|
-
cancelFunctions(props: __IChatFunctionReference.IProps)
|
|
22
|
+
cancelFunctions: (props: __IChatFunctionReference.IProps) => Promise<void>;
|
|
23
23
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IHttpLlmFunction } from "@samchon/openapi";
|
|
1
|
+
import type { IHttpLlmFunction } from "@samchon/openapi";
|
|
2
2
|
|
|
3
3
|
export interface __IChatInitialApplication {
|
|
4
4
|
/**
|
|
@@ -11,5 +11,5 @@ export interface __IChatInitialApplication {
|
|
|
11
11
|
* Also, user just wants to list up every remote API functions that can be
|
|
12
12
|
* called from the backend server, utilize this function too.
|
|
13
13
|
*/
|
|
14
|
-
getApiFunctions(
|
|
14
|
+
getApiFunctions: (props: object) => Promise<Array<IHttpLlmFunction<"chatgpt">>>;
|
|
15
15
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __IChatFunctionReference } from "./__IChatFunctionReference";
|
|
1
|
+
import type { __IChatFunctionReference } from "./__IChatFunctionReference";
|
|
2
2
|
|
|
3
3
|
export interface __IChatSelectFunctionsApplication {
|
|
4
4
|
/**
|
|
@@ -20,5 +20,5 @@ export interface __IChatSelectFunctionsApplication {
|
|
|
20
20
|
*
|
|
21
21
|
* @param props Properties of the function
|
|
22
22
|
*/
|
|
23
|
-
selectFunctions(props: __IChatFunctionReference.IProps)
|
|
23
|
+
selectFunctions: (props: __IChatFunctionReference.IProps) => Promise<void>;
|
|
24
24
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
|
-
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
3
|
+
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
|
+
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
5
5
|
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
6
6
|
|
|
7
7
|
export class AgenticaCallEvent<
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
4
|
-
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
3
|
+
import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
4
|
+
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
5
5
|
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
6
6
|
|
|
7
7
|
export class AgenticaCancelEvent<
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
3
|
+
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
4
|
+
import type { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
|
|
4
5
|
import { AgenticaDescribePrompt } from "../prompts/AgenticaDescribePrompt";
|
|
5
|
-
import { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
|
|
6
6
|
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
7
7
|
|
|
8
8
|
export class AgenticaDescribeEvent<
|
|
@@ -31,14 +31,14 @@ export class AgenticaDescribeEvent<
|
|
|
31
31
|
this.join_ = props.join;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
public join(): Promise<string> {
|
|
34
|
+
public async join(): Promise<string> {
|
|
35
35
|
return this.join_();
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
public toJSON(): IAgenticaEventJson.IDescribe {
|
|
39
39
|
return {
|
|
40
40
|
type: "describe",
|
|
41
|
-
executes: this.executes.map(
|
|
41
|
+
executes: this.executes.map(e => e.toJSON()),
|
|
42
42
|
text: this.text,
|
|
43
43
|
done: this.done,
|
|
44
44
|
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
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";
|
|
3
|
+
import type { AgenticaCallEvent } from "./AgenticaCallEvent";
|
|
4
|
+
import type { AgenticaCancelEvent } from "./AgenticaCancelEvent";
|
|
5
|
+
import type { AgenticaDescribeEvent } from "./AgenticaDescribeEvent";
|
|
6
|
+
import type { AgenticaExecuteEvent } from "./AgenticaExecuteEvent";
|
|
7
|
+
import type { AgenticaInitializeEvent } from "./AgenticaInitializeEvent";
|
|
8
|
+
import type { AgenticaRequestEvent } from "./AgenticaRequestEvent";
|
|
9
|
+
import type { AgenticaResponseEvent } from "./AgenticaResponseEvent";
|
|
10
|
+
import type { AgenticaSelectEvent } from "./AgenticaSelectEvent";
|
|
11
|
+
import type { AgenticaTextEvent } from "./AgenticaTextEvent";
|
|
12
12
|
|
|
13
13
|
export type AgenticaEvent<Model extends ILlmSchema.Model> =
|
|
14
14
|
| AgenticaCallEvent<Model>
|
|
@@ -22,7 +22,7 @@ export type AgenticaEvent<Model extends ILlmSchema.Model> =
|
|
|
22
22
|
| AgenticaTextEvent;
|
|
23
23
|
export namespace AgenticaEvent {
|
|
24
24
|
export type Type = AgenticaEvent<any>["type"];
|
|
25
|
-
export
|
|
25
|
+
export interface Mapper<Model extends ILlmSchema.Model> {
|
|
26
26
|
call: AgenticaCallEvent<Model>;
|
|
27
27
|
cancel: AgenticaCancelEvent<Model>;
|
|
28
28
|
describe: AgenticaDescribeEvent<Model>;
|
|
@@ -32,5 +32,5 @@ export namespace AgenticaEvent {
|
|
|
32
32
|
response: AgenticaResponseEvent;
|
|
33
33
|
select: AgenticaSelectEvent<Model>;
|
|
34
34
|
text: AgenticaTextEvent;
|
|
35
|
-
}
|
|
35
|
+
}
|
|
36
36
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
|
-
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
3
|
+
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
|
+
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
5
5
|
import { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
|
|
6
6
|
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
7
7
|
|
|
@@ -10,8 +10,8 @@ export class AgenticaExecuteEvent<
|
|
|
10
10
|
> extends AgenticaEventBase<"execute"> {
|
|
11
11
|
public readonly id: string;
|
|
12
12
|
public readonly operation: AgenticaOperation<Model>;
|
|
13
|
-
public readonly arguments: Record<string,
|
|
14
|
-
public readonly value:
|
|
13
|
+
public readonly arguments: Record<string, unknown>;
|
|
14
|
+
public readonly value: unknown;
|
|
15
15
|
|
|
16
16
|
public constructor(props: AgenticaExecuteEvent.IProps<Model>) {
|
|
17
17
|
super("execute");
|
|
@@ -44,7 +44,7 @@ export namespace AgenticaExecuteEvent {
|
|
|
44
44
|
export interface IProps<Model extends ILlmSchema.Model> {
|
|
45
45
|
id: string;
|
|
46
46
|
operation: AgenticaOperation<Model>;
|
|
47
|
-
arguments: Record<string,
|
|
48
|
-
value:
|
|
47
|
+
arguments: Record<string, unknown>;
|
|
48
|
+
value: unknown;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
1
|
+
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
2
2
|
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
3
3
|
|
|
4
4
|
export class AgenticaInitializeEvent extends AgenticaEventBase<"initialize"> {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import OpenAI from "openai";
|
|
1
|
+
import type OpenAI from "openai";
|
|
2
2
|
|
|
3
|
-
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
3
|
+
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
4
|
+
import type { AgenticaEventSource } from "./AgenticaEventSource";
|
|
4
5
|
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
5
|
-
import { AgenticaEventSource } from "./AgenticaEventSource";
|
|
6
6
|
|
|
7
7
|
export class AgenticaRequestEvent extends AgenticaEventBase<"request"> {
|
|
8
8
|
public readonly source: AgenticaEventSource;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import OpenAI from "openai";
|
|
1
|
+
import type OpenAI from "openai";
|
|
2
2
|
|
|
3
|
+
import type { AgenticaEventSource } from "./AgenticaEventSource";
|
|
3
4
|
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
4
|
-
import { AgenticaEventSource } from "./AgenticaEventSource";
|
|
5
5
|
|
|
6
6
|
export class AgenticaResponseEvent extends AgenticaEventBase<"response"> {
|
|
7
7
|
public readonly source: AgenticaEventSource;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import {
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
5
|
+
import { v4 } from "uuid";
|
|
6
6
|
import { AgenticaSelectPrompt } from "../prompts/AgenticaSelectPrompt";
|
|
7
7
|
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
8
8
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
1
|
+
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
2
2
|
import { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
|
|
3
3
|
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
4
4
|
|
|
@@ -27,7 +27,7 @@ export class AgenticaTextEvent extends AgenticaEventBase<"text"> {
|
|
|
27
27
|
this.join_ = props.join;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
public join(): Promise<string> {
|
|
30
|
+
public async join(): Promise<string> {
|
|
31
31
|
return this.join_();
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HttpLlm,
|
|
1
|
+
import type {
|
|
3
2
|
IHttpLlmApplication,
|
|
4
3
|
ILlmSchema,
|
|
5
|
-
OpenApi,
|
|
6
4
|
OpenApiV3,
|
|
7
5
|
OpenApiV3_1,
|
|
8
6
|
SwaggerV2,
|
|
9
7
|
} from "@samchon/openapi";
|
|
8
|
+
import {
|
|
9
|
+
HttpLlm,
|
|
10
|
+
OpenApi,
|
|
11
|
+
} from "@samchon/openapi";
|
|
10
12
|
import typia from "typia";
|
|
11
13
|
|
|
12
14
|
/**
|
|
@@ -26,7 +28,7 @@ import typia from "typia";
|
|
|
26
28
|
* @throws {@link TypeGuardError} when the given document is invalid
|
|
27
29
|
* @author Samchon
|
|
28
30
|
*/
|
|
29
|
-
export
|
|
31
|
+
export function assertHttpLlmApplication<
|
|
30
32
|
Model extends ILlmSchema.Model,
|
|
31
33
|
>(props: {
|
|
32
34
|
/**
|
|
@@ -47,9 +49,10 @@ export const assertHttpLlmApplication = <
|
|
|
47
49
|
* Options for the LLM function calling schema composition.
|
|
48
50
|
*/
|
|
49
51
|
options?: Partial<IHttpLlmApplication.IOptions<Model>>;
|
|
50
|
-
}): IHttpLlmApplication<Model>
|
|
51
|
-
HttpLlm.application({
|
|
52
|
+
}): IHttpLlmApplication<Model> {
|
|
53
|
+
return HttpLlm.application({
|
|
52
54
|
model: props.model,
|
|
53
55
|
document: OpenApi.convert(typia.assert(props.document)),
|
|
54
56
|
options: props.options,
|
|
55
57
|
});
|
|
58
|
+
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HttpLlm,
|
|
1
|
+
import type {
|
|
3
2
|
IHttpLlmApplication,
|
|
4
3
|
ILlmSchema,
|
|
5
|
-
OpenApi,
|
|
6
4
|
OpenApiV3,
|
|
7
5
|
OpenApiV3_1,
|
|
8
6
|
SwaggerV2,
|
|
9
7
|
} from "@samchon/openapi";
|
|
10
|
-
import
|
|
8
|
+
import type { IValidation } from "typia";
|
|
9
|
+
import {
|
|
10
|
+
HttpLlm,
|
|
11
|
+
OpenApi,
|
|
12
|
+
} from "@samchon/openapi";
|
|
13
|
+
import typia from "typia";
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
16
|
* Create an HTTP LLM application instance with type validation.
|
|
@@ -26,7 +29,7 @@ import typia, { IValidation } from "typia";
|
|
|
26
29
|
* @returns Validation result of the HTTP LLM application composition
|
|
27
30
|
* @author Samchon
|
|
28
31
|
*/
|
|
29
|
-
export
|
|
32
|
+
export function validateHttpLlmApplication<
|
|
30
33
|
Model extends ILlmSchema.Model,
|
|
31
34
|
>(props: {
|
|
32
35
|
/**
|
|
@@ -47,14 +50,17 @@ export const validateHttpLlmApplication = <
|
|
|
47
50
|
* Options for the LLM function calling schema composition.
|
|
48
51
|
*/
|
|
49
52
|
options?: Partial<IHttpLlmApplication.IOptions<Model>>;
|
|
50
|
-
}): IValidation<IHttpLlmApplication<Model>>
|
|
53
|
+
}): IValidation<IHttpLlmApplication<Model>> {
|
|
51
54
|
const inspect: IValidation<
|
|
52
55
|
| SwaggerV2.IDocument
|
|
53
56
|
| OpenApiV3.IDocument
|
|
54
57
|
| OpenApiV3_1.IDocument
|
|
55
58
|
| OpenApi.IDocument
|
|
56
59
|
> = typia.validate(props.document);
|
|
57
|
-
if (inspect.success === false)
|
|
60
|
+
if (inspect.success === false) {
|
|
61
|
+
return inspect;
|
|
62
|
+
}
|
|
63
|
+
|
|
58
64
|
return {
|
|
59
65
|
success: true,
|
|
60
66
|
data: HttpLlm.application({
|
|
@@ -63,4 +69,4 @@ export const validateHttpLlmApplication = <
|
|
|
63
69
|
options: props.options,
|
|
64
70
|
}),
|
|
65
71
|
};
|
|
66
|
-
}
|
|
72
|
+
}
|