@agentica/core 0.10.0 → 0.10.1-dev.20250302
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/LICENSE +21 -21
- package/README.md +419 -419
- package/package.json +1 -1
- package/prompts/cancel.md +4 -4
- package/prompts/common.md +2 -2
- package/prompts/describe.md +6 -6
- package/prompts/execute.md +6 -6
- package/prompts/initialize.md +2 -2
- package/prompts/select.md +6 -6
- package/src/Agentica.ts +323 -323
- package/src/chatgpt/ChatGptAgent.ts +75 -75
- package/src/chatgpt/ChatGptCallFunctionAgent.ts +464 -464
- package/src/chatgpt/ChatGptCancelFunctionAgent.ts +287 -287
- package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +52 -52
- package/src/chatgpt/ChatGptHistoryDecoder.ts +88 -88
- package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +88 -88
- package/src/chatgpt/ChatGptSelectFunctionAgent.ts +319 -319
- package/src/functional/createHttpLlmApplication.ts +63 -63
- package/src/index.ts +19 -19
- package/src/internal/AgenticaConstant.ts +4 -4
- package/src/internal/AgenticaDefaultPrompt.ts +43 -43
- package/src/internal/AgenticaOperationComposer.ts +87 -87
- package/src/internal/AgenticaPromptFactory.ts +32 -32
- package/src/internal/AgenticaPromptTransformer.ts +86 -86
- package/src/internal/AgenticaTokenUsageAggregator.ts +115 -115
- package/src/internal/MathUtil.ts +3 -3
- package/src/internal/Singleton.ts +22 -22
- package/src/internal/__map_take.ts +15 -15
- package/src/structures/IAgenticaConfig.ts +123 -123
- package/src/structures/IAgenticaContext.ts +129 -129
- package/src/structures/IAgenticaController.ts +133 -133
- package/src/structures/IAgenticaEvent.ts +229 -229
- package/src/structures/IAgenticaExecutor.ts +156 -156
- package/src/structures/IAgenticaOperation.ts +63 -63
- package/src/structures/IAgenticaOperationCollection.ts +52 -52
- package/src/structures/IAgenticaOperationSelection.ts +68 -68
- package/src/structures/IAgenticaPrompt.ts +182 -182
- package/src/structures/IAgenticaProps.ts +70 -70
- package/src/structures/IAgenticaSystemPrompt.ts +124 -124
- package/src/structures/IAgenticaTokenUsage.ts +107 -107
- package/src/structures/IAgenticaVendor.ts +39 -39
- package/src/structures/internal/__IChatCancelFunctionsApplication.ts +23 -23
- package/src/structures/internal/__IChatFunctionReference.ts +21 -21
- package/src/structures/internal/__IChatInitialApplication.ts +15 -15
- package/src/structures/internal/__IChatSelectFunctionsApplication.ts +24 -24
- package/src/typings/AgenticaSource.ts +6 -6
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import OpenAI from "openai";
|
|
3
|
-
|
|
4
|
-
import { AgenticaDefaultPrompt } from "../internal/AgenticaDefaultPrompt";
|
|
5
|
-
import { AgenticaSystemPrompt } from "../internal/AgenticaSystemPrompt";
|
|
6
|
-
import { IAgenticaContext } from "../structures/IAgenticaContext";
|
|
7
|
-
import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
|
|
8
|
-
import { ChatGptHistoryDecoder } from "./ChatGptHistoryDecoder";
|
|
9
|
-
|
|
10
|
-
export namespace ChatGptDescribeFunctionAgent {
|
|
11
|
-
export const execute = async <Model extends ILlmSchema.Model>(
|
|
12
|
-
ctx: IAgenticaContext<Model>,
|
|
13
|
-
histories: IAgenticaPrompt.IExecute<Model>[],
|
|
14
|
-
): Promise<IAgenticaPrompt.IDescribe<Model>[]> => {
|
|
15
|
-
if (histories.length === 0) return [];
|
|
16
|
-
const completion: OpenAI.ChatCompletion = await ctx.request("describe", {
|
|
17
|
-
messages: [
|
|
18
|
-
// COMMON SYSTEM PROMPT
|
|
19
|
-
{
|
|
20
|
-
role: "system",
|
|
21
|
-
content: AgenticaDefaultPrompt.write(ctx.config),
|
|
22
|
-
} satisfies OpenAI.ChatCompletionSystemMessageParam,
|
|
23
|
-
// FUNCTION CALLING HISTORIES
|
|
24
|
-
...histories.map(ChatGptHistoryDecoder.decode).flat(),
|
|
25
|
-
// SYSTEM PROMPT
|
|
26
|
-
{
|
|
27
|
-
role: "system",
|
|
28
|
-
content:
|
|
29
|
-
ctx.config?.systemPrompt?.describe?.(histories) ??
|
|
30
|
-
AgenticaSystemPrompt.DESCRIBE,
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
});
|
|
34
|
-
const descriptions: IAgenticaPrompt.IDescribe<Model>[] = completion.choices
|
|
35
|
-
.map((choice) =>
|
|
36
|
-
choice.message.role === "assistant" && !!choice.message.content?.length
|
|
37
|
-
? choice.message.content
|
|
38
|
-
: null,
|
|
39
|
-
)
|
|
40
|
-
.filter((str) => str !== null)
|
|
41
|
-
.map(
|
|
42
|
-
(content) =>
|
|
43
|
-
({
|
|
44
|
-
type: "describe",
|
|
45
|
-
executions: histories,
|
|
46
|
-
text: content,
|
|
47
|
-
}) satisfies IAgenticaPrompt.IDescribe<Model>,
|
|
48
|
-
);
|
|
49
|
-
for (const describe of descriptions) await ctx.dispatch(describe);
|
|
50
|
-
return descriptions;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import OpenAI from "openai";
|
|
3
|
+
|
|
4
|
+
import { AgenticaDefaultPrompt } from "../internal/AgenticaDefaultPrompt";
|
|
5
|
+
import { AgenticaSystemPrompt } from "../internal/AgenticaSystemPrompt";
|
|
6
|
+
import { IAgenticaContext } from "../structures/IAgenticaContext";
|
|
7
|
+
import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
|
|
8
|
+
import { ChatGptHistoryDecoder } from "./ChatGptHistoryDecoder";
|
|
9
|
+
|
|
10
|
+
export namespace ChatGptDescribeFunctionAgent {
|
|
11
|
+
export const execute = async <Model extends ILlmSchema.Model>(
|
|
12
|
+
ctx: IAgenticaContext<Model>,
|
|
13
|
+
histories: IAgenticaPrompt.IExecute<Model>[],
|
|
14
|
+
): Promise<IAgenticaPrompt.IDescribe<Model>[]> => {
|
|
15
|
+
if (histories.length === 0) return [];
|
|
16
|
+
const completion: OpenAI.ChatCompletion = await ctx.request("describe", {
|
|
17
|
+
messages: [
|
|
18
|
+
// COMMON SYSTEM PROMPT
|
|
19
|
+
{
|
|
20
|
+
role: "system",
|
|
21
|
+
content: AgenticaDefaultPrompt.write(ctx.config),
|
|
22
|
+
} satisfies OpenAI.ChatCompletionSystemMessageParam,
|
|
23
|
+
// FUNCTION CALLING HISTORIES
|
|
24
|
+
...histories.map(ChatGptHistoryDecoder.decode).flat(),
|
|
25
|
+
// SYSTEM PROMPT
|
|
26
|
+
{
|
|
27
|
+
role: "system",
|
|
28
|
+
content:
|
|
29
|
+
ctx.config?.systemPrompt?.describe?.(histories) ??
|
|
30
|
+
AgenticaSystemPrompt.DESCRIBE,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
const descriptions: IAgenticaPrompt.IDescribe<Model>[] = completion.choices
|
|
35
|
+
.map((choice) =>
|
|
36
|
+
choice.message.role === "assistant" && !!choice.message.content?.length
|
|
37
|
+
? choice.message.content
|
|
38
|
+
: null,
|
|
39
|
+
)
|
|
40
|
+
.filter((str) => str !== null)
|
|
41
|
+
.map(
|
|
42
|
+
(content) =>
|
|
43
|
+
({
|
|
44
|
+
type: "describe",
|
|
45
|
+
executions: histories,
|
|
46
|
+
text: content,
|
|
47
|
+
}) satisfies IAgenticaPrompt.IDescribe<Model>,
|
|
48
|
+
);
|
|
49
|
+
for (const describe of descriptions) await ctx.dispatch(describe);
|
|
50
|
+
return descriptions;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import OpenAI from "openai";
|
|
3
|
-
|
|
4
|
-
import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
|
|
5
|
-
|
|
6
|
-
export namespace ChatGptHistoryDecoder {
|
|
7
|
-
export const decode = <Model extends ILlmSchema.Model>(
|
|
8
|
-
history: IAgenticaPrompt<Model>,
|
|
9
|
-
): OpenAI.ChatCompletionMessageParam[] => {
|
|
10
|
-
// NO NEED TO DECODE DESCRIBE
|
|
11
|
-
if (history.type === "describe") return [];
|
|
12
|
-
else if (history.type === "text")
|
|
13
|
-
return [
|
|
14
|
-
{
|
|
15
|
-
role: history.role,
|
|
16
|
-
content: history.text,
|
|
17
|
-
},
|
|
18
|
-
];
|
|
19
|
-
else if (history.type === "select" || history.type === "cancel")
|
|
20
|
-
return [
|
|
21
|
-
{
|
|
22
|
-
role: "assistant",
|
|
23
|
-
tool_calls: [
|
|
24
|
-
{
|
|
25
|
-
type: "function",
|
|
26
|
-
id: history.id,
|
|
27
|
-
function: {
|
|
28
|
-
name: `${history.type}Functions`,
|
|
29
|
-
arguments: JSON.stringify({
|
|
30
|
-
functions: history.operations.map((t) => ({
|
|
31
|
-
name: t.function.name,
|
|
32
|
-
reason: t.reason,
|
|
33
|
-
})),
|
|
34
|
-
}),
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
role: "tool",
|
|
41
|
-
tool_call_id: history.id,
|
|
42
|
-
content: "",
|
|
43
|
-
},
|
|
44
|
-
];
|
|
45
|
-
|
|
46
|
-
return [
|
|
47
|
-
{
|
|
48
|
-
role: "assistant",
|
|
49
|
-
tool_calls: [
|
|
50
|
-
{
|
|
51
|
-
type: "function",
|
|
52
|
-
id: history.id,
|
|
53
|
-
function: {
|
|
54
|
-
name: history.function.name,
|
|
55
|
-
arguments: JSON.stringify(history.arguments),
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
role: "tool",
|
|
62
|
-
tool_call_id: history.id,
|
|
63
|
-
content: JSON.stringify({
|
|
64
|
-
function: {
|
|
65
|
-
protocol: history.protocol,
|
|
66
|
-
description: history.function.description,
|
|
67
|
-
parameters: history.function.parameters,
|
|
68
|
-
output: history.function.output,
|
|
69
|
-
...(history.protocol === "http"
|
|
70
|
-
? {
|
|
71
|
-
method: history.function.method,
|
|
72
|
-
path: history.function.path,
|
|
73
|
-
}
|
|
74
|
-
: {}),
|
|
75
|
-
},
|
|
76
|
-
...(history.protocol === "http"
|
|
77
|
-
? {
|
|
78
|
-
status: history.value.status,
|
|
79
|
-
data: history.value.body,
|
|
80
|
-
}
|
|
81
|
-
: {
|
|
82
|
-
value: history.value,
|
|
83
|
-
}),
|
|
84
|
-
}),
|
|
85
|
-
},
|
|
86
|
-
];
|
|
87
|
-
};
|
|
88
|
-
}
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import OpenAI from "openai";
|
|
3
|
+
|
|
4
|
+
import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
|
|
5
|
+
|
|
6
|
+
export namespace ChatGptHistoryDecoder {
|
|
7
|
+
export const decode = <Model extends ILlmSchema.Model>(
|
|
8
|
+
history: IAgenticaPrompt<Model>,
|
|
9
|
+
): OpenAI.ChatCompletionMessageParam[] => {
|
|
10
|
+
// NO NEED TO DECODE DESCRIBE
|
|
11
|
+
if (history.type === "describe") return [];
|
|
12
|
+
else if (history.type === "text")
|
|
13
|
+
return [
|
|
14
|
+
{
|
|
15
|
+
role: history.role,
|
|
16
|
+
content: history.text,
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
else if (history.type === "select" || history.type === "cancel")
|
|
20
|
+
return [
|
|
21
|
+
{
|
|
22
|
+
role: "assistant",
|
|
23
|
+
tool_calls: [
|
|
24
|
+
{
|
|
25
|
+
type: "function",
|
|
26
|
+
id: history.id,
|
|
27
|
+
function: {
|
|
28
|
+
name: `${history.type}Functions`,
|
|
29
|
+
arguments: JSON.stringify({
|
|
30
|
+
functions: history.operations.map((t) => ({
|
|
31
|
+
name: t.function.name,
|
|
32
|
+
reason: t.reason,
|
|
33
|
+
})),
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
role: "tool",
|
|
41
|
+
tool_call_id: history.id,
|
|
42
|
+
content: "",
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
return [
|
|
47
|
+
{
|
|
48
|
+
role: "assistant",
|
|
49
|
+
tool_calls: [
|
|
50
|
+
{
|
|
51
|
+
type: "function",
|
|
52
|
+
id: history.id,
|
|
53
|
+
function: {
|
|
54
|
+
name: history.function.name,
|
|
55
|
+
arguments: JSON.stringify(history.arguments),
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
role: "tool",
|
|
62
|
+
tool_call_id: history.id,
|
|
63
|
+
content: JSON.stringify({
|
|
64
|
+
function: {
|
|
65
|
+
protocol: history.protocol,
|
|
66
|
+
description: history.function.description,
|
|
67
|
+
parameters: history.function.parameters,
|
|
68
|
+
output: history.function.output,
|
|
69
|
+
...(history.protocol === "http"
|
|
70
|
+
? {
|
|
71
|
+
method: history.function.method,
|
|
72
|
+
path: history.function.path,
|
|
73
|
+
}
|
|
74
|
+
: {}),
|
|
75
|
+
},
|
|
76
|
+
...(history.protocol === "http"
|
|
77
|
+
? {
|
|
78
|
+
status: history.value.status,
|
|
79
|
+
data: history.value.body,
|
|
80
|
+
}
|
|
81
|
+
: {
|
|
82
|
+
value: history.value,
|
|
83
|
+
}),
|
|
84
|
+
}),
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import { ILlmFunction, ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import OpenAI from "openai";
|
|
3
|
-
import typia from "typia";
|
|
4
|
-
|
|
5
|
-
import { AgenticaDefaultPrompt } from "../internal/AgenticaDefaultPrompt";
|
|
6
|
-
import { AgenticaSystemPrompt } from "../internal/AgenticaSystemPrompt";
|
|
7
|
-
import { IAgenticaContext } from "../structures/IAgenticaContext";
|
|
8
|
-
import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
|
|
9
|
-
import { __IChatInitialApplication } from "../structures/internal/__IChatInitialApplication";
|
|
10
|
-
import { ChatGptHistoryDecoder } from "./ChatGptHistoryDecoder";
|
|
11
|
-
|
|
12
|
-
export namespace ChatGptInitializeFunctionAgent {
|
|
13
|
-
export const execute = async <Model extends ILlmSchema.Model>(
|
|
14
|
-
ctx: IAgenticaContext<Model>,
|
|
15
|
-
): Promise<IAgenticaPrompt<Model>[]> => {
|
|
16
|
-
//----
|
|
17
|
-
// EXECUTE CHATGPT API
|
|
18
|
-
//----
|
|
19
|
-
const completion: OpenAI.ChatCompletion = await ctx.request("initialize", {
|
|
20
|
-
messages: [
|
|
21
|
-
// COMMON SYSTEM PROMPT
|
|
22
|
-
{
|
|
23
|
-
role: "system",
|
|
24
|
-
content: AgenticaDefaultPrompt.write(ctx.config),
|
|
25
|
-
} satisfies OpenAI.ChatCompletionSystemMessageParam,
|
|
26
|
-
// PREVIOUS HISTORIES
|
|
27
|
-
...ctx.histories.map(ChatGptHistoryDecoder.decode).flat(),
|
|
28
|
-
// USER INPUT
|
|
29
|
-
{
|
|
30
|
-
role: "user",
|
|
31
|
-
content: ctx.prompt.text,
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
// SYSTEM PROMPT
|
|
35
|
-
role: "system",
|
|
36
|
-
content:
|
|
37
|
-
ctx.config?.systemPrompt?.initialize?.(ctx.histories) ??
|
|
38
|
-
AgenticaSystemPrompt.INITIALIZE,
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
// GETTER FUNCTION
|
|
42
|
-
tools: [
|
|
43
|
-
{
|
|
44
|
-
type: "function",
|
|
45
|
-
function: {
|
|
46
|
-
name: FUNCTION.name,
|
|
47
|
-
description: FUNCTION.description,
|
|
48
|
-
parameters: FUNCTION.parameters as any,
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
tool_choice: "auto",
|
|
53
|
-
parallel_tool_calls: false,
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
//----
|
|
57
|
-
// PROCESS COMPLETION
|
|
58
|
-
//----
|
|
59
|
-
const prompts: IAgenticaPrompt<Model>[] = [];
|
|
60
|
-
for (const choice of completion.choices) {
|
|
61
|
-
if (
|
|
62
|
-
choice.message.role === "assistant" &&
|
|
63
|
-
!!choice.message.content?.length
|
|
64
|
-
)
|
|
65
|
-
prompts.push({
|
|
66
|
-
type: "text",
|
|
67
|
-
role: "assistant",
|
|
68
|
-
text: choice.message.content,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
if (
|
|
72
|
-
completion.choices.some(
|
|
73
|
-
(c) =>
|
|
74
|
-
!!c.message.tool_calls?.some(
|
|
75
|
-
(tc) =>
|
|
76
|
-
tc.type === "function" && tc.function.name === FUNCTION.name,
|
|
77
|
-
),
|
|
78
|
-
)
|
|
79
|
-
)
|
|
80
|
-
await ctx.initialize();
|
|
81
|
-
return prompts;
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const FUNCTION: ILlmFunction<"chatgpt"> = typia.llm.application<
|
|
86
|
-
__IChatInitialApplication,
|
|
87
|
-
"chatgpt"
|
|
88
|
-
>().functions[0]!;
|
|
1
|
+
import { ILlmFunction, ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import OpenAI from "openai";
|
|
3
|
+
import typia from "typia";
|
|
4
|
+
|
|
5
|
+
import { AgenticaDefaultPrompt } from "../internal/AgenticaDefaultPrompt";
|
|
6
|
+
import { AgenticaSystemPrompt } from "../internal/AgenticaSystemPrompt";
|
|
7
|
+
import { IAgenticaContext } from "../structures/IAgenticaContext";
|
|
8
|
+
import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
|
|
9
|
+
import { __IChatInitialApplication } from "../structures/internal/__IChatInitialApplication";
|
|
10
|
+
import { ChatGptHistoryDecoder } from "./ChatGptHistoryDecoder";
|
|
11
|
+
|
|
12
|
+
export namespace ChatGptInitializeFunctionAgent {
|
|
13
|
+
export const execute = async <Model extends ILlmSchema.Model>(
|
|
14
|
+
ctx: IAgenticaContext<Model>,
|
|
15
|
+
): Promise<IAgenticaPrompt<Model>[]> => {
|
|
16
|
+
//----
|
|
17
|
+
// EXECUTE CHATGPT API
|
|
18
|
+
//----
|
|
19
|
+
const completion: OpenAI.ChatCompletion = await ctx.request("initialize", {
|
|
20
|
+
messages: [
|
|
21
|
+
// COMMON SYSTEM PROMPT
|
|
22
|
+
{
|
|
23
|
+
role: "system",
|
|
24
|
+
content: AgenticaDefaultPrompt.write(ctx.config),
|
|
25
|
+
} satisfies OpenAI.ChatCompletionSystemMessageParam,
|
|
26
|
+
// PREVIOUS HISTORIES
|
|
27
|
+
...ctx.histories.map(ChatGptHistoryDecoder.decode).flat(),
|
|
28
|
+
// USER INPUT
|
|
29
|
+
{
|
|
30
|
+
role: "user",
|
|
31
|
+
content: ctx.prompt.text,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
// SYSTEM PROMPT
|
|
35
|
+
role: "system",
|
|
36
|
+
content:
|
|
37
|
+
ctx.config?.systemPrompt?.initialize?.(ctx.histories) ??
|
|
38
|
+
AgenticaSystemPrompt.INITIALIZE,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
// GETTER FUNCTION
|
|
42
|
+
tools: [
|
|
43
|
+
{
|
|
44
|
+
type: "function",
|
|
45
|
+
function: {
|
|
46
|
+
name: FUNCTION.name,
|
|
47
|
+
description: FUNCTION.description,
|
|
48
|
+
parameters: FUNCTION.parameters as any,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
tool_choice: "auto",
|
|
53
|
+
parallel_tool_calls: false,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
//----
|
|
57
|
+
// PROCESS COMPLETION
|
|
58
|
+
//----
|
|
59
|
+
const prompts: IAgenticaPrompt<Model>[] = [];
|
|
60
|
+
for (const choice of completion.choices) {
|
|
61
|
+
if (
|
|
62
|
+
choice.message.role === "assistant" &&
|
|
63
|
+
!!choice.message.content?.length
|
|
64
|
+
)
|
|
65
|
+
prompts.push({
|
|
66
|
+
type: "text",
|
|
67
|
+
role: "assistant",
|
|
68
|
+
text: choice.message.content,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (
|
|
72
|
+
completion.choices.some(
|
|
73
|
+
(c) =>
|
|
74
|
+
!!c.message.tool_calls?.some(
|
|
75
|
+
(tc) =>
|
|
76
|
+
tc.type === "function" && tc.function.name === FUNCTION.name,
|
|
77
|
+
),
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
await ctx.initialize();
|
|
81
|
+
return prompts;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const FUNCTION: ILlmFunction<"chatgpt"> = typia.llm.application<
|
|
86
|
+
__IChatInitialApplication,
|
|
87
|
+
"chatgpt"
|
|
88
|
+
>().functions[0]!;
|