@agentica/core 0.12.20 → 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,28 +1,30 @@
|
|
|
1
|
-
import { ILlmFunction, ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import OpenAI from "openai";
|
|
3
|
-
import
|
|
1
|
+
import type { ILlmFunction, ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import type OpenAI from "openai";
|
|
3
|
+
import type { AgenticaContext } from "../context/AgenticaContext";
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import type { __IChatInitialApplication } from "../context/internal/__IChatInitialApplication";
|
|
6
|
+
import type { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
7
|
+
import typia from "typia";
|
|
7
8
|
import { AgenticaTextEvent } from "../events/AgenticaTextEvent";
|
|
8
9
|
import { AgenticaDefaultPrompt } from "../internal/AgenticaDefaultPrompt";
|
|
9
10
|
import { AgenticaSystemPrompt } from "../internal/AgenticaSystemPrompt";
|
|
10
|
-
import {
|
|
11
|
+
import { MPSC } from "../internal/MPSC";
|
|
11
12
|
import { StreamUtil } from "../internal/StreamUtil";
|
|
12
|
-
import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
13
13
|
import { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
|
|
14
14
|
import { ChatGptCompletionMessageUtil } from "./ChatGptCompletionMessageUtil";
|
|
15
15
|
import { ChatGptHistoryDecoder } from "./ChatGptHistoryDecoder";
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
const FUNCTION: ILlmFunction<"chatgpt"> = typia.llm.application<
|
|
18
|
+
__IChatInitialApplication,
|
|
19
|
+
"chatgpt"
|
|
20
|
+
>().functions[0]!;
|
|
21
|
+
|
|
22
|
+
export async function execute<Model extends ILlmSchema.Model>(ctx: AgenticaContext<Model>): Promise<AgenticaPrompt<Model>[]> {
|
|
23
|
+
// ----
|
|
24
|
+
// EXECUTE CHATGPT API
|
|
25
|
+
// ----
|
|
26
|
+
const completionStream = await ctx.request("initialize", {
|
|
27
|
+
messages: [
|
|
26
28
|
// COMMON SYSTEM PROMPT
|
|
27
29
|
{
|
|
28
30
|
role: "system",
|
|
@@ -39,126 +41,129 @@ export namespace ChatGptInitializeFunctionAgent {
|
|
|
39
41
|
// SYSTEM PROMPT
|
|
40
42
|
role: "system",
|
|
41
43
|
content:
|
|
42
|
-
ctx.config?.systemPrompt?.initialize?.(ctx.histories)
|
|
43
|
-
AgenticaSystemPrompt.INITIALIZE,
|
|
44
|
+
ctx.config?.systemPrompt?.initialize?.(ctx.histories)
|
|
45
|
+
?? AgenticaSystemPrompt.INITIALIZE,
|
|
44
46
|
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
],
|
|
48
|
+
// GETTER FUNCTION
|
|
49
|
+
tools: [
|
|
50
|
+
{
|
|
51
|
+
type: "function",
|
|
52
|
+
function: {
|
|
53
|
+
name: FUNCTION.name,
|
|
54
|
+
description: FUNCTION.description,
|
|
55
|
+
/**
|
|
56
|
+
* @TODO fix it
|
|
57
|
+
* The property and value have a type mismatch, but it works.
|
|
58
|
+
*/
|
|
59
|
+
parameters: FUNCTION.parameters as unknown as Record<string, unknown>,
|
|
55
60
|
},
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
textContext[choice.index]!.content += choice.delta.content;
|
|
84
|
-
textContext[choice.index]!.produce(choice.delta.content);
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const { consumer, produce, close, waitClosed, waitUntilEmpty, done } =
|
|
89
|
-
MPSCUtil.create<string>();
|
|
90
|
-
|
|
91
|
-
textContext[choice.index] = {
|
|
92
|
-
content: choice.delta.content,
|
|
93
|
-
consumer,
|
|
94
|
-
produce,
|
|
95
|
-
close,
|
|
96
|
-
waitClosed,
|
|
97
|
-
waitUntilEmpty,
|
|
98
|
-
done,
|
|
99
|
-
};
|
|
100
|
-
produce(choice.delta.content);
|
|
101
|
-
|
|
102
|
-
void ctx.dispatch(
|
|
103
|
-
new AgenticaTextEvent({
|
|
104
|
-
role: "assistant",
|
|
105
|
-
stream: consumer,
|
|
106
|
-
done,
|
|
107
|
-
get: () => textContext[choice.index]?.content ?? "",
|
|
108
|
-
join: async () => {
|
|
109
|
-
await waitClosed();
|
|
110
|
-
return textContext[choice.index]!.content;
|
|
111
|
-
},
|
|
112
|
-
}),
|
|
113
|
-
);
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
tool_choice: "auto",
|
|
64
|
+
parallel_tool_calls: false,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const textContext: ({
|
|
68
|
+
content: string;
|
|
69
|
+
mpsc: MPSC<string>;
|
|
70
|
+
})[] = [];
|
|
71
|
+
|
|
72
|
+
const completion = await StreamUtil.reduce<
|
|
73
|
+
OpenAI.ChatCompletionChunk,
|
|
74
|
+
Promise<OpenAI.ChatCompletion>
|
|
75
|
+
>(completionStream, async (accPromise, chunk) => {
|
|
76
|
+
const acc = await accPromise;
|
|
77
|
+
const registerContext = (
|
|
78
|
+
choices: OpenAI.ChatCompletionChunk.Choice[],
|
|
79
|
+
) => {
|
|
80
|
+
for (const choice of choices) {
|
|
81
|
+
/**
|
|
82
|
+
* @TODO fix it
|
|
83
|
+
* Sometimes, the complete message arrives along with a finish reason.
|
|
84
|
+
*/
|
|
85
|
+
if (choice.finish_reason != null) {
|
|
86
|
+
textContext[choice.index]?.mpsc.close();
|
|
87
|
+
continue;
|
|
114
88
|
}
|
|
115
|
-
};
|
|
116
89
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
90
|
+
if (choice.delta.content == null) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
121
93
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
94
|
+
if (textContext[choice.index] != null) {
|
|
95
|
+
textContext[choice.index]!.content += choice.delta.content;
|
|
96
|
+
textContext[choice.index]!.mpsc.produce(choice.delta.content);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
125
99
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
100
|
+
const mpsc = new MPSC<string>();
|
|
101
|
+
|
|
102
|
+
textContext[choice.index] = {
|
|
103
|
+
content: choice.delta.content,
|
|
104
|
+
mpsc,
|
|
105
|
+
};
|
|
106
|
+
mpsc.produce(choice.delta.content);
|
|
129
107
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
//----
|
|
133
|
-
const prompts: AgenticaPrompt<Model>[] = [];
|
|
134
|
-
for (const choice of completion.choices) {
|
|
135
|
-
if (
|
|
136
|
-
choice.message.role === "assistant" &&
|
|
137
|
-
!!choice.message.content?.length
|
|
138
|
-
) {
|
|
139
|
-
prompts.push(
|
|
140
|
-
new AgenticaTextPrompt({
|
|
108
|
+
void ctx.dispatch(
|
|
109
|
+
new AgenticaTextEvent({
|
|
141
110
|
role: "assistant",
|
|
142
|
-
|
|
111
|
+
stream: mpsc.consumer,
|
|
112
|
+
done: () => mpsc.done(),
|
|
113
|
+
get: () => textContext[choice.index]!.content,
|
|
114
|
+
join: async () => {
|
|
115
|
+
await mpsc.waitClosed();
|
|
116
|
+
return textContext[choice.index]!.content;
|
|
117
|
+
},
|
|
143
118
|
}),
|
|
144
119
|
);
|
|
145
120
|
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
if (acc.object === "chat.completion.chunk") {
|
|
124
|
+
registerContext([acc, chunk].flatMap(v => v.choices));
|
|
125
|
+
return ChatGptCompletionMessageUtil.merge([acc, chunk]);
|
|
146
126
|
}
|
|
127
|
+
|
|
128
|
+
registerContext(chunk.choices);
|
|
129
|
+
return ChatGptCompletionMessageUtil.accumulate(acc, chunk);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
if (completion === null) {
|
|
133
|
+
throw new Error("No completion received");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ----
|
|
137
|
+
// PROCESS COMPLETION
|
|
138
|
+
// ----
|
|
139
|
+
const prompts: AgenticaPrompt<Model>[] = [];
|
|
140
|
+
for (const choice of completion.choices) {
|
|
147
141
|
if (
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
142
|
+
choice.message.role === "assistant"
|
|
143
|
+
&& choice.message.content != null
|
|
144
|
+
) {
|
|
145
|
+
prompts.push(
|
|
146
|
+
new AgenticaTextPrompt({
|
|
147
|
+
role: "assistant",
|
|
148
|
+
text: choice.message.content,
|
|
149
|
+
}),
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (
|
|
154
|
+
completion.choices.some(
|
|
155
|
+
c =>
|
|
156
|
+
c.message.tool_calls != null
|
|
157
|
+
&& c.message.tool_calls.some(
|
|
158
|
+
tc =>
|
|
159
|
+
tc.type === "function" && tc.function.name === FUNCTION.name,
|
|
160
|
+
),
|
|
155
161
|
)
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
162
|
+
) { await ctx.initialize(); }
|
|
163
|
+
|
|
164
|
+
return prompts;
|
|
159
165
|
}
|
|
160
166
|
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
>().functions[0]!;
|
|
167
|
+
export const ChatGptInitializeFunctionAgent = {
|
|
168
|
+
execute,
|
|
169
|
+
};
|