@agentica/core 0.12.21 → 0.13.1
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 +120 -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 +19210 -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 +361 -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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatGptCompletionMessageUtil.js","sourceRoot":"","sources":["../../src/chatgpt/ChatGptCompletionMessageUtil.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ChatGptCompletionMessageUtil.js","sourceRoot":"","sources":["../../src/chat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0CAAE,IAAI,mCAAI,EAAE;oBACnC,SAAS,EAAE,MAAA,MAAA,QAAQ,CAAC,QAAQ,0CAAE,SAAS,mCAAI,EAAE;iBAC9C;aACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAgB,cAAc,CAAC,GAAkC,EAAE,GAA8C;;IAC/G,IAAI,GAAG,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAC;QACzB,GAAG,CAAC,QAAQ,CAAC,SAAS,IAAI,MAAA,GAAG,CAAC,QAAQ,CAAC,SAAS,mCAAI,EAAE,CAAC;QACvD,GAAG,CAAC,QAAQ,CAAC,IAAI,IAAI,MAAA,GAAG,CAAC,QAAQ,CAAC,IAAI,mCAAI,EAAE,CAAC;IAC/C,CAAC;IAED,GAAG,CAAC,EAAE,IAAI,MAAA,GAAG,CAAC,EAAE,mCAAI,EAAE,CAAC;IAEvB,OAAO,GAAG,CAAC;AACb,CAAC;AAEY,QAAA,4BAA4B,GAAG;IAC1C,wBAAwB;IACxB,UAAU;IACV,KAAK;IACL,WAAW;IACX,cAAc;CACf,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import { AgenticaContext } from "../context/AgenticaContext";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import type { AgenticaContext } from "../context/AgenticaContext";
|
|
3
|
+
import type { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
|
|
3
4
|
import { AgenticaDescribePrompt } from "../prompts/AgenticaDescribePrompt";
|
|
4
|
-
|
|
5
|
-
export declare
|
|
6
|
-
|
|
7
|
-
}
|
|
5
|
+
export declare function execute<Model extends ILlmSchema.Model>(ctx: AgenticaContext<Model>, histories: AgenticaExecutePrompt<Model>[]): Promise<AgenticaDescribePrompt<Model>[]>;
|
|
6
|
+
export declare const ChatGptDescribeFunctionAgent: {
|
|
7
|
+
execute: typeof execute;
|
|
8
|
+
};
|
|
@@ -10,20 +10,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.ChatGptDescribeFunctionAgent = void 0;
|
|
13
|
+
exports.execute = execute;
|
|
13
14
|
const AgenticaDescribeEvent_1 = require("../events/AgenticaDescribeEvent");
|
|
14
15
|
const AgenticaDefaultPrompt_1 = require("../internal/AgenticaDefaultPrompt");
|
|
15
16
|
const AgenticaSystemPrompt_1 = require("../internal/AgenticaSystemPrompt");
|
|
16
|
-
const
|
|
17
|
+
const MPSC_1 = require("../internal/MPSC");
|
|
17
18
|
const StreamUtil_1 = require("../internal/StreamUtil");
|
|
18
19
|
const AgenticaDescribePrompt_1 = require("../prompts/AgenticaDescribePrompt");
|
|
19
20
|
const ChatGptCompletionMessageUtil_1 = require("./ChatGptCompletionMessageUtil");
|
|
20
21
|
const ChatGptHistoryDecoder_1 = require("./ChatGptHistoryDecoder");
|
|
21
|
-
|
|
22
|
-
(function (
|
|
23
|
-
ChatGptDescribeFunctionAgent.execute = (ctx, histories) => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
function execute(ctx, histories) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
24
|
var _a, _b, _c, _d;
|
|
25
|
-
if (histories.length === 0)
|
|
25
|
+
if (histories.length === 0) {
|
|
26
26
|
return [];
|
|
27
|
+
}
|
|
27
28
|
const completionStream = yield ctx.request("describe", {
|
|
28
29
|
messages: [
|
|
29
30
|
// COMMON SYSTEM PROMPT
|
|
@@ -45,63 +46,63 @@ var ChatGptDescribeFunctionAgent;
|
|
|
45
46
|
const acc = yield accPromise;
|
|
46
47
|
const registerContext = (choices) => {
|
|
47
48
|
for (const choice of choices) {
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
/**
|
|
50
|
+
* @TODO fix it
|
|
51
|
+
* Sometimes, the complete message arrives along with a finish reason.
|
|
52
|
+
*/
|
|
53
|
+
if (choice.finish_reason != null) {
|
|
54
|
+
describeContext[choice.index].mpsc.close();
|
|
50
55
|
continue;
|
|
51
56
|
}
|
|
52
|
-
if (
|
|
57
|
+
if (choice.delta.content == null) {
|
|
53
58
|
continue;
|
|
54
59
|
}
|
|
55
|
-
if (describeContext[choice.index]) {
|
|
60
|
+
if (describeContext[choice.index] != null) {
|
|
56
61
|
describeContext[choice.index].content += choice.delta.content;
|
|
57
|
-
describeContext[choice.index].produce(choice.delta.content);
|
|
62
|
+
describeContext[choice.index].mpsc.produce(choice.delta.content);
|
|
58
63
|
continue;
|
|
59
64
|
}
|
|
60
|
-
const
|
|
65
|
+
const mpsc = new MPSC_1.MPSC();
|
|
61
66
|
describeContext[choice.index] = {
|
|
62
67
|
content: choice.delta.content,
|
|
63
|
-
|
|
64
|
-
produce,
|
|
65
|
-
close,
|
|
66
|
-
waitClosed,
|
|
67
|
-
waitUntilEmpty,
|
|
68
|
-
done,
|
|
68
|
+
mpsc,
|
|
69
69
|
};
|
|
70
|
-
produce(choice.delta.content);
|
|
70
|
+
mpsc.produce(choice.delta.content);
|
|
71
71
|
void ctx.dispatch(new AgenticaDescribeEvent_1.AgenticaDescribeEvent({
|
|
72
72
|
executes: histories,
|
|
73
|
-
stream: consumer,
|
|
74
|
-
done,
|
|
73
|
+
stream: mpsc.consumer,
|
|
74
|
+
done: () => mpsc.done(),
|
|
75
75
|
get: () => { var _a, _b; return (_b = (_a = describeContext[choice.index]) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : ""; },
|
|
76
76
|
join: () => __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
yield waitClosed();
|
|
77
|
+
yield mpsc.waitClosed();
|
|
78
78
|
return describeContext[choice.index].content;
|
|
79
79
|
}),
|
|
80
80
|
}));
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
83
|
if (acc.object === "chat.completion.chunk") {
|
|
84
|
-
registerContext([acc, chunk].flatMap(
|
|
84
|
+
registerContext([acc, chunk].flatMap(v => v.choices));
|
|
85
85
|
return ChatGptCompletionMessageUtil_1.ChatGptCompletionMessageUtil.merge([acc, chunk]);
|
|
86
86
|
}
|
|
87
87
|
registerContext(chunk.choices);
|
|
88
88
|
return ChatGptCompletionMessageUtil_1.ChatGptCompletionMessageUtil.accumulate(acc, chunk);
|
|
89
89
|
}));
|
|
90
|
-
if (
|
|
90
|
+
if (completion == null) {
|
|
91
91
|
throw new Error("No completion received");
|
|
92
|
+
}
|
|
92
93
|
const descriptions = completion.choices
|
|
93
|
-
.map(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
})
|
|
99
|
-
.filter((str) => str !== null)
|
|
100
|
-
.map((content) => new AgenticaDescribePrompt_1.AgenticaDescribePrompt({
|
|
94
|
+
.map(choice => choice.message.role === "assistant"
|
|
95
|
+
? choice.message.content
|
|
96
|
+
: null)
|
|
97
|
+
.filter(str => str !== null)
|
|
98
|
+
.map(content => new AgenticaDescribePrompt_1.AgenticaDescribePrompt({
|
|
101
99
|
executes: histories,
|
|
102
100
|
text: content,
|
|
103
101
|
}));
|
|
104
102
|
return descriptions;
|
|
105
103
|
});
|
|
106
|
-
}
|
|
104
|
+
}
|
|
105
|
+
exports.ChatGptDescribeFunctionAgent = {
|
|
106
|
+
execute,
|
|
107
|
+
};
|
|
107
108
|
//# sourceMappingURL=ChatGptDescribeFunctionAgent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatGptDescribeFunctionAgent.js","sourceRoot":"","sources":["../../src/chatgpt/ChatGptDescribeFunctionAgent.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ChatGptDescribeFunctionAgent.js","sourceRoot":"","sources":["../../src/chatgpt/ChatGptDescribeFunctionAgent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAcA,0BA2GC;AApHD,2EAAwE;AACx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gBAC3C,eAAe,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;gBACtD,OAAO,2DAA4B,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;YAC1D,CAAC;YAED,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC/B,OAAO,2DAA4B,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC7D,CAAC,CAAA,CAAC,CAAC;QAEH,IAAI,UAAU,IAAI,IAAI,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC5C,CAAC;QACD,MAAM,YAAY,GAAoC,UAAU,CAAC,OAAO;aACrE,GAAG,CAAC,MAAM,CAAC,EAAE,CACZ,MAAM,CAAC,OAAO,CAAC,IAAI,KAAK,WAAW;YACjC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO;YACxB,CAAC,CAAC,IAAI,CACT;aACA,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC;aAC3B,GAAG,CACF,OAAO,CAAC,EAAE,CACR,IAAI,+CAAsB,CAAC;YACzB,QAAQ,EAAE,SAAS;YACnB,IAAI,EAAE,OAAO;SACd,CAAC,CACL,CAAC;QACJ,OAAO,YAAY,CAAC;IACtB,CAAC;CAAA;AAEY,QAAA,4BAA4B,GAAG;IAC1C,OAAO;CACR,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import OpenAI from "openai";
|
|
3
|
-
import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
4
|
-
export declare
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import type OpenAI from "openai";
|
|
3
|
+
import type { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
4
|
+
export declare function decode<Model extends ILlmSchema.Model>(history: AgenticaPrompt<Model>): OpenAI.ChatCompletionMessageParam[];
|
|
5
|
+
export declare const ChatGptHistoryDecoder: {
|
|
6
|
+
decode: typeof decode;
|
|
7
|
+
};
|
|
@@ -1,45 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ChatGptHistoryDecoder = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
{
|
|
20
|
-
role: "assistant",
|
|
21
|
-
tool_calls: [
|
|
22
|
-
{
|
|
23
|
-
type: "function",
|
|
24
|
-
id: history.id,
|
|
25
|
-
function: {
|
|
26
|
-
name: `${history.type}Functions`,
|
|
27
|
-
arguments: JSON.stringify({
|
|
28
|
-
functions: history.selections.map((s) => ({
|
|
29
|
-
name: s.operation.function.name,
|
|
30
|
-
reason: s.reason,
|
|
31
|
-
})),
|
|
32
|
-
}),
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
role: "tool",
|
|
39
|
-
tool_call_id: history.id,
|
|
40
|
-
content: "",
|
|
41
|
-
},
|
|
42
|
-
];
|
|
4
|
+
exports.decode = decode;
|
|
5
|
+
function decode(history) {
|
|
6
|
+
// NO NEED TO DECODE DESCRIBE
|
|
7
|
+
if (history.type === "describe") {
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
else if (history.type === "text") {
|
|
11
|
+
return [
|
|
12
|
+
{
|
|
13
|
+
role: history.role,
|
|
14
|
+
content: history.text,
|
|
15
|
+
},
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
else if (history.type === "select" || history.type === "cancel") {
|
|
43
19
|
return [
|
|
44
20
|
{
|
|
45
21
|
role: "assistant",
|
|
@@ -48,8 +24,13 @@ var ChatGptHistoryDecoder;
|
|
|
48
24
|
type: "function",
|
|
49
25
|
id: history.id,
|
|
50
26
|
function: {
|
|
51
|
-
name: history.
|
|
52
|
-
arguments: JSON.stringify(
|
|
27
|
+
name: `${history.type}Functions`,
|
|
28
|
+
arguments: JSON.stringify({
|
|
29
|
+
functions: history.selections.map(s => ({
|
|
30
|
+
name: s.operation.function.name,
|
|
31
|
+
reason: s.reason,
|
|
32
|
+
})),
|
|
33
|
+
}),
|
|
53
34
|
},
|
|
54
35
|
},
|
|
55
36
|
],
|
|
@@ -57,21 +38,44 @@ var ChatGptHistoryDecoder;
|
|
|
57
38
|
{
|
|
58
39
|
role: "tool",
|
|
59
40
|
tool_call_id: history.id,
|
|
60
|
-
content:
|
|
61
|
-
? {
|
|
62
|
-
method: history.operation.function.method,
|
|
63
|
-
path: history.operation.function.path,
|
|
64
|
-
}
|
|
65
|
-
: {})) }, (history.operation.protocol === "http"
|
|
66
|
-
? {
|
|
67
|
-
status: history.value.status,
|
|
68
|
-
data: history.value.body,
|
|
69
|
-
}
|
|
70
|
-
: {
|
|
71
|
-
value: history.value,
|
|
72
|
-
}))),
|
|
41
|
+
content: "",
|
|
73
42
|
},
|
|
74
43
|
];
|
|
75
|
-
}
|
|
76
|
-
|
|
44
|
+
}
|
|
45
|
+
return [
|
|
46
|
+
{
|
|
47
|
+
role: "assistant",
|
|
48
|
+
tool_calls: [
|
|
49
|
+
{
|
|
50
|
+
type: "function",
|
|
51
|
+
id: history.id,
|
|
52
|
+
function: {
|
|
53
|
+
name: history.operation.name,
|
|
54
|
+
arguments: JSON.stringify(history.arguments),
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
role: "tool",
|
|
61
|
+
tool_call_id: history.id,
|
|
62
|
+
content: JSON.stringify(Object.assign({ function: Object.assign({ protocol: history.operation.protocol, description: history.operation.function.description, parameters: history.operation.function.parameters, output: history.operation.function.output }, (history.operation.protocol === "http"
|
|
63
|
+
? {
|
|
64
|
+
method: history.operation.function.method,
|
|
65
|
+
path: history.operation.function.path,
|
|
66
|
+
}
|
|
67
|
+
: {})) }, (history.operation.protocol === "http"
|
|
68
|
+
? {
|
|
69
|
+
status: history.value.status,
|
|
70
|
+
data: history.value.body,
|
|
71
|
+
}
|
|
72
|
+
: {
|
|
73
|
+
value: history.value,
|
|
74
|
+
}))),
|
|
75
|
+
},
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
exports.ChatGptHistoryDecoder = {
|
|
79
|
+
decode,
|
|
80
|
+
};
|
|
77
81
|
//# sourceMappingURL=ChatGptHistoryDecoder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatGptHistoryDecoder.js","sourceRoot":"","sources":["../../src/chatgpt/ChatGptHistoryDecoder.ts"],"names":[],"mappings":";;;AAKA,
|
|
1
|
+
{"version":3,"file":"ChatGptHistoryDecoder.js","sourceRoot":"","sources":["../../src/chatgpt/ChatGptHistoryDecoder.ts"],"names":[],"mappings":";;;AAKA,wBAkFC;AAlFD,SAAgB,MAAM,CAAiC,OAA8B;IACnF,6BAA6B;IAC7B,IAAI,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QAChC,OAAO,EAAE,CAAC;IACZ,CAAC;SACI,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACjC,OAAO;YACL;gBACE,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,OAAO,EAAE,OAAO,CAAC,IAAI;aACtB;SACF,CAAC;IACJ,CAAC;SACI,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAChE,OAAO;YACL;gBACE,IAAI,E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,CAAC,QAAQ,KAAK,MAAM;oBACvC,CAAC,CAAC;wBACE,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM;wBACzC,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI;qBACtC;oBACH,CAAC,CAAC,EAAE,CAAC,KAEN,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,KAAK,MAAM;gBACvC,CAAC,CAAC;oBACE,MAAM,EAAG,OAAO,CAAC,KAAuB,CAAC,MAAM;oBAC/C,IAAI,EAAG,OAAO,CAAC,KAAuB,CAAC,IAAI;iBAC5C;gBACH,CAAC,CAAC;oBACE,KAAK,EAAE,OAAO,CAAC,KAAK;iBACrB,CAAC,EACN;SACH;KACF,CAAC;AACJ,CAAC;AAEY,QAAA,qBAAqB,GAAG;IACnC,MAAM;CACP,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import { AgenticaContext } from "../context/AgenticaContext";
|
|
3
|
-
import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
4
|
-
export declare
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import type { AgenticaContext } from "../context/AgenticaContext";
|
|
3
|
+
import type { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
4
|
+
export declare function execute<Model extends ILlmSchema.Model>(ctx: AgenticaContext<Model>): Promise<AgenticaPrompt<Model>[]>;
|
|
5
|
+
export declare const ChatGptInitializeFunctionAgent: {
|
|
6
|
+
execute: typeof execute;
|
|
7
|
+
};
|
|
@@ -46,129 +46,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
46
46
|
};
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
48
|
exports.ChatGptInitializeFunctionAgent = void 0;
|
|
49
|
+
exports.execute = execute;
|
|
49
50
|
const __typia_transform__validateReport = __importStar(require("typia/lib/internal/_validateReport.js"));
|
|
50
51
|
const typia_1 = __importDefault(require("typia"));
|
|
51
52
|
const AgenticaTextEvent_1 = require("../events/AgenticaTextEvent");
|
|
52
53
|
const AgenticaDefaultPrompt_1 = require("../internal/AgenticaDefaultPrompt");
|
|
53
54
|
const AgenticaSystemPrompt_1 = require("../internal/AgenticaSystemPrompt");
|
|
54
|
-
const
|
|
55
|
+
const MPSC_1 = require("../internal/MPSC");
|
|
55
56
|
const StreamUtil_1 = require("../internal/StreamUtil");
|
|
56
57
|
const AgenticaTextPrompt_1 = require("../prompts/AgenticaTextPrompt");
|
|
57
58
|
const ChatGptCompletionMessageUtil_1 = require("./ChatGptCompletionMessageUtil");
|
|
58
59
|
const ChatGptHistoryDecoder_1 = require("./ChatGptHistoryDecoder");
|
|
59
|
-
var ChatGptInitializeFunctionAgent;
|
|
60
|
-
(function (ChatGptInitializeFunctionAgent) {
|
|
61
|
-
ChatGptInitializeFunctionAgent.execute = (ctx) => __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
var _a, _b, _c, _d, _e;
|
|
63
|
-
//----
|
|
64
|
-
// EXECUTE CHATGPT API
|
|
65
|
-
//----
|
|
66
|
-
const completionStream = yield ctx.request("initialize", {
|
|
67
|
-
messages: [
|
|
68
|
-
// COMMON SYSTEM PROMPT
|
|
69
|
-
{
|
|
70
|
-
role: "system",
|
|
71
|
-
content: AgenticaDefaultPrompt_1.AgenticaDefaultPrompt.write(ctx.config),
|
|
72
|
-
},
|
|
73
|
-
// PREVIOUS HISTORIES
|
|
74
|
-
...ctx.histories.map(ChatGptHistoryDecoder_1.ChatGptHistoryDecoder.decode).flat(),
|
|
75
|
-
// USER INPUT
|
|
76
|
-
{
|
|
77
|
-
role: "user",
|
|
78
|
-
content: ctx.prompt.text,
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
// SYSTEM PROMPT
|
|
82
|
-
role: "system",
|
|
83
|
-
content: (_d = (_c = (_b = (_a = ctx.config) === null || _a === void 0 ? void 0 : _a.systemPrompt) === null || _b === void 0 ? void 0 : _b.initialize) === null || _c === void 0 ? void 0 : _c.call(_b, ctx.histories)) !== null && _d !== void 0 ? _d : AgenticaSystemPrompt_1.AgenticaSystemPrompt.INITIALIZE,
|
|
84
|
-
},
|
|
85
|
-
],
|
|
86
|
-
// GETTER FUNCTION
|
|
87
|
-
tools: [
|
|
88
|
-
{
|
|
89
|
-
type: "function",
|
|
90
|
-
function: {
|
|
91
|
-
name: FUNCTION.name,
|
|
92
|
-
description: FUNCTION.description,
|
|
93
|
-
parameters: FUNCTION.parameters,
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
],
|
|
97
|
-
tool_choice: "auto",
|
|
98
|
-
parallel_tool_calls: false,
|
|
99
|
-
});
|
|
100
|
-
const textContext = [];
|
|
101
|
-
const completion = yield StreamUtil_1.StreamUtil.reduce(completionStream, (accPromise, chunk) => __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
const acc = yield accPromise;
|
|
103
|
-
const registerContext = (choices) => {
|
|
104
|
-
var _a;
|
|
105
|
-
for (const choice of choices) {
|
|
106
|
-
if (choice.finish_reason) {
|
|
107
|
-
(_a = textContext[choice.index]) === null || _a === void 0 ? void 0 : _a.close();
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
if (!choice.delta.content) {
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
if (textContext[choice.index]) {
|
|
114
|
-
textContext[choice.index].content += choice.delta.content;
|
|
115
|
-
textContext[choice.index].produce(choice.delta.content);
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
const { consumer, produce, close, waitClosed, waitUntilEmpty, done } = MPSCUtil_1.MPSCUtil.create();
|
|
119
|
-
textContext[choice.index] = {
|
|
120
|
-
content: choice.delta.content,
|
|
121
|
-
consumer,
|
|
122
|
-
produce,
|
|
123
|
-
close,
|
|
124
|
-
waitClosed,
|
|
125
|
-
waitUntilEmpty,
|
|
126
|
-
done,
|
|
127
|
-
};
|
|
128
|
-
produce(choice.delta.content);
|
|
129
|
-
void ctx.dispatch(new AgenticaTextEvent_1.AgenticaTextEvent({
|
|
130
|
-
role: "assistant",
|
|
131
|
-
stream: consumer,
|
|
132
|
-
done,
|
|
133
|
-
get: () => { var _a, _b; return (_b = (_a = textContext[choice.index]) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : ""; },
|
|
134
|
-
join: () => __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
yield waitClosed();
|
|
136
|
-
return textContext[choice.index].content;
|
|
137
|
-
}),
|
|
138
|
-
}));
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
if (acc.object === "chat.completion.chunk") {
|
|
142
|
-
registerContext([acc, chunk].flatMap((v) => v.choices));
|
|
143
|
-
return ChatGptCompletionMessageUtil_1.ChatGptCompletionMessageUtil.merge([acc, chunk]);
|
|
144
|
-
}
|
|
145
|
-
registerContext(chunk.choices);
|
|
146
|
-
return ChatGptCompletionMessageUtil_1.ChatGptCompletionMessageUtil.accumulate(acc, chunk);
|
|
147
|
-
}));
|
|
148
|
-
if (!completion) {
|
|
149
|
-
throw new Error("No completion received");
|
|
150
|
-
}
|
|
151
|
-
//----
|
|
152
|
-
// PROCESS COMPLETION
|
|
153
|
-
//----
|
|
154
|
-
const prompts = [];
|
|
155
|
-
for (const choice of completion.choices) {
|
|
156
|
-
if (choice.message.role === "assistant" &&
|
|
157
|
-
!!((_e = choice.message.content) === null || _e === void 0 ? void 0 : _e.length)) {
|
|
158
|
-
prompts.push(new AgenticaTextPrompt_1.AgenticaTextPrompt({
|
|
159
|
-
role: "assistant",
|
|
160
|
-
text: choice.message.content,
|
|
161
|
-
}));
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
if (completion.choices.some((c) => {
|
|
165
|
-
var _a;
|
|
166
|
-
return !!((_a = c.message.tool_calls) === null || _a === void 0 ? void 0 : _a.some((tc) => tc.type === "function" && tc.function.name === FUNCTION.name));
|
|
167
|
-
}))
|
|
168
|
-
yield ctx.initialize();
|
|
169
|
-
return prompts;
|
|
170
|
-
});
|
|
171
|
-
})(ChatGptInitializeFunctionAgent || (exports.ChatGptInitializeFunctionAgent = ChatGptInitializeFunctionAgent = {}));
|
|
172
60
|
const FUNCTION = {
|
|
173
61
|
model: "chatgpt",
|
|
174
62
|
options: {
|
|
@@ -1973,11 +1861,11 @@ const FUNCTION = {
|
|
|
1973
1861
|
_report = __typia_transform__validateReport._validateReport(errors);
|
|
1974
1862
|
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input && false === Array.isArray(input) || _report(true, {
|
|
1975
1863
|
path: _path + "",
|
|
1976
|
-
expected: "
|
|
1864
|
+
expected: "object",
|
|
1977
1865
|
value: input
|
|
1978
1866
|
})) && _vo0(input, _path + "", true) || _report(true, {
|
|
1979
1867
|
path: _path + "",
|
|
1980
|
-
expected: "
|
|
1868
|
+
expected: "object",
|
|
1981
1869
|
value: input
|
|
1982
1870
|
}))(input, "$input", true);
|
|
1983
1871
|
const success = 0 === errors.length;
|
|
@@ -1998,4 +1886,121 @@ const FUNCTION = {
|
|
|
1998
1886
|
}
|
|
1999
1887
|
]
|
|
2000
1888
|
}.functions[0];
|
|
1889
|
+
function execute(ctx) {
|
|
1890
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1891
|
+
var _a, _b, _c, _d;
|
|
1892
|
+
// ----
|
|
1893
|
+
// EXECUTE CHATGPT API
|
|
1894
|
+
// ----
|
|
1895
|
+
const completionStream = yield ctx.request("initialize", {
|
|
1896
|
+
messages: [
|
|
1897
|
+
// COMMON SYSTEM PROMPT
|
|
1898
|
+
{
|
|
1899
|
+
role: "system",
|
|
1900
|
+
content: AgenticaDefaultPrompt_1.AgenticaDefaultPrompt.write(ctx.config),
|
|
1901
|
+
},
|
|
1902
|
+
// PREVIOUS HISTORIES
|
|
1903
|
+
...ctx.histories.map(ChatGptHistoryDecoder_1.ChatGptHistoryDecoder.decode).flat(),
|
|
1904
|
+
// USER INPUT
|
|
1905
|
+
{
|
|
1906
|
+
role: "user",
|
|
1907
|
+
content: ctx.prompt.text,
|
|
1908
|
+
},
|
|
1909
|
+
{
|
|
1910
|
+
// SYSTEM PROMPT
|
|
1911
|
+
role: "system",
|
|
1912
|
+
content: (_d = (_c = (_b = (_a = ctx.config) === null || _a === void 0 ? void 0 : _a.systemPrompt) === null || _b === void 0 ? void 0 : _b.initialize) === null || _c === void 0 ? void 0 : _c.call(_b, ctx.histories)) !== null && _d !== void 0 ? _d : AgenticaSystemPrompt_1.AgenticaSystemPrompt.INITIALIZE,
|
|
1913
|
+
},
|
|
1914
|
+
],
|
|
1915
|
+
// GETTER FUNCTION
|
|
1916
|
+
tools: [
|
|
1917
|
+
{
|
|
1918
|
+
type: "function",
|
|
1919
|
+
function: {
|
|
1920
|
+
name: FUNCTION.name,
|
|
1921
|
+
description: FUNCTION.description,
|
|
1922
|
+
/**
|
|
1923
|
+
* @TODO fix it
|
|
1924
|
+
* The property and value have a type mismatch, but it works.
|
|
1925
|
+
*/
|
|
1926
|
+
parameters: FUNCTION.parameters,
|
|
1927
|
+
},
|
|
1928
|
+
},
|
|
1929
|
+
],
|
|
1930
|
+
tool_choice: "auto",
|
|
1931
|
+
parallel_tool_calls: false,
|
|
1932
|
+
});
|
|
1933
|
+
const textContext = [];
|
|
1934
|
+
const completion = yield StreamUtil_1.StreamUtil.reduce(completionStream, (accPromise, chunk) => __awaiter(this, void 0, void 0, function* () {
|
|
1935
|
+
const acc = yield accPromise;
|
|
1936
|
+
const registerContext = (choices) => {
|
|
1937
|
+
var _a;
|
|
1938
|
+
for (const choice of choices) {
|
|
1939
|
+
/**
|
|
1940
|
+
* @TODO fix it
|
|
1941
|
+
* Sometimes, the complete message arrives along with a finish reason.
|
|
1942
|
+
*/
|
|
1943
|
+
if (choice.finish_reason != null) {
|
|
1944
|
+
(_a = textContext[choice.index]) === null || _a === void 0 ? void 0 : _a.mpsc.close();
|
|
1945
|
+
continue;
|
|
1946
|
+
}
|
|
1947
|
+
if (choice.delta.content == null) {
|
|
1948
|
+
continue;
|
|
1949
|
+
}
|
|
1950
|
+
if (textContext[choice.index] != null) {
|
|
1951
|
+
textContext[choice.index].content += choice.delta.content;
|
|
1952
|
+
textContext[choice.index].mpsc.produce(choice.delta.content);
|
|
1953
|
+
continue;
|
|
1954
|
+
}
|
|
1955
|
+
const mpsc = new MPSC_1.MPSC();
|
|
1956
|
+
textContext[choice.index] = {
|
|
1957
|
+
content: choice.delta.content,
|
|
1958
|
+
mpsc,
|
|
1959
|
+
};
|
|
1960
|
+
mpsc.produce(choice.delta.content);
|
|
1961
|
+
void ctx.dispatch(new AgenticaTextEvent_1.AgenticaTextEvent({
|
|
1962
|
+
role: "assistant",
|
|
1963
|
+
stream: mpsc.consumer,
|
|
1964
|
+
done: () => mpsc.done(),
|
|
1965
|
+
get: () => textContext[choice.index].content,
|
|
1966
|
+
join: () => __awaiter(this, void 0, void 0, function* () {
|
|
1967
|
+
yield mpsc.waitClosed();
|
|
1968
|
+
return textContext[choice.index].content;
|
|
1969
|
+
}),
|
|
1970
|
+
}));
|
|
1971
|
+
}
|
|
1972
|
+
};
|
|
1973
|
+
if (acc.object === "chat.completion.chunk") {
|
|
1974
|
+
registerContext([acc, chunk].flatMap(v => v.choices));
|
|
1975
|
+
return ChatGptCompletionMessageUtil_1.ChatGptCompletionMessageUtil.merge([acc, chunk]);
|
|
1976
|
+
}
|
|
1977
|
+
registerContext(chunk.choices);
|
|
1978
|
+
return ChatGptCompletionMessageUtil_1.ChatGptCompletionMessageUtil.accumulate(acc, chunk);
|
|
1979
|
+
}));
|
|
1980
|
+
if (completion === null) {
|
|
1981
|
+
throw new Error("No completion received");
|
|
1982
|
+
}
|
|
1983
|
+
// ----
|
|
1984
|
+
// PROCESS COMPLETION
|
|
1985
|
+
// ----
|
|
1986
|
+
const prompts = [];
|
|
1987
|
+
for (const choice of completion.choices) {
|
|
1988
|
+
if (choice.message.role === "assistant"
|
|
1989
|
+
&& choice.message.content != null) {
|
|
1990
|
+
prompts.push(new AgenticaTextPrompt_1.AgenticaTextPrompt({
|
|
1991
|
+
role: "assistant",
|
|
1992
|
+
text: choice.message.content,
|
|
1993
|
+
}));
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
if (completion.choices.some(c => c.message.tool_calls != null
|
|
1997
|
+
&& c.message.tool_calls.some(tc => tc.type === "function" && tc.function.name === FUNCTION.name))) {
|
|
1998
|
+
yield ctx.initialize();
|
|
1999
|
+
}
|
|
2000
|
+
return prompts;
|
|
2001
|
+
});
|
|
2002
|
+
}
|
|
2003
|
+
exports.ChatGptInitializeFunctionAgent = {
|
|
2004
|
+
execute,
|
|
2005
|
+
};
|
|
2001
2006
|
//# sourceMappingURL=ChatGptInitializeFunctionAgent.js.map
|